forked from SilverHoodCorp/polar-bookshelf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
59 lines (42 loc) · 1.85 KB
/
main.ts
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
import {app} from 'electron';
import {Logger} from 'polar-shared/src/logger/Logger';
import {MainApp} from './web/js/apps/main/MainApp';
import {Cmdline} from './web/js/electron/Cmdline';
import {Logging} from './web/js/logger/Logging';
import {Datastores} from './web/js/datastore/Datastores';
import process from 'process';
import {LazyWriteDatastore} from './web/js/datastore/LazyWriteDatastore';
import {Version} from "polar-shared/src/util/Version";
const hasSingleInstanceLock = app.requestSingleInstanceLock();
if (process.env.POLAR_DISABLE_HARDWARE_ACCELERATION === 'true') {
console.log("Disabling hardware acceleration");
app.disableHardwareAcceleration();
}
if (!hasSingleInstanceLock) {
console.error("Quiting. App is single instance.");
app.quit();
}
// needed to disable site isolation because it doesn't actually allow us to
// disable web security properly.
app.commandLine.appendSwitch('disable-site-isolation-trials');
async function launch() {
console.log("Running with CWD: " + process.cwd());
console.log("Running with Node version: " + process.version);
console.log("Running with Electron version: " + process.versions.electron);
console.log("Running with Polar version: " + Version.get());
console.log("Running with app version: " + app.getVersion());
const log = Logger.create();
const datastore = new LazyWriteDatastore(Datastores.create());
await datastore.init();
await Logging.init();
const mainApp = new MainApp(datastore);
const {mainAppController} = await mainApp.start();
const fileArg = Cmdline.getDocArg(process.argv);
if (fileArg) {
log.info("Opening file given on the command line: " + fileArg);
await mainAppController.handleLoadDoc(fileArg);
}
}
app.on('ready', async () => {
launch().catch(err => console.error("Unable to launch app: ", err));
});