-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
124 lines (113 loc) · 3.94 KB
/
Copy pathmain.js
File metadata and controls
124 lines (113 loc) · 3.94 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
const {app, BrowserWindow, systemPreferences, ipcMain, webContents} = require('electron')
const isDev = require('electron-is-dev');
const path = require('path');
let win;
function createWindow(){
// make browser window
win = new BrowserWindow(
{
width: 400,
height: 500,
resizable: false,
fullscreenable: false,
maximizable: false,
disableHtmlFullscreenWindowResize: true,
icon: path.join(__dirname, "assets", "icon", "dhlogo.png"),
webPreferences: {
//a security risk only when you're executing some untrusted remote code on your application.
// nodeIntegration: true,
// contextIsolation: false,
preload: path.join(__dirname, 'renderer/preload.js'),
},
}
)
// load main html
// Delete win.loadURL function for security
win.loadFile(path.join(__dirname, 'index.html'))
// open DevTool option
// if (isDev) {
// win.webContents.openDevTools()
// }
// event when window closed
win.on('closed', () => {
win = null
})
//dialog setting
let modalWindow
ipcMain.on('electron-modal', (event) => {
//Modal Window Setting
modalWindow = new BrowserWindow({
parent: win, // set child window
title: "Save file",
width: 300,
height: 150,
minimizable: false,
fullscreenable: false,
maximizable: false,
resizable: false,
skipTaskbar: true,
icon: path.join(__dirname, "assets", "icon", "dhlogo.png"),
modal: true, // when open child window, set parents window to untouchable
// titleBarStyle: 'hidden',
webPreferences: {
preload: path.join(__dirname, 'renderer/preload.js'),
}
});
//initial setting
modalWindow.setMenu(null);
modalWindow.setMenuBarVisibility(false);
//HTML File
modalWindow.loadFile(path.join(__dirname, 'renderer/pages/modal.html'));
modalWindow.on('ready-to-show', () => {
modalWindow.show();
})
//Modal Closed Option
modalWindow.on('closed', () => { modalWindow = null; })
ipcMain.on('electron-modal-value', (e, value) => {
// console.log(modalWindow); // for debugging
modalWindow.close();
event.returnValue = value;
})
})
let fileList;
ipcMain.on('open-list', () => {
fileList = new BrowserWindow({
width: 400,
height: 500,
icon: path.join(__dirname, "assets", "icon", "dhlogo.png"),
webPreferences: {
preload: path.join(__dirname, 'renderer/preload.js'),
},
});
//initial setting
fileList.setMenu(null);
fileList.setMenuBarVisibility(false);
fileList.loadFile(path.join(__dirname, 'renderer/pages/fileList.html'));
// fileList.webContents.openDevTools() // for debugging
fileList.on('ready-to-show', () => {
fileList.show();
});
// Window Close Option
fileList.on('closed', () => { fileList = null; });
})
// Permission to Access Microphone
// console.log(systemPreferences.getMediaAccessStatus('microphone')) // not determined -> NSMicrophone.. plist..
const status = systemPreferences.getMediaAccessStatus('microphone')
console.log(status)
const access = systemPreferences.askForMediaAccess('microphone')
console.log(access)
}
/* Electron */
app.whenReady().then(() => {
createWindow();
if (process.platform == 'darwin') app.dock.setIcon(path.join(__dirname, "assets", "icon", "dhlogo.png"));
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
})
// On mac, command+Q
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
})