-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.js
136 lines (120 loc) · 3.89 KB
/
index.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
125
126
127
128
129
130
131
132
133
134
135
136
const path = require('path');
const electron = require('electron');
const AppTray = require('./app/app_tray');
const setAppMenu = require('./app/app_menu');
const Helper = require('./app/helper');
const MainWindow = require('./app/main_window');
const c = require('./app/constants');
const { app, Menu, ipcMain, Notification } = electron;
let mainWindow;
let spinnerWindow;
let offlineWindow;
let tray;
let appIconPath;
app.on('ready', () => {
// set up icons
let appIcon = 'app-win.ico';
let trayIcon = 'tray-win.ico';
if (Helper.isLinux()) {
appIcon = 'app-linux512x512.png';
trayIcon = 'tray-linux32x32.png';
}
if (Helper.isMacOS()) {
appIcon = 'app-mac.png';
trayIcon = 'tray-mac.png';
}
const trayIconPath = path.join(__dirname, 'src', 'assets', trayIcon);
appIconPath = path.join(__dirname, 'src', 'assets', appIcon);
// get main page ready
loadAppWindows(c.settings.showLoader);
// create menu
setAppMenu(mainWindow);
// create tray
tray = new AppTray(trayIconPath, mainWindow);
// create TouchBar on macOS
if (Helper.useTouchBar()) {
const setTouchBar = require('./app/touch_bar');
setTouchBar(mainWindow);
}
});
// Handle BrowserWindow setup
function loadAppWindows(showLoader) {
// setup/load main page
let appPath = c.settings.appUrl;
if (Helper.usePhotonKitShell()) {
appPath = `file://${__dirname}/src/shellMacOS.html`;
} else if (Helper.useWindowsShell()) {
appPath = `file://${__dirname}/src/shellWindows.html`;
} else if (Helper.useLinuxShell()) {
appPath = `file://${__dirname}/src/shellLinux.html`;
}
mainWindow = new MainWindow(appPath, appIconPath, !showLoader);
// quit app when mainWindow is closed
mainWindow.on('closed', () => app.quit());
if (showLoader) {
// show loader window only on first start,
// the PWA should be cached afterwards.
spinnerWindow = new MainWindow(`file://${__dirname}/src/loader.html`, appIconPath);
// hide loader when app is ready
mainWindow.once('ready-to-show', () => {
spinnerWindow.hide();
spinnerWindow = null;
mainWindow.show();
});
}
/* DEBUG: force show offline window */
// offlineWindow = new MainWindow(`file://${__dirname}/src/offline.html`, appIconPath);
// show offline-page if no connectivity
mainWindow.webContents.on('did-fail-load', function(ev, errorCode, errorDesc, url) {
offlineWindow = new MainWindow(`file://${__dirname}/src/offline.html`, appIconPath);
mainWindow.hide();
});
}
// Listen for events fired in the UI
ipcMain.on('app:refresh', (event) => {
// hide offline window if applicable
if (offlineWindow && offlineWindow.isVisible()) {
offlineWindow.hide();
}
offlineWindow = null;
if (mainWindow) {
// mainWindow is hidden, refresh and show it directly
mainWindow.loadHome();
mainWindow.show();
} else {
// instantiate mainWindow additionally
loadAppWindows(false);
}
});
/// Sample Notification
if (Notification.isSupported()) {
ipcMain.on('webview:notification', (event) => {
const notification = new Notification({
title: 'Anfrage erfolgreich versandt',
// subtitle: 'Subtitle', // macOS only
body: 'Sie erhalten Ihr Angebot innerhalb von höchstens 2 Werktagen, aber wir setzen alles daran, schneller zu sein!',
});
notification.show();
});
}
// Shell listeners
if (Helper.isUsingShell()) {
const resize = function(width, height) {
let bounds = mainWindow.getBounds();
const diffWidth = (width - bounds.width);
let newX = bounds.x - (diffWidth / 2);
if (newX < 0) {
newX = 0;
}
bounds.x = newX;
bounds.height = height;
bounds.width = width;
mainWindow.setBounds(bounds, true);
};
ipcMain.on('titlebar:small_view', (event) => {
resize(c.mainWindow.width, c.mainWindow.height);
});
ipcMain.on('titlebar:large_view', (event) => {
resize(c.mainWindow.largeWidth, c.mainWindow.largeHeight);
});
}