-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
107 lines (79 loc) · 2.39 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
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
let mainWindow = null;
app.on('ready', () => {
let fs = require('fs');
let path = __dirname + '/package.json';
let map_package = JSON.parse(fs.readFileSync(path));
let map_window = map_package["window"];
console.log(map_package);
console.log(map_window);
let width = parseInt(map_window["width"]);
let height = parseInt(map_window["height"]);
let resize = map_window["resize"];
//windows微調整
if (process.platform == "win32") {
if(resize==false){
height = height + 20;
}
}
// mainWindowを作成(windowの大きさや、Kioskモードにするかどうかなどもここで定義できる)
mainWindow = new BrowserWindow({
"width": width,
"height": height,
"resizable":resize,
"useContentSize": true,
"show":false,
webPreferences: {
nodeIntegration: true
}
});
// 判定用ユーザーエージェント追加
mainWindow.webContents.setUserAgent(mainWindow.webContents.getUserAgent() + " TyranoErectron");
// Electronに表示するhtmlを絶対パスで指定(相対パスだと動かない)
mainWindow.loadURL('file://' + __dirname + '/index.html');
// ChromiumのDevツールを開く
// mainWindow.webContents.openDevTools();
if (map_window["devtools"] == true) {
mainWindow.webContents.openDevTools();
}
mainWindow.on("ready-to-show", () => {
//メニューの調整
const Menu = require('electron').Menu;
if (process.platform == "win32") {
mainWindow.removeMenu();
mainWindow.minimize(); // 最小化
mainWindow.restore(); // 最大化
} else {
const templateMenu = [
{
label: 'ファイル',
submenu: [
{
label: '終了',
role: 'close',
},
]
}
];
let menu = Menu.buildFromTemplate(templateMenu);
Menu.setApplicationMenu(menu);
}
mainWindow.show();
});
// mainWindow.removeMenu();
// mainWindow.setMenu(null);
mainWindow.on('closed', function() {
mainWindow = null;
});
});
/*
var log = require('electron-log');
process.on('uncaughtException', function(err) {
log.error('electron:event:uncaughtException');
log.error(err);
log.error(err.stack);
app.quit();
});
*/