This repository was archived by the owner on Jan 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpatternbot.js
More file actions
97 lines (73 loc) · 2.36 KB
/
patternbot.js
File metadata and controls
97 lines (73 loc) · 2.36 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
'use strict';
const {app, ipcMain, BrowserWindow, dialog, Menu} = require('electron');
const is = require('electron-is');
const appMenu = require(`${__dirname}/app/main/menu/app-menu`);
const menuFile = require(`${__dirname}/app/main/menu/helpers/file`);
const menuHelp = require(`${__dirname}/app/main/menu/helpers/help`);
const env = process.env.NODE_ENV;
const DEBUG = !!(env === 'development');
const appPkg = require(`${__dirname}/package.json`);
require('electron-debug')({ showDevTools: true });
let mainWindow;
const bindMenus = function () {
menuFile.bind(appMenu, mainWindow.id);
menuHelp.bind(appMenu, mainWindow.id);
};
const createMainWindow = function (next) {
mainWindow = new BrowserWindow({
width: 400,
minWidth: 400,
height: 400,
show: false,
minHeight: 400,
vibrancy: 'light',
});
mainWindow.loadURL(`file://${__dirname}/app/renderer/windows/main/main.html`);
bindMenus();
mainWindow.on('closed', function () {
mainWindow = null;
if (!is.macOS()) app.quit();
});
mainWindow.on('focus', function () {
mainWindow.webContents.send('app:focus');
});
mainWindow.on('blur', function () {
mainWindow.webContents.send('app:blur');
});
mainWindow.once('ready-to-show', function () {
mainWindow.show();
if (next) next();
});
};
const updateAppMenu = function () {
Menu.setApplicationMenu(Menu.buildFromTemplate(appMenu.getMenuTemplate()));
};
app.on('ready', function () {
updateAppMenu();
createMainWindow();
});
app.on('window-all-closed', function () {
if (!is.macOS()) app.quit();
});
app.on('activate', function () {
if (mainWindow === null) createMainWindow();
});
app.on('open-file', function (e, filepath) {
e.preventDefault();
if (typeof filepath !== 'string') filepath = filepath[0];
if (mainWindow === null) {
createMainWindow(function () {
mainWindow.webContents.send('app:add-folder', filepath);
});
} else {
mainWindow.webContents.send('app:add-folder', filepath);
}
});
ipcMain.on('menu:enable-file-items', function () {
appMenu.updateMenuItem('file,generate', { enabled: true });
appMenu.updateMenuItem('file,browse-pattern-library', { enabled: true });
});
ipcMain.on('menu:disable-file-items', function () {
appMenu.updateMenuItem('file,generate', { enabled: false });
appMenu.updateMenuItem('file,browse-pattern-library', { enabled: false });
});