teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

MainProcessのコードを全て記載

2021/06/16 16:30

投稿

Praline
Praline

スコア46

title CHANGED
File without changes
body CHANGED
@@ -21,20 +21,37 @@
21
21
 
22
22
  ```javascript
23
23
  //MainProcess
24
- //一部ソースは省略
24
+ const {BrowserWindow, app, ipcMain} = require('electron');
25
- ipcMain.on('mainwindow_close', () => {
25
+ const path = require('path');
26
- //ここの処理は実行される
27
- mainWindow.close();
28
- });
29
26
 
27
+ let mainWindow;
28
+
29
+ app.on('ready', function() {
30
+ mainWindow = new BrowserWindow({
31
+ frame: false,
32
+ width: 300,
33
+ height: 300,
34
+ webPreferences: {
35
+ nodeIntegration: true,
36
+ contextIsolation: false
37
+ }
38
+ });
39
+
40
+ mainWindow.loadURL('htmlFilePath');//htmlFilePathは任意の文字列
41
+
30
- mainWindow.on('closed', () => {
42
+ mainWindow.on('closed', function() {
31
- //ここのclosedイベント発生しない
43
+ //iframeを含むとここが実行されない
32
- mainWindow = null;
44
+ mainWindow = null;
45
+ });
33
46
  });
34
-
35
- app.on('window-all-closed', () => {
47
+ app.on('window-all-closed', function () {
36
48
  app.quit();
37
49
  });
50
+
51
+ ipcMain.on('mainwindow_close', () => {
52
+ //ここは実行される
53
+ mainWindow.close();
54
+ });
38
55
  ```
39
56
 
40
57