forked from code-artisan/hexo-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.es6
137 lines (111 loc) · 4.24 KB
/
app.es6
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
import url from 'url';
import path from 'path';
import fs from 'fs-jetpack';
// import glob from 'glob';
import { app, BrowserWindow, Menu, MenuItem, ipcMain as ipc } from 'electron';
import { autoUpdater } from 'electron-updater';
import { ASSETS_PATH } from './app/config/global.es6';
import registry from './lib/socket.es6';
import template from './app/config/menu.es6';
import { getPrefix } from './lib/utilities.es6';
import editorMenu from './app/config/context/editor.es6';
import BlogController from './app/controllers/BlogController.es6';
import WindowController from './app/controllers/WindowController.es6';
import ArticleController from './app/controllers/ArticleController.es6';
import SettingController from './app/controllers/SettingController.es6';
let mainWindow = null;
function sendStatusToWindow(message) {
mainWindow.webContents.send('message', message);
}
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
title: 'Hexo 客户端',
minWidth: 800,
minHeight: 600,
icon: path.join(__dirname, 'build', 'icon.ico')
});
let prefix = getPrefix(),
file = url.format({
pathname: path.join(ASSETS_PATH, 'index.html'),
protocol: 'file:',
slashes: true,
hash: typeof prefix === 'string' && prefix.length !== 0 ? '#/' : '#/install'
});
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
// and load the index.html of the app.
mainWindow.loadURL(file);
if (process.env.NODE_ENV === 'development') {
// Open the DevTools.
mainWindow.webContents.openDevTools();
}
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}
app.on('ready', function () {
// glob('./app/controller/**Controller.es6', function (error, result) {
// result.forEach(function (filepath) {
// filepath = filepath.replace('./app/', './');
// console.log( filepath, filepath === './controller/ArticleController.es6', require(filepath), require('./controller/ArticleController.es6') );
// registry(require(filepath));
// });
// });
createWindow();
registry(BlogController);
registry(WindowController);
registry(ArticleController);
registry(SettingController);
});
app.on('activate', function () {
// On macOS 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();
});
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') app.quit();
});
ipc.on('show-editor-context-menu', function ({sender}) {
const win = BrowserWindow.fromWebContents(sender);
editorMenu.popup( win );
});
// app.on('browser-window-created', function (event, win) {
// win.webContents.on('context-menu', function (e, params) {
// if (params.linkText) {
// parameters = params;
// }
// contextMenu.popup(win, params.x, params.y);
// });
// });
// autoUpdater
// .on('updater-downloaded', function () {
// autoUpdater.quitAndInstall();
// })
// .on('checking-for-update', () => {
// sendStatusToWindow('正在检查更新...');
// })
// .on('update-available', (ev, info) => {
// sendStatusToWindow('Update available.');
// })
// .on('update-not-available', (ev, info) => {
// sendStatusToWindow('已经是最新版本.');
// })
// .on('error', (ev, err) => {
// sendStatusToWindow('更新失败.');
// })
// .on('download-progress', (progressObj) => {
// let log_message = "正在下载: " + progressObj.bytesPerSecond;
// log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
// log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
// sendStatusToWindow(log_message);
// })
// .on('update-downloaded', (ev, info) => {
// sendStatusToWindow('下载完成,正在更新并重启...');
// });