This repository was archived by the owner on Apr 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
186 lines (175 loc) · 5.92 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// require('babel-polyfill');
const electron = require('electron');
const { app, BrowserWindow, Menu, globalShortcut, dialog, /*autoUpdater*/ } = electron;
const path = require('path');
const Updater = require('./app/Updater')
const Spreadsheets = require('./app/Spreadsheets');
let win = null;
let forceQuit = false;
app.on('window-all-closed', () => {
if (process.platform != 'darwin')
app.quit();
});
app.on('ready', () => {
let splashWin = new BrowserWindow({
width: 256,
height: 263,
transparent: true,
frame: false,
center: true,
show: false
});
splashWin.loadURL('file://' + path.join(__dirname, "./app/splash/splash.html"));
win = new BrowserWindow({
width: 750,
height: 675,
show: false
});
const update = async () => {
try {
splashWin.show();
splashWin.webContents.send('status', 'アップデートを確認中');
splashWin.webContents.send('all', 1);
const update = await Updater.updateRequired();
splashWin.webContents.send('complete');
if (update) {
if (Updater.downloadRequired()) {
splashWin.webContents.send('status', 'ダウンロード中');
splashWin.webContents.send('all', Updater.getDownloadAmount());
await Updater.download(() => splashWin.webContents.send('complete'));
}
if (Updater.deleteRequired()) {
splashWin.webContents.send('status', '不要なファイルの消去中');
splashWin.webContents.send('all', Updater.getDeleteAmount());
await Updater.delete(() => splashWin.webContents.send('complete'));
}
}
splashWin.webContents.send('status', '初期化中');
splashWin.webContents.send('all', 1);
await Spreadsheets.init(win).then(() => splashWin.webContents.send('complete'));
splashWin.webContents.send('allDone');
splashWin.webContents.send('status', '準備完了');
win.loadURL('file://' + path.join(__dirname, './app/index.html'));
} catch (err) {
console.error(err);
splashWin.webContents.send('error');
splashWin.webContents.send('status', 'エラーが発生しました');
dialog.showMessageBox(splashWin, {
type: 'error',
message: 'エラーが発生しました',
detail: err.stack,
buttons: ['リトライ', '終了']
}, (res) => {
if (res === 0)
update();
else
app.exit(1);
});
}
}
splashWin.webContents.on("did-finish-load", update);
win.webContents.on("did-finish-load", () => {
splashWin.close();
splashWin = null;
win.show();
});
const template = [
{
label: 'Application',
submenu: [
{
role: 'about'
},
{
type: 'separator'
},
{
role: 'quit'
}
]
},
{
label: 'Edit',
submenu: [
{
role: 'undo',
},
{
role: 'redo',
},
{
type: 'separator'
},
{
role: 'cut'
},
{
role: 'copy'
},
{
role: 'paste'
}
]
}
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
win.on('close', (e) => {
if (forceQuit || process.platform != 'darwin') {
win = null;
} else {
e.preventDefault();
win.hide();
}
});
globalShortcut.register(process.platform === 'darwin' ? 'Alt+Cmd+I' : 'Ctrl+Shift+I', () => {
win.toggleDevTools();
});
const updateChecker = setInterval(async () => {
if (await Updater.updateRequired()) {
dialog.showMessageBox({
type: 'info',
buttons: ['再起動', '後で'],
title: 'アップデートがあります'
}, (res) => {
if (res === 0) {
app.relaunch();
app.exit();
}
});
clearInterval(updateChecker);
}
}, 600000);
// const server = 'https://hazel-server-ezczncogdc.now.sh';
// const feed = `${server}/update/${process.platform}/${app.getVersion()}`;
// autoUpdater.setFeedURL(feed)
// autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
// const dialogOpts = {
// type: 'info',
// buttons: ['Restart', 'Later'],
// title: 'Application Update',
// message: process.platform === 'win32' ? releaseNotes : releaseName,
// detail: 'A new version has been downloaded. Restart the application to apply the updates.'
// };
// dialog.showMessageBox(dialogOpts, (response) => {
// if (response === 0)
// autoUpdater.quitAndInstall();
// })
// });
// autoUpdater.on('error', (message) => {
// console.error('There was a problem updating the application');
// console.error(message);
// });
// autoUpdater.on('checking-for-update', () => {
// console.log('checking-for-update');
// });
// setInterval((function callback() {
// autoUpdater.checkForUpdates();
// return callback;
// }()), 600000);
});
app.on('before-quit', () => {
forceQuit = true;
});
app.on('activate', () => {
win.show();
});