-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
150 lines (127 loc) · 4.88 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
'use strict';
// Settings
const {DEVELOPMENT}=require('./settings.js');
if(DEVELOPMENT && process.platform == 'darwin') require('electron-reload')(__dirname);
// Required Modules
// const {app, BrowserWindow, Menu, MenuItem, shell, ipcRenderer, protocol} = require('electron');
const {app, BrowserWindow, Menu, MenuItem, shell, ipcRenderer, protocol, ipcMain, dialog} = require('electron');
// console.log(require.resolve('electron'))
const path = require('path');
// Global Variables
var window, menu;
// Menu
// click: function (menuItem, focusedWindow) { focusedWindow.webContents.undo(); }
function send(menuItem) {
window.webContents.send('MENU',menuItem.id);
}
menu=[
{
label: 'Virtual Hosts',
submenu: [
{ label: `New Document`, accelerator: 'CmdOrCtrl+N', id:'NEW', click: send },
{ label: `Open …`, accelerator: 'CmdOrCtrl+O', id:'OPEN', click: send },
{ label: `Reload`, accelerator: 'CmdOrCtrl+R', id:'RELOAD', click: send },
{ label: `Save`, accelerator: 'CmdOrCtrl+S', id:'SAVE', click: send },
{ label: `Save As …`, accelerator: 'CmdOrCtrl+Shift+S', id:'SAVEAS', click: send },
{ type:'separator' },
{ role: `quit`, accelerator: 'CmdOrCtrl+Q' }
]
},
{
label: 'Edit',
submenu: [
{ role: 'undo', accelerator: 'CmdOrCtrl+Z' },
{ role: 'redo', accelerator: 'CmdOrCtrl+Shift+Z' },
{ type:'separator'},
{ role: 'cut', accelerator: 'CmdOrCtrl+X' },
{ role: 'copy', accelerator: 'CmdOrCtrl+C' },
{ role: 'paste', accelerator: 'CmdOrCtrl+V' },
{ role: 'selectAll', accelerator: 'CmdOrCtrl+A' },
{ type:'separator' },
{ label: 'Find …', accelerator: 'CmdOrCtrl+F', id: 'FIND', click: send },
{ label: 'Find Again', accelerator: 'CmdOrCtrl+G', id:'FINDAGAIN', click: send },
]
},
{
role: 'help',
submenu: [
{ label: 'About …', id: 'ABOUT', click: send },
{ label: 'Instructions …', id: 'INSTRUCTIONS', click: send },
{ type:'separator' },
{ label: 'Virtual Hosts Home', icon: path.join(__dirname, 'images/external.png'), click: () => { shell.openExternal('https://github.com/manngo/virtual-hosts'); } },
{ label: 'Internotes Virtual Hosts', icon: path.join(__dirname,'images/external.png'), click: () => { shell.openExternal('https://www.internotes.net/virtual-hosts'); } },
{ id: 'debug-separator', type:'separator' },
{ id: 'debug-developer-tools', accelerator: 'CmdOrCtrl+Shift+I', label: 'Show Development Tools', click: function (menuItem, focusedWindow) { window.webContents.openDevTools({mode: 'detach'}); } },
]
}
];
var developmentMenu=[{
label: 'Development',
submenu: [
{ label: 'Show Development Tools', click: function (menuItem, focusedWindow) { window.webContents.openDevTools(); } },
{ label: 'Show Development Detached', click: function (menuItem, focusedWindow) { window.webContents.openDevTools({mode: 'detach'}); } },
]
}];
if(DEVELOPMENT) menu=menu.concat(developmentMenu);
// Init
function init() {
window = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
}
});
protocol.registerStringProtocol('doit',(request,callback)=>{
var [dummy,action,data,more]=decodeURI(request.url).split(/:/);
window.webContents.send('DOIT',action,data,more);
},(error)=> {});
window.once('ready-to-show', () => {
window.show();
});
window.setTitle('Virtual Hosts');
menu=Menu.buildFromTemplate(menu);
Menu.setApplicationMenu(menu);
window.loadURL(path.join('file://', __dirname, '/index.html'));
// if(DEVELOPMENT) window.webContents.openDevTools({mode: 'detach'});
if(DEVELOPMENT) window.webContents.openDevTools();
// window.webContents.setDevToolsWebContents(devtools.webContents);
window.on('closed', function () {
window = null;
});
}
// Events
app.on('ready', init);
app.on('window-all-closed', function () {
// if (process.platform !== 'darwin')
app.quit();
});
app.on('activate', function () {
if (window === null) init();
});
ipcMain.on('open-path',(event,options,returnMessage)=>{
options.properties=['openDirectory'];
openDialog(event,options,returnMessage);
});
ipcMain.on('open-file',(event,options,returnMessage)=>{
openDialog(event,options,returnMessage);
});
function openDialog(event,options,returnMessage) {
dialog.showOpenDialog(null, options).then(result => {
event.sender.send(returnMessage, result);
});
}
ipcMain.on('home',(event,options) => {
var home=`${app.getPath('home')}`;
event.returnValue = home;
});
ipcMain.on('init',(event,data) => {
var home = `${app.getPath('home')}`;
event.returnValue = JSON.stringify({home});
});
ipcMain.on('app-path',(event,options)=>{
var home=`${app.getAppPath()}`;
event.returnValue = home;
});