-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (55 loc) · 1.67 KB
/
index.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
const { app, BrowserWindow, ipcMain } = require("electron");
const path = require("path");
let authCredentials = { id: "", password: "" };
let mainWindow;
function createAuthWindow() {
const authWindow = new BrowserWindow({
icon: path.join(__dirname, "app.icns"),
width: 400,
height: 400,
webPreferences: {
preload: path.join(__dirname, "preload.js"), // ここに preload スクリプトを指定
nodeIntegration: false,
},
});
// 認証情報入力画面のロード(HTMLファイルのパスを指定)
authWindow.loadFile("auth.html");
ipcMain.once("submit-auth", (event, id, password) => {
authCredentials = { id, password };
console.log(authCredentials);
authWindow.close();
createMainWindow();
});
}
function createMainWindow() {
mainWindow = new BrowserWindow({
icon: path.join(__dirname, "app.icns"),
width: 512,
height: 330,
webPreferences: {
nodeIntegration: true,
},
});
mainWindow.loadURL("http://solar-monitor.local/");
mainWindow.webContents.on("did-finish-load", () => {
mainWindow.webContents.setZoomFactor(0.5);
mainWindow.webContents.insertCSS(
"body::-webkit-scrollbar { display: none; }"
);
});
mainWindow.webContents.on("login", (event, request, authInfo, callback) => {
event.preventDefault();
callback(authCredentials.id, authCredentials.password); // メモリ上の認証情報を使用
});
}
app.whenReady().then(createAuthWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createMainWindow();
}
});