forked from Paxa/postbird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
108 lines (87 loc) · 2.83 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
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const windowStateKeeper = require('electron-window-state');
electron.app.ApplicationStart = Date.now();
electron.app.MainFilename = process.mainModule.filename;
// 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.systemPreferences.isDarkMode()) {
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();
//}
});
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);
} else {
urlsToOpen.push(url);
}
});
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,
},
});
mainWindowState.manage(mainWindow);
electron.app.mainWindow = mainWindow;
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/index.html');
if (process.env.NW_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;
});
});