-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
110 lines (94 loc) · 3.8 KB
/
main.js
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
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const fs = require('fs')
const dir = path.dirname(app.getPath('exe'))
var global = {
selectorWin: null, dir: dir,
workspace: null, profile: null
}
ipcMain.handle('getDirectory', () => dir)
ipcMain.handle('exists', (event, path) => fs.existsSync(path))
ipcMain.handle('write', (event, path, data) => { console.log(path); return fs.writeFileSync(path, data) })
ipcMain.handle('read', (event, path) => fs.readFileSync(path, 'utf8'))
ipcMain.handle('tryCreateDir', (event, path) => fs.mkdirSync(path, { recursive: true }))
ipcMain.handle('isAbsolute', (event, _path) => path.isAbsolute(_path))
ipcMain.handle('pathJoin', (event, ...paths) => path.join(...paths))
ipcMain.handle('workspace', () => global.workspace)
ipcMain.handle('profile', () => global.profile)
ipcMain.handle('setWorkspace', (event, workspace) => global.workspace = workspace)
ipcMain.handle('setProfile', (event, profile) => global.profile = profile)
ipcMain.handle('openIndex', (ev, workspace) => createIndexWindow(workspace))
ipcMain.handle('openMarketplace', () => createMarketplaceSelectorWindow())
ipcMain.handle('openSelector', () => createSelectorWindow())
ipcMain.handle('openPrompt', (event, title, questions) => createPromptWindow(title, questions))
function createSelectorWindow() {
if (global.marketplaceSelectorWin) global.marketplaceSelectorWin.close()
if (global.indexWin) global.indexWin.close()
const selectorWin = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'src', 'preload.js'),
},
titleBarStyle: 'hidden',
titleBarOverlay: {
color: '#000'
},
})
selectorWin.maximizable = false
selectorWin.resizable = false
try { ipcMain.once('setTitleBarColor', (event, color) => { selectorWin.setTitleBarOverlay({ color }) }) }
catch {}
selectorWin.loadFile('src/pages/selector.html')
global.selectorWin = selectorWin
}
function createIndexWindow(workspace) {
global.selectorWin.close()
global.workspace = workspace
console.log(workspace)
const indexWin = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
preload: path.join(__dirname, 'src', 'preload.js'),
},
show: false,
})
indexWin.maximize()
indexWin.loadFile('src/pages/index.html')
indexWin.once('ready-to-show', () => indexWin.show())
global.indexWin = indexWin
}
function createMarketplaceSelectorWindow() {
global.selectorWin.close()
const marketplaceSelectorWin = new BrowserWindow({
width: 600,
height: 400,
webPreferences: {
preload: path.join(__dirname, 'src', 'preload.js'),
},
show: false,
})
marketplaceSelectorWin.maximizable = false
marketplaceSelectorWin.resizable = false
marketplaceSelectorWin.setMenuBarVisibility(false)
marketplaceSelectorWin.loadFile('src/pages/marketplace-selector.html')
marketplaceSelectorWin.once('ready-to-show', () => marketplaceSelectorWin.show())
global.marketplaceSelectorWin = marketplaceSelectorWin
}
function createPromptWindow(title, questions) {
const queryParams = new URLSearchParams({ title, questions: JSON.stringify(questions) }).toString();
const promptWin = new BrowserWindow({
width: 800,
height: 700,
webPreferences: {
preload: path.join(__dirname, 'src', 'preload.js'),
},
show: false,
})
promptWin.maximizable = false
promptWin.loadURL(`file://${path.join(__dirname, 'src', 'pages', 'prompt.html')}?${queryParams}`);
promptWin.once('ready-to-show', () => promptWin.show())
global.promptWin = promptWin
}
app.whenReady().then(createSelectorWindow)