-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathindex.ts
More file actions
128 lines (107 loc) · 4.21 KB
/
Copy pathindex.ts
File metadata and controls
128 lines (107 loc) · 4.21 KB
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
import { app, BrowserWindow, dialog, ipcMain, screen, session } from 'electron'
import { electronApp, optimizer } from '@electron-toolkit/utils'
import { REDUX_DEVTOOLS, installExtension } from '@tomjs/electron-devtools-installer'
import { ProjectData } from '@hedron-gl/app-store'
import { openSketchSourceFile } from './handlers/openSketchSourceFile'
import { saveFrameHandler, saveFrameSequenceHandler } from './handlers/frameHandlers'
import {
DialogEvents,
FileEvents,
OpenProjectResponse,
SaveProjectResponse,
SketchEvents,
} from '@shared/Events'
import { updateDisplayMenu, updateMenu } from '@main/menu'
import { createWindow } from '@main/mainWindow'
import { startSketchesServer } from '@main/handleSketchFiles'
import { saveProjectFile } from '@main/handlers/saveProjectFile'
import { openProjectFile } from '@main/handlers/openProjectFile'
import { openFolder } from '@main/handlers/openFolder'
import { FrameEvents } from '@shared/FrameEvents'
const isDevelopment = process.env.NODE_ENV !== 'production'
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
updateMenu()
initiateScreens()
// Set app user model id for windows
electronApp.setAppUserModelId('com.electron')
// Default open or close DevTools by F12 in development
// and ignore CommandOrControl + R in production.
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
app.on('browser-window-created', (_, window) => {
optimizer.watchWindowShortcuts(window)
})
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
if (isDevelopment) {
let reduxDevtoolsInstaller: Promise<Electron.Extension>
const reduxDevtoolsPath = process.env.HEDRON_REDUX_DEVTOOLS_PATH
if (reduxDevtoolsPath) {
// Override automatic install
// This is needed if there is some bug with the latest version
// https://github.com/reduxjs/redux-devtools/issues/1730
reduxDevtoolsInstaller = session.defaultSession.loadExtension(reduxDevtoolsPath)
} else {
reduxDevtoolsInstaller = installExtension(REDUX_DEVTOOLS)
}
reduxDevtoolsInstaller
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.error('An error occurred: ', err))
}
})
const updateDisplays = (): void => {
const displays = screen.getAllDisplays()
updateDisplayMenu(displays)
}
export const initiateScreens = (): void => {
updateDisplays()
screen.on('display-added', updateDisplays)
screen.on('display-removed', updateDisplays)
screen.on('display-metrics-changed', updateDisplays)
}
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
ipcMain.handle(DialogEvents.OpenSketchesDirDialog, async () => {
const result = await dialog.showOpenDialog({
properties: ['openDirectory'],
})
return result.filePaths[0]
})
ipcMain.handle(
DialogEvents.OpenProjectFileDialog,
async (_, projectPath?: string): Promise<OpenProjectResponse> => {
return await openProjectFile(projectPath)
},
)
ipcMain.handle(
FileEvents.SaveProject,
async (_, projectData: ProjectData, savePath: string | null): Promise<SaveProjectResponse> => {
return await saveProjectFile(projectData, savePath)
},
)
ipcMain.handle(FileEvents.OpenFolder, async (_, folderPath: string) => {
return await openFolder(folderPath)
})
ipcMain.handle(
FileEvents.OpenSketchSourceFile,
async (_, sketchesDir: string, moduleId: string) => {
return await openSketchSourceFile(sketchesDir, moduleId)
},
)
ipcMain.handle(SketchEvents.StartSketchesServer, async (_, sketchesDir: string) => {
return await startSketchesServer(sketchesDir)
})
ipcMain.handle(FrameEvents.SaveFrame, saveFrameHandler)
ipcMain.handle(FrameEvents.SaveFrameSequence, saveFrameSequenceHandler)