-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
main.js
118 lines (103 loc) · 2.59 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
const path = require("path");
const { app, BrowserWindow, TouchBar, ipcMain, screen } = require("electron");
const { TouchBarButton } = TouchBar;
const MAIN_WIDTH = 320;
const MAIN_HEIGHT = 350;
const spin = new TouchBarButton({
label: "👻 血小板 けっしょうばん",
backgroundColor: "#7851A9",
click: () => {
console.log("血小板");
}
});
let spins = [spin];
const touchBar = new TouchBar({
items: spins
});
let mainWindow, settingWindow;
function createWindow() {
const display = screen.getPrimaryDisplay();
const { width, height } = display.bounds;
mainWindow = new BrowserWindow({
width: MAIN_WIDTH,
height: MAIN_HEIGHT,
title: "platelet",
hasShadow: false,
transparent: true,
resizable: app.isPackaged ? false : true,
frame: false,
focusable: true,
alwaysOnTop: true,
show: false,
x: width - MAIN_WIDTH,
y: height - MAIN_HEIGHT,
webPreferences: {
devTools: app.isPackaged ? false : true,
nodeIntegration: true,
nodeIntegrationInWorker: true
}
});
mainWindow.on("closed", () => (mainWindow = null));
mainWindow.loadFile(path.join(__dirname, "index.html"));
mainWindow.once("ready-to-show", () => {
mainWindow.show();
mainWindow.setTouchBar(touchBar);
});
}
function createSettingWindow() {
if (settingWindow) {
settingWindow.show();
return
}
settingWindow = new BrowserWindow({
height: 300,
width: 400,
parent: mainWindow,
frame: false,
focusable: true,
resizable: app.isPackaged ? false : true,
hasShadow: false,
transparent: true,
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true
},
show: false
});
settingWindow.loadFile(path.join(__dirname, "setting.html"));
settingWindow.show();
}
app.on("ready", () => createWindow());
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
if (mainWindow === null) {
createWindow();
}
});
app.on("second-instance", () => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
if (process.platform === "darwin") {
app.setAboutPanelOptions({
applicationName: "血小板",
applicationVersion: app.getVersion(),
copyright: "Copyright 2018",
credits: "Amor"
});
}
ipcMain.on("show-setting-window", () => {
createSettingWindow();
});
ipcMain.on("hide-setting-window", event => {
settingWindow.hide()
});
ipcMain.on("setting-hitokoto", (event, data) => {
mainWindow.webContents.send("setting-hitokoto", data);
});