-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
147 lines (121 loc) · 3.44 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
144
145
146
147
// Main.js
const { networkInterfaces } = require('os');
const fs = require('fs');
const path = require('path');
const { app, BrowserWindow, dialog, ipcRenderer, Menu } = require('electron');
const log = require('electron-log');
const { autoUpdater } = require("electron-updater");
const express = require('express');
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';
log.info('App starting...');
function sendStatusToWindow(text) {
log.info(text);
// win.webContents.send('message', text);
}
autoUpdater.on('checking-for-update', () => {
sendStatusToWindow('Checking for update...');
})
autoUpdater.on('update-available', (info) => {
sendStatusToWindow('Update available.');
})
autoUpdater.on('update-not-available', (info) => {
sendStatusToWindow('Update not available.');
})
autoUpdater.on('error', (err) => {
sendStatusToWindow('Error in auto-updater. ' + err);
})
autoUpdater.on('download-progress', (progressObj) => {
let log_message = "Download speed: " + progressObj.bytesPerSecond;
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
sendStatusToWindow(log_message);
})
autoUpdater.on('update-downloaded', (info) => {
sendStatusToWindow('Update downloaded');
});
//-------------------------------------------------------------------
app.on('ready', function () {
autoUpdater.checkForUpdatesAndNotify();
});
//-------------------------------------------------------------------
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
contextIsolation: false,
nodeIntegration: true
}
})
let name = app.getName();
var menu = Menu.buildFromTemplate([
{
label: "Help",
submenu: [
{
label: 'About ' + name,
role: 'about'
}]
}
])
Menu.setApplicationMenu(menu);
win.loadFile('app/index.html')
// win.webContents.openDevTools()
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
app.setAboutPanelOptions({
applicationName: "FileCast",
"applicationVersion": "v" + app.getVersion()
})
// Events
// In the Main process
const { ipcMain } = require('electron')
ipcMain.handle('folder-select', async (event, arg) => {
// log.info(arg) // prints "ping"
return await selectFolder();
})
// Functions
// Express
// Include dependencies
// Constants
const port = 80;
const Server = new (require('./folderServer').Server)(port, express(), app.getAppPath());
log.info("Starting express...");
Server.listen();
async function selectFolder() {
let filePaths;
var selectedPath
const folderPickResult = await dialog.showOpenDialog({
properties: ['openDirectory']
});
if (!folderPickResult.canceled) {
selectedPath = folderPickResult.filePaths[0];
filePaths = getFullPathsFromDir(selectedPath);
Server.setPath(selectedPath);
}
return {
fpr: selectedPath,
paths: filePaths
};
}
function getFullPathsFromDir(folderPath) {
let fullPaths = [];
let dir = fs.readdirSync(folderPath);
for (let filePath of dir) {
let absPath = path.join(folderPath, filePath);
if (fs.lstatSync(absPath).isDirectory()) continue;
fullPaths.push(filePath);
}
return fullPaths;
}