-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_dev.js
79 lines (63 loc) · 1.76 KB
/
main_dev.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
const { app, BrowserWindow, ipcMain } = require("electron");
const pty = require("node-pty");
const guess_shell_path = function(){
if (process.platform == "win32") {
return process.env["ComSpec"];
} else {
return process.env["SHELL"];
}
};
if (process.argv.includes("--hot-reload")) {
try {
require("electron-reloader")(module);
} catch {}
}
require("@electron/remote/main").initialize();
app.commandLine.appendSwitch("remote-debugging-port", "9541");
/** @type {string} */
let CurrentStatusOfIME = "en";
/** @type {BrowserWindow | null | undefined} */
let win;
const createWindow = () => {
win = new BrowserWindow({
width: 1200,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
minWidth: 800,
minHeight: 600
});
require("@electron/remote/main").enable(win.webContents);
win.loadFile("./App/start.html");
win.webContents.openDevTools();
};
app.whenReady().then(() => createWindow());
ipcMain.on("ime_setToEnglishMode", () => {
CurrentStatusOfIME = "en";
});
ipcMain.on("ime_setToInputMode", () => {
CurrentStatusOfIME = "input";
});
ipcMain.on("ime_getCurrentStatus", (event) => {
event.returnValue = CurrentStatusOfIME;
});
/**
@type { import("node-pty").IPty | null }
*/
let shellInstanceObject = null;
ipcMain.on("spawnShell", () => {
const shell_path = guess_shell_path();
const ptyProcess = pty.spawn(shell_path);
if (shellInstanceObject !== null) {
shellInstanceObject.kill();
}
shellInstanceObject = ptyProcess;
shellInstanceObject.on("data", (/** @type {string} */ data) => {
win.webContents.send("shellInstanceData", data);
});
});
ipcMain.on("shellInstanceWrite", (event, /** @type {string} */ data) => {
shellInstanceObject.write(data);
});