-
Notifications
You must be signed in to change notification settings - Fork 125
/
main.js
124 lines (100 loc) · 3.3 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const electron = require('electron');
const app = electron.app;
const path = require('path');
const BrowserWindow = electron.BrowserWindow;
const windowStateKeeper = require('electron-window-state');
require('@electron/remote/main').initialize();
electron.app.ApplicationStart = Date.now();
electron.app.MainFilename = process.mainModule.filename;
require('./lib/error_reporter').init();
// Report crashes to our server.
//require('crash-reporter').start();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;
var filesToOpen = [];
var urlsToOpen = [];
if (electron.systemPreferences && electron.systemPreferences.subscribeNotification) {
var checkDarkMode = () => {
if (electron.nativeTheme.shouldUseDarkColors) {
electron.systemPreferences.setAppLevelAppearance('dark');
} else {
electron.systemPreferences.setAppLevelAppearance('light');
}
}
electron.systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', checkDarkMode);
checkDarkMode();
}
app.on('window-all-closed', function() {
//if (process.platform != 'darwin') {
app.quit();
//}
});
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient('postgres', process.execPath, [path.resolve(process.argv[1])])
}
} else {
app.setAsDefaultProtocolClient('postgres')
}
app.on('open-file', (event, filename) => {
event.preventDefault();
if (mainWindow) {
mainWindow.send('open-file', filename);
} else {
filesToOpen.push(filename);
}
});
app.on('open-url', (event, url) => {
event.preventDefault();
if (mainWindow) {
mainWindow.send('open-url', url);
mainWindow.focus();
} else {
urlsToOpen.push(url);
}
});
var gotTheLock = app.requestSingleInstanceLock();
app.on('ready', () => {
const mainWindowState = windowStateKeeper({
defaultWidth: 960,
defaultHeight: 640
});
mainWindow = new BrowserWindow({
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
contextIsolation: false,
},
});
mainWindowState.manage(mainWindow);
electron.app.mainWindow = mainWindow;
// and load the index.html of the app.
require("@electron/remote/main").enable(mainWindow.webContents);
mainWindow.loadURL('file://' + __dirname + '/index.html');
if (process.env.POSTBIRD_DEBUG == "true") {
mainWindow.webContents.openDevTools({detach: true});
}
// when main window is ready - send all pending events
electron.ipcMain.on('main-window-ready', () => {
filesToOpen.forEach((file) => {
mainWindow.send('open-file', file);
});
urlsToOpen.forEach((url) => {
mainWindow.send('open-url', url);
});
//electron.autoUpdater.setFeedURL("http://localhost:5000/update/osx/0.4");
//electron.autoUpdater.checkForUpdates();
});
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});