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
|
/*
* Copyright (C) 2021-2022 Kristóf Marussy <kristof@marussy.com>
* Copyright (C) 2022 Vijay A <vraravam@users.noreply.github.com>
*
* This file is part of Sophie.
*
* Sophie is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import os from 'node:os';
import { app } from 'electron';
import { ensureDirSync } from 'fs-extra';
import osName from 'os-name';
import { enableStacktraceSourceMaps } from './infrastructure/electron/impl/devTools';
import electronShell from './infrastructure/electron/impl/electronShell';
import initReactions from './initReactions';
import MainStore from './stores/MainStore';
import { getLogger } from './utils/log';
const isDevelopment = import.meta.env.MODE === 'development';
const log = getLogger('index');
// Always enable sandboxing.
app.enableSandbox();
if (isDevelopment) {
// Use alternative directory when debugging to avoid clobbering the main installation.
app.setPath('userData', `${app.getPath('userData')}-dev`);
ensureDirSync(app.getPath('userData'));
// Use source maps in stack traces.
enableStacktraceSourceMaps();
}
// Only allow a single instance at a time.
const isSingleInstance = app.requestSingleInstanceLock();
if (!isSingleInstance) {
app.quit();
process.exit(0);
}
// Disable chromium's MPRIS integration, which is usually more annoying
// (triggered by random sounds played by websites) than useful.
app.commandLine.appendSwitch(
'disable-features',
'HardwareMediaKeyHandling,MediaSessionService',
);
app.setAboutPanelOptions({
applicationVersion: [
`Version: ${app.getVersion()}`,
`Electron: ${process.versions.electron}`,
`Chrome: ${process.versions.chrome}`,
`Node.js: ${process.versions.node}`,
`Platform: ${osName()}`,
`Arch: ${os.arch()}`,
`Build date: ${new Date(
Number(import.meta.env.BUILD_DATE),
).toLocaleString()}`,
`Git SHA: ${import.meta.env.GIT_SHA}`,
`Git branch: ${import.meta.env.GIT_BRANCH}`,
].join('\n'),
version: '',
});
const store = MainStore.create({}, electronShell);
app.on('second-instance', () => {
store.mainWindow?.bringToForeground();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
const isMac = os.platform() === 'darwin';
initReactions(store, isDevelopment, isMac)
// eslint-disable-next-line promise/always-return -- `then` instead of top-level await.
.then((disposeCompositionRoot) => {
app.on('will-quit', disposeCompositionRoot);
})
.catch((error) => {
log.log('Failed to initialize application', error);
});
|