-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
149 lines (123 loc) · 3.6 KB
/
index.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
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
import { app, BrowserWindow, ipcMain, nativeImage, dialog } from 'electron';
import path from 'path';
import url from 'url';
import { WordManager } from './lib/kkutu/word-manager';
import axios, { AxiosResponse } from 'axios';
import { machineId } from 'node-machine-id';
import {
DBWordReq,
LookupPendingReq,
LookupReq,
WordMode,
} from './lib/interface';
const wordManager = new WordManager('./kkutu.db');
let win: BrowserWindow | null;
/*
(async () => {
try {
const instance = axios.create({ timeout: 3000 });
const myHwid = await machineId();
const result = await instance.get<
any,
AxiosResponse<{ status: number; message: string }>
>(`http://sv.steins.kr/api/hwid?hwid=${myHwid}&n=1`);
if (result.data.status != 200) process.exit(0);
else
dialog.showMessageBox({
title: '디바이스 체크',
icon: undefined,
message: result.data.message,
});
} catch (e) {
app.quit();
win = null;
process.exit(0);
}
})();
*/
function createWindow() {
const image = nativeImage.createFromPath(__dirname + '/icon/icon.png');
image.setTemplateImage(true);
win = new BrowserWindow({
width: 1700,
height: 900,
icon: image,
resizable: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
allowRunningInsecureContent: true,
webviewTag: true,
devTools: true,
},
});
win.removeMenu();
win.loadURL(
url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true,
}),
);
// F12
// win.webContents.openDevTools({ mode: 'undocked' });
win.on('closed', () => {
win = null;
});
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// macOS에서 독 아이콘이 클릭되고 다른 창은 열리지 않는다.
if (!win) {
createWindow();
}
});
ipcMain.on('lookup_words', async (event, data: LookupReq) => {
const queryResult = await wordManager.db.getWord(
data.startWords.map((x) => x + '%'),
data.overlaps,
data.mission,
100,
);
event.sender.send('lookup_words', {
result: queryResult.result,
elapsed: queryResult.elapsedTime,
});
});
ipcMain.on('detected_words', async (event, data: DBWordReq) => {
const queryResult = await wordManager.addDetectedWords(data.words);
event.sender.send('detected_words', queryResult);
});
ipcMain.on('invalid_words', async (event, data: DBWordReq) => {
const queryResult = await wordManager.addInvalidWords(data.words);
event.sender.send('invalid_words', queryResult);
});
ipcMain.on('add_words', async (event, data: DBWordReq) => {
const queryResult = await wordManager.db.addWord(data.words);
wordManager.db.resetPendingNewWords();
event.sender.send('add_words', queryResult);
});
ipcMain.on('remove_words', async (event, data: DBWordReq) => {
const queryResult = await wordManager.db.removeWord(data.words);
wordManager.db.resetPendingInvalidWords();
event.sender.send('remove_words', queryResult);
});
ipcMain.on('lookup_pending_words', async (event, data: LookupPendingReq) => {
let queryResult;
if (data.mode == WordMode.ADD)
queryResult = await wordManager.db.getPendingNewWords();
else queryResult = await wordManager.db.getPendingInvalidWords();
event.sender.send('lookup_pending_words', queryResult);
});
ipcMain.on('get_all_words', async (event) => {
event.sender.send(
'get_all_words',
await wordManager.db.getWord('%', [], undefined, 1000000000),
);
});