-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
90 lines (83 loc) · 2.97 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const { app, BrowserWindow, ipcMain, shell } = require('electron');
const { autoUpdater } = require("electron-updater");
const fixPath = require('fix-path');
const chokidar = require('chokidar');
const prettyBytes = require('pretty-bytes');
const path = require('path');
const state = require('./src/state.js');
const api = require('./src/api.js');
const docker = require('./src/docker.js');
const singularity = require('./src/singularity.js');
const rsync = require('./src/rsync.js');
let win = undefined;
function init() {
delete process.env.DISPLAY; // req'd so ssh connection terminates when executing single commands e.g. ssh user@cubic cmd
singularity.rsyncInstance = rsync;
let watcher = chokidar.watch([], {
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true
});
watcher.on('all', (event, fn, stats) => {
// every time a watched file changed, add to re sync list
if (!event.includes("Dir")) { // ignore directories since we're watching files
fn = path.dirname(fn)
}
if (!rsync.watched.has(fn)) {
rsync.watched.add(fn);
}
if (!state.data.syncNeeded.has(fn)) {
state.data.syncNeeded.add(fn);
}
rsync.fileStats[fn] = stats;
rsync.fileStats[fn].size = prettyBytes(rsync.fileStats[fn].size);
win.webContents.send('asynchronous-message', { type: 'remakeDataTab', local: rsync.watched, notSynced: state.data.syncNeeded, stats: rsync.fileStats, remote: state.findRemoteMounts() });
});
rsync.watcher = watcher;
fixPath();
createWindow();
autoUpdater.checkForUpdatesAndNotify();
}
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 880,
height: 900,
titleBarStyle: 'hiddenInset',
webPreferences: {
nodeIntegration: true
}
});
win.loadFile('html/index.html');
win.webContents.on('did-finish-load', () => {
state.refreshWindowState(win, {
singularity: singularity,
docker: docker,
rsync: rsync
});
});
win.webContents.on('new-window', function (e, url) {
// https://stackoverflow.com/a/32427579/2624391
e.preventDefault();
shell.openExternal(url);
});
}
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
win = undefined;
});
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
ipcMain.on('asynchronous-message', (event, json) => {
api.request(json, state, win, docker, singularity, rsync);
});
app.whenReady().then(init);