-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
70 lines (53 loc) · 1.5 KB
/
main.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
64
65
66
67
68
69
70
const {app, BrowserWindow, ipcMain} = require('electron')
const { exec, execFileSync, execFile } = require('child_process');
const applescript = require('applescript');
var mainWindow;
app.on('ready', initialise)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.once('before-quit', () => {
mainWindow.removeAllListeners('close');
});
function initialise(){
// Create the browser window.
mainWindow = new BrowserWindow({width: 500, height: 750})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
mainWindow.webContents.once('dom-ready', () => {
setInterval(function(){
findWindow();
},3000);
})
// Emitted when the window is closed.
mainWindow.on('closed', function () {
mainWindow = null
})
}
function findWindow()
{
if( process.platform == 'win32' ){
execFile('./bin/win/activetab', (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
//send to renderer
if( mainWindow ){
mainWindow.webContents.send('store-data', stdout);
}
});
}
if( process.platform == 'darwin' ){
const script = 'tell application "Google Chrome" to return URL of active tab of front window';
applescript.execString(script, (err, rtn) => {
if (err) {
// Something went wrong!
}
mainWindow.webContents.send('store-data', rtn);
});
}
}