-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
143 lines (126 loc) · 3.83 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
const electron = require("electron");
const { BrowserWindow, ipcMain, dialog, shell, Menu } = require("electron");
const app = electron.app;
const path = require("path");
const url = require("url");
const decache = require("decache");
// const autoUpdater = require('./lib/autoUpdate.js')
const autoUpdater = require("./lib/notifyUpdate.js");
const { userDataPath, getLoadTemplateObj } = require("./lib/getTemplates.js");
const { jxaBridge } = require("./lib/jxaBridge.js");
const { applicationMenu } = require("./lib/menu.js");
const {
saveMockup,
renderPNG,
cleanTempFiles,
copyMockupFile,
deleteTempJson
} = require("./lib/mockupData.js");
// Keep a global reference of the window object, if you don't, the window will
let mainWindow;
let addWindow;
app.on("ready", function() {
// Pass those values in to the BrowserWindow options
mainWindow = new BrowserWindow({
width: 950,
height: 610,
resizable: false,
title: "Select your theme",
icon: path.join(__dirname, "/app/assets/ic.png.icns"),
preloadWindow: true
});
mainWindow.loadURL("file://" + path.join(__dirname, "index.html"));
//mainWindow.openDevTools()
// Get the default mockups
const templatesPath = path.join(__dirname, "/app/assets/templates.json");
const defaultTemplates = require(templatesPath);
defaultTemplates.defaults = defaultTemplates.defaults.map(obj => {
obj.mockup.path = `${__dirname}/app/assets/${obj.mockup.path}`;
return obj;
});
/*
Keynotes
*/
ipcMain.on("load-templates", event => {
console.log("Load Templates");
getLoadTemplateObj().then(loadTemplates => {
const templates = Object.assign(defaultTemplates, loadTemplates);
event.sender.send("template-list", templates);
});
});
ipcMain.on("run-keynote", (event, templateData) => {
console.log("click");
dialog.showOpenDialog(
mainWindow,
{
title: "Select the folder or the image files",
properties: ["openFile", "openDirectory", "multiSelections"],
filters: [{ name: "Images", extensions: ["jpg", "png", "gif"] }]
},
function(filesPath) {
if (filesPath !== undefined) {
jxaBridge(templateData, filesPath);
}
}
);
});
/*
Save Mockups
*/
ipcMain.on("add-mockup", (event, data) => {
dialog.showOpenDialog(
mainWindow,
{
title: "Select your mockup image",
properties: ["openFile"],
filters: [{ name: "Images", extensions: ["png"] }]
},
function(filesPath) {
if (filesPath !== undefined) {
copyMockupFile(filesPath[0]).then(newFilePath => {
renderPNG(newFilePath).then(() => event.sender.send("change-page"));
});
}
}
);
});
ipcMain.on("load-mockup", (event, data) => {
const tempPath = path.join(`${userDataPath}/templates/`, data);
decache(tempPath);
const tempData = require(tempPath);
event.sender.send("result-mockup", tempData);
});
ipcMain.on("save-mockup", (event, data) => {
let fileName = data.name;
saveMockup(fileName, data);
deleteTempJson();
});
ipcMain.on("clear-mockup", (event, data) => {
cleanTempFiles(data);
});
/*
Others
*/
ipcMain.on("open-docs", () => {
shell.openExternal(
"https://github.com/zehfernandes/screeener#how-to-create-a-mockup"
);
});
ipcMain.on("install-update", event => {
shell.openExternal("https://github.com/zehfernandes/screeener/releases");
});
Menu.setApplicationMenu(applicationMenu);
autoUpdater.init(mainWindow);
mainWindow.on("window-all-closed", function() {
cleanTempFiles("_temp.json");
});
});
/*
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()
}
})
*/