forked from evolus/pencil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
134 lines (105 loc) · 3.57 KB
/
index.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
"use strict";
if (require('electron-squirrel-startup')) {
return;
}
const {app, protocol, shell, BrowserWindow} = require("electron");
const pkg = require("./package.json");
const fs = require("fs");
const path = require("path");
app.commandLine.appendSwitch("allow-file-access-from-files");
app.commandLine.appendSwitch("allow-file-access");
// Disable hardware acceleration by default for Linux
// TODO: implement a setting for this one and requires a restart after changing that value
if (process.platform.trim().toLowerCase() == "linux" && app.disableHardwareAcceleration) {
console.log("Hardware acceleration disabled for Linux.");
app.disableHardwareAcceleration();
}
var handleRedirect = (e, url) => {
e.preventDefault();
shell.openExternal(url);
}
var mainWindow = null;
function createWindow() {
var mainWindowProperties = {
title: pkg.name,
autoHideMenuBar: true,
webPreferences: {
webSecurity: false,
allowRunningInsecureContent: true,
allowDisplayingInsecureContent: true,
defaultEncoding: "UTF-8"
},
};
var iconFile = process.platform == "win32" ? "app.ico" : "css/images/logo-shadow.png";
mainWindowProperties.icon = path.join(__dirname, iconFile);
mainWindow = new BrowserWindow(mainWindowProperties);
var devEnable = false;
if (process.argv.indexOf("--enable-dev") >= 0) {
devEnable = true;
} else if (process.env.PENCIL_ENV === "development") {
devEnable = true;
}
app.devEnable = devEnable;
mainWindow.hide();
mainWindow.maximize();
if (devEnable) {
mainWindow.webContents.openDevTools();
} else {
mainWindow.setMenu(null);
}
var mainUrl = "file://" + __dirname + "/app.xhtml";
mainWindow.loadURL(mainUrl);
mainWindow.show();
//mainWindow.webContents.openDevTools();
mainWindow.on("closed", function() {
mainWindow = null;
app.exit(0);
});
if (process.platform == 'darwin') {
var {MacOSToolbar} = require('./views/toolbars/MacOSToolbar');
MacOSToolbar.createMacOSToolbar();
}
mainWindow.webContents.on("will-navigate", handleRedirect);
mainWindow.webContents.on("new-window", handleRedirect);
app.mainWindow = mainWindow;
global.mainWindow = mainWindow;
}
// Quit when all windows are closed.
app.on("window-all-closed", function() {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on('ready', function() {
protocol.registerBufferProtocol("ref", function(request, callback) {
var path = request.url.substr(6);
console.log("PATH", path);
fs.readFile(path, function (err, data) {
console.log("Got data: ", data.length);
callback({mimeType: "image/jpeg", data: new Buffer(data)});
});
}, function (error, scheme) {
if (error) {
console.log("ERROR REGISTERING", error);
}
});
// Create the browser window.
createWindow();
const renderer = require("./pencil-core/common/renderer");
renderer.start();
const webPrinter = require("./pencil-core/common/webPrinter");
webPrinter.start();
});
app.on("activate", function() {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
} else {
app.show();
}
});
process.on('uncaughtException', function (error) {
console.error(error);
});
console.log("Platform: " + process.platform.trim());