-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (35 loc) · 947 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const path = require('path');
const fs = require('fs');
const bin = (() => {
if(process.platform == 'win32'){
return require('./bins/win.node');
}
const { exec } = require('child_process');
switch (process.platform) {
case 'darwin': return {
open(path){
exec('xdg-open ' + path);
return true;
}
}
case 'linux' || 'freebsd' || 'freebsd': return {
open(path){
exec('open ' + path);
return true;
}
}
default: return {
open(_){
console.log('[OpenWith] Your OS not supported - ' + process.platform);
return false;
}
}
}
})();
module.exports = class openWith {
static open(file){
file = path.normalize(file);
if(!fs.existsSync(file)) return false;
return bin.open(file);
}
}