picosh 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -2
- package/package.json +1 -1
- package/scripts/postinstall.js +28 -4
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const https = require('https');
|
|
|
7
7
|
const http = require('http');
|
|
8
8
|
|
|
9
9
|
const SAVE_DIR = path.join(os.tmpdir(), 'picosh');
|
|
10
|
+
const SAVE_PATH = path.join(SAVE_DIR, 'clip_latest.png');
|
|
10
11
|
|
|
11
12
|
function hasImage(clipboard) {
|
|
12
13
|
if (!clipboard.readImage().isEmpty()) return {type: 'bitmap'};
|
|
@@ -20,7 +21,7 @@ function hasImage(clipboard) {
|
|
|
20
21
|
|
|
21
22
|
function saveBitmap(clipboard) {
|
|
22
23
|
fs.mkdirSync(SAVE_DIR, {recursive: true});
|
|
23
|
-
const filepath =
|
|
24
|
+
const filepath = SAVE_PATH;
|
|
24
25
|
fs.writeFileSync(filepath, clipboard.readImage().toPNG());
|
|
25
26
|
return Promise.resolve(filepath);
|
|
26
27
|
}
|
|
@@ -28,7 +29,7 @@ function saveBitmap(clipboard) {
|
|
|
28
29
|
function downloadImage(url) {
|
|
29
30
|
return new Promise((resolve) => {
|
|
30
31
|
fs.mkdirSync(SAVE_DIR, {recursive: true});
|
|
31
|
-
const filepath =
|
|
32
|
+
const filepath = SAVE_PATH;
|
|
32
33
|
const file = fs.createWriteStream(filepath);
|
|
33
34
|
const client = url.startsWith('https') ? https : http;
|
|
34
35
|
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -15,18 +15,42 @@ function findHyperCli() {
|
|
|
15
15
|
return HYPER_CLI_PATHS.find((p) => fs.existsSync(p));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
function installHyper() {
|
|
19
|
+
const platform = os.platform();
|
|
20
|
+
console.log('[picosh] Installing Hyper...');
|
|
21
|
+
try {
|
|
22
|
+
if (platform === 'win32') {
|
|
23
|
+
execSync('winget install vercel.Hyper --silent', {stdio: 'inherit'});
|
|
24
|
+
} else if (platform === 'darwin') {
|
|
25
|
+
execSync('brew install --cask hyper', {stdio: 'inherit'});
|
|
26
|
+
} else {
|
|
27
|
+
console.log('[picosh] Please install Hyper manually: https://hyper.is');
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.log('[picosh] Auto-install failed. Please install Hyper manually: https://hyper.is');
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let cli = findHyperCli();
|
|
38
|
+
|
|
39
|
+
if (!cli) {
|
|
40
|
+
const installed = installHyper();
|
|
41
|
+
if (!installed) process.exit(0);
|
|
42
|
+
cli = findHyperCli();
|
|
43
|
+
}
|
|
19
44
|
|
|
20
45
|
if (!cli) {
|
|
21
|
-
console.log('[picosh] Hyper
|
|
22
|
-
console.log('[picosh] Then run: hyper i picosh');
|
|
46
|
+
console.log('[picosh] Hyper installed. Run `hyper i picosh` to activate the plugin.');
|
|
23
47
|
process.exit(0);
|
|
24
48
|
}
|
|
25
49
|
|
|
26
50
|
try {
|
|
27
51
|
console.log('[picosh] Registering plugin with Hyper...');
|
|
28
52
|
execSync(`"${cli}" i picosh`, {stdio: 'inherit'});
|
|
29
|
-
console.log('[picosh] Done!
|
|
53
|
+
console.log('[picosh] Done! Launch Hyper to start using picosh.');
|
|
30
54
|
} catch (e) {
|
|
31
55
|
console.log('[picosh] Could not auto-register. Run manually: hyper i picosh');
|
|
32
56
|
}
|