forked from janhq/jan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
102 lines (89 loc) · 2.46 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
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
import { app, BrowserWindow } from 'electron'
import { join } from 'path'
import { setupMenu } from './utils/menu'
import { createUserSpace } from './utils/path'
/**
* Managers
**/
import { WindowManager } from './managers/window'
import { log, ModuleManager } from '@janhq/core/node'
/**
* IPC Handlers
**/
import { handleDownloaderIPCs } from './handlers/download'
import { handleExtensionIPCs } from './handlers/extension'
import { handleFileMangerIPCs } from './handlers/fileManager'
import { handleAppIPCs } from './handlers/app'
import { handleAppUpdates } from './handlers/update'
import { handleFsIPCs } from './handlers/fs'
/**
* Utils
**/
import { migrateExtensions } from './utils/migration'
import { cleanUpAndQuit } from './utils/clean'
import { setupExtensions } from './utils/extension'
app
.whenReady()
.then(createUserSpace)
.then(migrateExtensions)
.then(setupExtensions)
.then(setupMenu)
.then(handleIPCs)
.then(handleAppUpdates)
.then(createMainWindow)
.then(() => {
app.on('activate', () => {
if (!BrowserWindow.getAllWindows().length) {
createMainWindow()
}
})
})
app.once('window-all-closed', () => {
cleanUpAndQuit()
})
app.once('quit', () => {
cleanUpAndQuit()
})
function createMainWindow() {
/* Create main window */
const mainWindow = WindowManager.instance.createWindow({
webPreferences: {
nodeIntegration: true,
preload: join(__dirname, 'preload.js'),
webSecurity: false,
},
})
const startURL = app.isPackaged
? `file://${join(__dirname, '..', 'renderer', 'index.html')}`
: 'http://localhost:3000'
/* Load frontend app to the window */
mainWindow.loadURL(startURL)
mainWindow.once('ready-to-show', () => mainWindow?.show())
mainWindow.on('closed', () => {
if (process.platform !== 'darwin') app.quit()
})
/* Open external links in the default browser */
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
require('electron').shell.openExternal(url)
return { action: 'deny' }
})
/* Enable dev tools for development */
if (!app.isPackaged) mainWindow.webContents.openDevTools()
}
/**
* Handles various IPC messages from the renderer process.
*/
function handleIPCs() {
handleFsIPCs()
handleDownloaderIPCs()
handleExtensionIPCs()
handleAppIPCs()
handleFileMangerIPCs()
}
/*
** Suppress Node error messages
*/
process.on('uncaughtException', function (err) {
// TODO: Write error to log file in #1447
log(`Error: ${err}`)
})