-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
72 lines (61 loc) · 1.8 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
/**
* Created by jaro on 27.10.16.
*/
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const Url = require('url');
const Path = require('path');
let window;
function createWindow() {
window = new BrowserWindow({width: 800, height: 600, frame: false, titleBarStyle: 'hidden-inset', show: false});
if(process.argv.length > 2){ //path/toTelectron . debug
window.webContents.openDevTools();
}
window.loadURL(`file://${__dirname}/app/index.html`);
window.once('ready-to-show', () => {
//hack for not showing white first
window.show();
});
window.on('closed', function () {
window = null
})
}
app.on('ready', createWindow);
// macOS foo.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
if (window === null) {
createWindow()
}
});
app.on('ready', function () {
// register protocol browser://
electron.protocol.registerFileProtocol('browser', (request, cb) => {
if ( !request.url ) {
cb (-3); // ABORTED
return;
}
let url = decodeURIComponent(request.url);
let uri = Url.parse(url);
let relativePath = uri.hostname;
if ( uri.pathname ) {
relativePath = Path.join( relativePath, uri.pathname );
}
if(!relativePath.search(".")) {
relativePath += ".html";
}
let file = Path.join( __dirname + "/app/pages", relativePath);
cb ( { path: file } );
}, err => {
if (err) {
console.log('Failed to register protocol browser, %s', err.message);
return;
}
console.log('protocol browser registered');
});
});