-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser_windows.js
More file actions
93 lines (88 loc) 路 2.49 KB
/
Copy pathbrowser_windows.js
File metadata and controls
93 lines (88 loc) 路 2.49 KB
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
const { app, BrowserWindow, screen, dialog } = require("electron");
const path = require('path');
const createMainWindow = () => {
const win = new BrowserWindow({
width: 1000,
height: 700,
minimizable: true,
maximizable: false,
// resizable: false,
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
nodeIntegration: true
}
});
win.loadFile('./src/views/html/control_panel.html');
return win;
}
const createWidgetWindow = () => {
// Debug width and height
// const width = 500;
// const height = 300;
const width = 115;
const height = 145;
const workAreaSize = screen.getPrimaryDisplay().workAreaSize;
const win = new BrowserWindow({
width: width,
height: height,
x: workAreaSize.width - width,
y: workAreaSize.height - height,
opacity: 0.65,
resizable: false,
minimizable: false,
maximizable: false,
show: false,
frame: false,
closable: false,
focusable: false,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
nodeIntegration: true
}
});
win.loadFile('./src/views/html/timer_widget.html');
return win;
}
function initializeWindowEvents(MainWindow, TimerWidgetWindow, app) {
// When the close button is clicked
MainWindow.on("close", (event) => {
// Prompt the user if they want to quit or minimize
const options = {
type: "question",
buttons: ["Quit", "Minimize"],
defaultId: 0,
title: "",
message: "Do you want to quit or minimize?"
}
const selectedNum = dialog.showMessageBoxSync(null, options)
if (selectedNum === 1) {
event.preventDefault();
MainWindow.minimize();
return;
}
TimerWidgetWindow.destroy();
});
app.on("activate", () => { // MacOS
MainWindow.restore();
});
MainWindow.on("minimize", () => {
TimerWidgetWindow.show();
});
MainWindow.on("restore", () => {
TimerWidgetWindow.hide();
});
TimerWidgetWindow.setAlwaysOnTop(true, "floating");
}
function createWindows() {
let MainWindow = createMainWindow();
let TimerWidgetWindow = createWidgetWindow();
return {
MainWindow,
TimerWidgetWindow
}
}
module.exports = {
createWindows,
initializeWindowEvents
};