-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
153 lines (135 loc) · 4.03 KB
/
start.js
File metadata and controls
153 lines (135 loc) · 4.03 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const electron = require('electron');
const { app, BrowserWindow, Tray, Menu } = require('electron');
const ipcHandler = require('./mainIpc.js');
const os = require("os");
const { exec } = require('child_process');
const path = require('path')
let debugMode = false;
//debugMode = true;
let win = null;
let tray = null;
let isMainMode = true;
let mainTrayMenu;
let calTrayMenu;
function createWindow () {
if(debugMode) {
win = new BrowserWindow({
width: 1024,
height: 768,
webPreferences: {
nodeIntegration: true
}
});
} else {
let displays = electron.screen.getAllDisplays();
let display = displays.find((dis) => {
//return (dis.bounds.x !== 0 || dis.bounds.y !== 0);
return (dis.bounds.x == 0 || dis.bounds.y == 0);
})
// 브라우저 창을 생성합니다.
win = new BrowserWindow({
// width: 1024,
// height: 768,
x: display.bounds.x,
y: display.bounds.y,
fullscreen: true,
frame: false,
webPreferences: {
nodeIntegration: true
}
});
}
tray = new Tray('icon.png');
/*const contextMenu = Menu.buildFromTemplate([
{ label: 'Calendar Mode', click: swapMode },
{ label: 'Quit', click: win.close() }
]);*/
tray.setToolTip('School Desktop');
//tray.setContextMenu(contextMenu);
mainTrayMenu = Menu.buildFromTemplate([
{ label: '30724 정종현' },
{ label: 'Quit', click: ()=>{win.close();} }
]);
calTrayMenu = Menu.buildFromTemplate([
{ label: 'Main Mode', click: swapMode },
{ label: 'Quit', click: ()=>{win.close();} }
]);
// and load the index.html of the app.
//win.loadFile('./web/winmain/index.html')
loadMode(true);
// 개발자 도구를 엽니다.
if(debugMode) win.webContents.openDevTools();
if(!debugMode) makeWallpaper(getHwnd(win));
}
function loadMode(isMain) {
isMainMode = isMain;
if(isMainMode) {
tray.setContextMenu(mainTrayMenu);
//win.loadFile('./web/winmain/index.html');
win.loadURL(`file://${path.join(__dirname, './web/winmain/index.html')}`);
} else {
tray.setContextMenu(calTrayMenu);
//win.loadFile('./web/wincal/index.html');
win.loadURL(`file://${path.join(__dirname, './web/wincal/index.html')}`);
}
}
function swapMode() {
loadMode(!isMainMode);
}
function getHwnd(win) {
let hbuf = win.getNativeWindowHandle();
if (os.endianness() == "LE") {
return hbuf.readInt32LE();
} else {
return hbuf.readInt32BE();
}
}
function makeWallpaper(hwnd) {
exec(`cd cpp & wallpaper_setter.exe ${hwnd}`, (err, stdout, stderr) => {
if (err) {
//some err occurred
console.error(err);
} else {
// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
}
});
}
function resetWallpaper() {
console.log('aa');
exec('cd cpp & wallpaper_resetter.exe', (err, stdout, stderr) => {
if (err) {
//some err occurred
console.error(err);
} else {
// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
}
app.quit();
});
}
// 이 메소드는 Electron의 초기화가 완료되고
// 브라우저 윈도우가 생성될 준비가 되었을때 호출된다.
// 어떤 API는 이 이벤트가 나타난 이후에만 사용할 수 있습니다.
app.whenReady().then(createWindow)
// 모든 윈도우가 닫히면 종료된다.
app.on('window-all-closed', () => {
// macOS에서는 사용자가 명확하게 Cmd + Q를 누르기 전까지는
// 애플리케이션이나 메뉴 바가 활성화된 상태로 머물러 있는 것이 일반적입니다.
if (process.platform !== 'darwin') {
if(debugMode) {
app.quit();
} else {
resetWallpaper();
}
}
})
app.on('activate', () => {
// macOS에서는 dock 아이콘이 클릭되고 다른 윈도우가 열려있지 않았다면
// 앱에서 새로운 창을 다시 여는 것이 일반적입니다.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})