-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
121 lines (101 loc) · 2.58 KB
/
index.js
File metadata and controls
121 lines (101 loc) · 2.58 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
"use strict";
const path = require("path");
const { app, BrowserWindow, Menu, ipcMain, shell } = require("electron");
/// const {autoUpdater} = require('electron-updater');
const { is } = require("electron-util");
const unhandled = require("electron-unhandled");
const debug = require("electron-debug");
const contextMenu = require("electron-context-menu");
const menu = require("./menu.js");
const fs = require("fs");
const {
convertPCLtoPDF,
openItemWithOSDefault,
openFileDialog,
} = require("./util.js");
unhandled();
debug();
contextMenu();
// Note: Must match `build.appId` in package.json
app.setAsDefaultProtocolClient("bobapclconverter", process.execPath, ["%1"]);
app.setAppUserModelId("com.bobaprint.pclconverter");
// Prevent window from being garbage collected
let mainWindow;
const createMainWindow = async () => {
const window_ = new BrowserWindow({
title: app.name,
show: false,
width: 600,
height: 600,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
},
});
window_.on("ready-to-show", () => {
window_.show();
});
window_.on("closed", () => {
// Dereference the window
// For multiple windows store them in an array
mainWindow = undefined;
});
await window_.loadFile(path.join(__dirname, "index.html"));
return window_;
};
// Prevent multiple instances of the app
if (!app.requestSingleInstanceLock()) {
app.quit();
}
app.on("second-instance", () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.show();
}
});
app.on("window-all-closed", () => {
if (!is.macos) {
app.quit();
}
});
app.on("activate", async () => {
if (!mainWindow) {
mainWindow = await createMainWindow();
}
});
/**
* Event Listeners
*/
app.on("open-file", async (event, filePath) => {
const outputPath = `${filePath}.pdf`;
const output = await convertPCLtoPDF({
inputPath: filePath,
outputFile: outputPath,
});
await openItemWithOSDefault({ filePath: output });
});
(async () => {
await app.whenReady();
Menu.setApplicationMenu(menu);
mainWindow = await createMainWindow();
/**
* Add IpcMain Handler
*/
ipcMain.handle("convertPCLtoPDF", async (event, args) => {
return convertPCLtoPDF(args);
});
ipcMain.handle("openItemWithOSDefault", async (event, args) => {
return openItemWithOSDefault(args);
});
ipcMain.handle("openFileDialog", async (event, args) => {
return openFileDialog(args);
});
})();
// If development environment
if (!app.isPackaged) {
require("electron-reload")(__dirname, {
electron: path.join(__dirname, "node_modules", ".bin", "electron"),
hardResetMethod: "exit",
});
}