forked from finos/SymphonyElectron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspectronUtils.js
63 lines (54 loc) · 2.09 KB
/
spectronUtils.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const childProcess = require('child_process');
const path = require('path');
const fs = require('fs');
const { isMac } = require('../../js/utils/misc');
class Utils {
static async openAppInMaximize(appPath) {
if (isMac) {
const osascript = require('node-osascript');
await osascript.execute('if application "' + appPath + '" is running then \n do shell script ("pkill -9 ' + appPath + '*") \n end if \n delay 5 \n tell application "' + appPath + '" \n activate \n tell window 1 \n set zoomed to true \n end tell \n end tell');
} else {
await childProcess.exec('start /MAX ' + appPath);
}
}
static async killProcess(processName) {
if (isMac) {
const osascript = require('node-osascript');
await osascript.execute('if application "' + processName + '" is running then \n do shell script ("pkill -9 ' + processName + '*") \n end if \n delay 5');
} else {
await childProcess.exec('taskkill /f /t /im ' + processName);
}
}
static async sleep(second) {
return new Promise(resolve => {
setTimeout(resolve, this.toMs(second));
})
}
static getFolderPath(folderName) {
return path.join(require('os').homedir(), folderName);
}
static getFiles(path) {
return fs.readdirSync(path);
}
static toMs(second) {
return second * 1000;
}
static async randomString() {
var chars = await "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = await 8;
var randomstring = await '';
for (var i = 0; i < string_length; i++) {
var rnum = await Math.floor(Math.random() * chars.length);
randomstring += await chars.substring(rnum, rnum + 1);
}
return randomstring;
}
static execPromise(command) {
return new Promise(function (resolve, reject) {
childProcess.exec(command, (error, stdout, stderr) => {
resolve(stdout.trim());
});
});
}
}
module.exports = Utils;