This repository was archived by the owner on Mar 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
129 lines (109 loc) · 2.56 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
119
120
121
122
123
124
125
126
127
128
129
const {
app,
BrowserWindow,
globalShortcut,
ipcMain
} = require('electron');
var openAboutWindow = require('about-window').default;
var join = require('path').join;
var notifier = require('node-notifier');
var configuration = require('./js/configuration');
var utils = require('./js/utils');
// main进程
let win = null;
// 创建窗体
function createWindow() {
win = new BrowserWindow({
minWidth: 480,
width: 770,
minHeight: 480,
height: 640,
titleBarStyle: 'hidden-inset',
frame: false,
icon: join(__dirname, 'imgs', 'tray.ico'),
show: false
});
// 加载首页
win.loadURL(`file://${__dirname}/html/index.html`)
// 窗口关闭时置 null
win.on('closed', () => {
win = null
});
// 可显示时才显示, 避免白屏窗口
win.once('ready-to-show', () => {
win.show();
});
// 发送 resize后的数据
win.on('resize', ()=>{
win.webContents.send('resize-charts-to-render', win.getContentSize());
});
win.on('maximize', function(){
win.webContents.send('maximized');
});
win.on('unmaximize', function(){
win.webContents.send('restored');
});
}
// 入口
app.on('ready', () => {
createWindow();
// 注册快捷键
globalShortcut.register('CommandOrControl+X', () => {
win.webContents.openDevTools();
});
});
// 所有窗口都关闭时, 程序退出
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
// 窗口最小化消息
ipcMain.on('min-window', () => {
win.minimize();
});
// 窗口最大化消息
ipcMain.on('max-window', (ev, arg) => {
if(win == null)
return;
if (win.isMaximized()) {
win.restore();
ev.sender.send('restored');
} else {
win.maximize();
ev.sender.send('maximized');
}
});
// 窗口关闭消息
ipcMain.on('close-window', () => {
win.close();
win = null;
});
// 发送 resize 消息
ipcMain.on('resize-charts', (ev, arg)=>{
win.webContents.send('resize-charts-to-render', win.getContentSize());
});
// 信息弹窗
ipcMain.on('open-information-dialog', (ev, arg)=>{
showMessage(arg[0]);
});
// 信息弹窗
function showMessage(msg){
let dialog = require('electron').dialog;
let options = {
type: 'info',
title: '提示',
message: msg,
buttons: ['ok']
};
dialog.showMessageBox(options, function(index){
//
});
}
// 打开 About 窗口
ipcMain.on('open-about-dialog', function(ev, arg){
openAboutWindow({
icon_path: join(__dirname, 'imgs', 'logo.png'),
copyright: 'Copyright (c) 2017 张洁'
});
});