This repository was archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·149 lines (131 loc) · 3.58 KB
/
main.js
File metadata and controls
executable file
·149 lines (131 loc) · 3.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const electron = require('electron');
const path = require('path');
const url = require('url');
const fs = require('node-fs-extra');
const platform = require('os').platform();
const version = require('./package.json').version;
const db = require('./src/js/db');
const dataToHTML = require('./src/js/dataToHTML');
const formatContent = require('./src/js/contentProcess').formatContent;
const github = require('./src/js/github');
const config = require('./src/js/config');
const theme = require('./src/js/theme');
const user = require('./src/js/user');
const autoUpdate = require('./src/js/autoUpdate');
const menuTemplate = require('./src/js/menuTemplate');
const { app, BrowserWindow, Menu } = electron;
let win;
// Define a function to create window
function openWindow(path, options, isMax) {
!options && (options = {});
options = Object.assign(
{
width: 1200,
height: 800,
minHeight: 600,
minWidth: 400,
center: true,
show: false
},
options
);
win = new BrowserWindow(options);
isMax && win.maximize();
win.loadURL(url.format({
pathname: path,
protocol: 'file',
slashes: true
}));
win.on('closed', () => {
win = null;
});
win.on('ready-to-show', () => {
win.show()
});
return win;
}
// App events
const isLogged = config.get().username !== '' && config.get().password !== '';
app.on('ready', function () {
openWindow(
isLogged ?
path.join(__dirname, './src/html/index.html') :
path.join(__dirname, './src/html/login.html'),
isLogged ? null :
{
width: 600,
height: 300,
frame: false
},
isLogged);
Menu.setApplicationMenu(Menu.buildFromTemplate(menuTemplate(app, win)));
});
app.on('window-all-closed', () => {
platform !== 'darwin' && app.quit()
});
app.on('activate', () => {
win === null && (win =
openWindow(
isLogged ?
path.join(__dirname, './src/html/index.html') :
path.join(__dirname, './src/html/login.html'),
isLogged ? null :
{
width: 600,
height: 300,
frame: false
},
isLogged));
win.show();
});
const upload = {
win: null,
openWindow: function () {
this.win = openWindow(
path.join(__dirname, './src/html/uploading.html'),
{
width: 500,
height: 200,
frame: false
}, false);
this.win.show();
},
start: function() {
return github.pushRepo()
},
end: function () {
this.win.close();
this.win = null;
}
};
const logout = {
win: null,
start: function () {
this.win = openWindow(
path.join(__dirname, './src/html/logout.html'),
{
width: 600,
height: 300,
frame: false
}, false);
this.win.show();
},
end: function () {
this.win.close();
this.win = null
}
};
// Functions for rendering process
exports.platform = platform;
exports.db = db;
exports.path = path.join(__dirname);
exports.openWindow = openWindow;
exports.upload = upload;
exports.dataToHTML = dataToHTML;
exports.config = config;
exports.theme = theme;
exports.formatContent = formatContent;
exports.user = user;
exports.logout = logout;
exports.autoUpdate = autoUpdate;
exports.version = version;