-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
85 lines (73 loc) · 2.06 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
/**
* Configure the Electron Window
*/
const {app, BrowserWindow, screen, shell} = require("electron");
const upath = require('upath');
const os = require('os');
const fs = require('fs');
const fse = require('fs-extra');
var wikiDir = ".include";
var homeDir = os.homedir();
var platform = os.platform;
var defaultsDir = upath.join(__dirname, "default-settings");
var tiddlyDir = upath.join(homeDir, wikiDir);
var port = 23981;
var mainWindow;
// If dirs does not exist, create and copy in server template
if (!fs.existsSync(tiddlyDir)) {
fs.mkdirSync(tiddlyDir);
// Apply default settings and tiddlers
fse.copySync(`${defaultsDir}/`, `${tiddlyDir}/`);
}
// Start tiddlywiki
var $tw = require('tiddlywiki').TiddlyWiki();
$tw.boot.argv = [tiddlyDir, "--listen", "host=localhost", "port=" + port];
$tw.boot.boot();
function createWindow() {
var {width, height} = screen.getPrimaryDisplay().workAreaSize;
var icon = "";
switch (platform) {
case "win32":
icon = "resources/include.ico";
break;
case "darwin":
icon = "resources/include.icns";
break;
default:
icon = "resources/include.png";
break;
}
mainWindow = new BrowserWindow({
width: width,
height: height,
icon: icon,
webPreferences: {
nodeIntegration: true,
zoomFactor: 1.0,
},
backgroundColor: '#22272e',
titleBarStyle: 'hidden',
titleBarOverlay: true,
autoHideMenuBar: true
});
mainWindow.loadURL("http://localhost:" + port);
mainWindow.on("closed", function () {
mainWindow = null;
});
mainWindow.webContents.on('new-window', function (e, url) {
e.preventDefault();
shell.openExternal(url);
});
}
app.on("ready", createWindow);
app.on("resize", function (e, x, y) {
mainWindow.setSize(x, y);
});
app.on("window-all-closed", function () {
app.quit();
});
app.on("activate", function () {
if (mainWindow === null) {
createWindow();
}
});