|
1 | | -import path from 'path'; |
2 | | - |
3 | | -import { app, BrowserWindow } from 'electron'; |
4 | | -import setupElectronReload from 'electron-reload'; |
5 | | -import rimraf from 'rimraf'; |
6 | | - |
7 | | -import { setupErrorHandling } from './errorHandling'; |
8 | | - |
9 | | -if (process.env.NODE_ENV === 'development') { |
10 | | - setupElectronReload(__dirname, { |
11 | | - electron: process.execPath, |
12 | | - }); |
| 1 | +import { setupDevelopmentTools } from './main/dev'; |
| 2 | +import { setupErrorHandling } from './main/errors'; |
| 3 | +import { handleStartup } from './main/startup'; |
| 4 | +import { setupAppEvents } from './main/events'; |
| 5 | +import { setupRootWindow } from './main/rootWindow'; |
| 6 | + |
| 7 | +if (require.main === module) { |
| 8 | + setupDevelopmentTools(); |
| 9 | + setupErrorHandling(); |
| 10 | + handleStartup(); |
| 11 | + setupAppEvents(); |
| 12 | + setupRootWindow(); |
13 | 13 | } |
14 | | - |
15 | | -const preventEvent = (event) => event.preventDefault(); |
16 | | - |
17 | | -const prepareApp = () => { |
18 | | - setupErrorHandling('main'); |
19 | | - |
20 | | - app.setAsDefaultProtocolClient('rocketchat'); |
21 | | - app.setAppUserModelId('chat.rocket'); |
22 | | - |
23 | | - const dirName = process.env.NODE_ENV === 'production' ? app.name : `${ app.name } (${ process.env.NODE_ENV })`; |
24 | | - |
25 | | - app.setPath('userData', path.join(app.getPath('appData'), dirName)); |
26 | | - |
27 | | - const [command, args] = [ |
28 | | - process.argv.slice(0, app.isPackaged ? 1 : 2), |
29 | | - process.argv.slice(app.isPackaged ? 1 : 2), |
30 | | - ]; |
31 | | - |
32 | | - if (args.includes('--disable-gpu')) { |
33 | | - app.commandLine.appendSwitch('--disable-2d-canvas-image-chromium'); |
34 | | - app.commandLine.appendSwitch('--disable-accelerated-2d-canvas'); |
35 | | - app.commandLine.appendSwitch('--disable-gpu'); |
36 | | - } |
37 | | - |
38 | | - if (args.includes('--reset-app-data')) { |
39 | | - const dataDir = app.getPath('userData'); |
40 | | - rimraf.sync(dataDir); |
41 | | - app.relaunch({ args: [...command.slice(1)] }); |
42 | | - app.exit(); |
43 | | - return; |
44 | | - } |
45 | | - |
46 | | - const canStart = process.mas || app.requestSingleInstanceLock(); |
47 | | - |
48 | | - if (!canStart) { |
49 | | - app.exit(); |
50 | | - return; |
51 | | - } |
52 | | - |
53 | | - app.commandLine.appendSwitch('--autoplay-policy', 'no-user-gesture-required'); |
54 | | - |
55 | | - // TODO: make it a setting |
56 | | - if (process.platform === 'linux') { |
57 | | - app.disableHardwareAcceleration(); |
58 | | - } |
59 | | - |
60 | | - app.addListener('certificate-error', preventEvent); |
61 | | - app.addListener('select-client-certificate', preventEvent); |
62 | | - app.addListener('login', preventEvent); |
63 | | - app.addListener('open-url', preventEvent); |
64 | | - app.addListener('window-all-closed', () => { |
65 | | - app.quit(); |
66 | | - }); |
67 | | -}; |
68 | | - |
69 | | -const createMainWindow = () => { |
70 | | - const mainWindow = new BrowserWindow({ |
71 | | - width: 1000, |
72 | | - height: 600, |
73 | | - minWidth: 400, |
74 | | - minHeight: 400, |
75 | | - titleBarStyle: 'hidden', |
76 | | - backgroundColor: '#2f343d', |
77 | | - show: false, |
78 | | - webPreferences: { |
79 | | - webviewTag: true, |
80 | | - nodeIntegration: true, |
81 | | - }, |
82 | | - }); |
83 | | - |
84 | | - mainWindow.addListener('close', preventEvent); |
85 | | - |
86 | | - mainWindow.webContents.addListener('will-attach-webview', (event, webPreferences) => { |
87 | | - delete webPreferences.enableBlinkFeatures; |
88 | | - }); |
89 | | - |
90 | | - mainWindow.loadFile(`${ app.getAppPath() }/app/public/app.html`); |
91 | | -}; |
92 | | - |
93 | | -const initialize = async () => { |
94 | | - prepareApp(); |
95 | | - await app.whenReady(); |
96 | | - createMainWindow(); |
97 | | -}; |
98 | | - |
99 | | -initialize(); |
0 commit comments