diff options
Diffstat (limited to 'src/electron')
-rw-r--r-- | src/electron/Settings.js | 2 | ||||
-rw-r--r-- | src/electron/deepLinking.js | 2 | ||||
-rw-r--r-- | src/electron/ipc-api/autoUpdate.js | 55 | ||||
-rw-r--r-- | src/electron/ipc-api/download.js | 2 | ||||
-rw-r--r-- | src/electron/ipc-api/index.js | 4 | ||||
-rw-r--r-- | src/electron/ipc-api/localServer.js | 51 | ||||
-rw-r--r-- | src/electron/ipc-api/processManager.js | 8 |
7 files changed, 100 insertions, 24 deletions
diff --git a/src/electron/Settings.js b/src/electron/Settings.js index e4ad6b612..d4f0d25bf 100644 --- a/src/electron/Settings.js +++ b/src/electron/Settings.js | |||
@@ -4,7 +4,7 @@ import path from 'path'; | |||
4 | 4 | ||
5 | import { SETTINGS_PATH } from '../config'; | 5 | import { SETTINGS_PATH } from '../config'; |
6 | 6 | ||
7 | const debug = require('debug')('Franz:Settings'); | 7 | const debug = require('debug')('Ferdi:Settings'); |
8 | 8 | ||
9 | export default class Settings { | 9 | export default class Settings { |
10 | type = ''; | 10 | type = ''; |
diff --git a/src/electron/deepLinking.js b/src/electron/deepLinking.js index ef23fd3c5..70e5cfb6f 100644 --- a/src/electron/deepLinking.js +++ b/src/electron/deepLinking.js | |||
@@ -1,5 +1,5 @@ | |||
1 | export default function handleDeepLink(window, rawUrl) { | 1 | export default function handleDeepLink(window, rawUrl) { |
2 | const url = rawUrl.replace('franz://', ''); | 2 | const url = rawUrl.replace('ferdi://', ''); |
3 | 3 | ||
4 | if (!url) return; | 4 | if (!url) return; |
5 | 5 | ||
diff --git a/src/electron/ipc-api/autoUpdate.js b/src/electron/ipc-api/autoUpdate.js index 9a04c1958..506aecdf7 100644 --- a/src/electron/ipc-api/autoUpdate.js +++ b/src/electron/ipc-api/autoUpdate.js | |||
@@ -1,27 +1,36 @@ | |||
1 | import { app, ipcMain } from 'electron'; | 1 | import { app, ipcMain } from 'electron'; |
2 | import { autoUpdater } from 'electron-updater'; | 2 | import { autoUpdater } from 'electron-updater'; |
3 | 3 | ||
4 | const debug = require('debug')('Franz:ipcApi:autoUpdate'); | 4 | const debug = require('debug')('Ferdi:ipcApi:autoUpdate'); |
5 | 5 | ||
6 | export default (params) => { | 6 | export default (params) => { |
7 | if (process.platform === 'darwin' || process.platform === 'win32' || process.env.APPIMAGE) { | 7 | const disableUpdates = Boolean(params.settings.app.get('noUpdates')); |
8 | |||
9 | if (disableUpdates) { | ||
10 | autoUpdater.autoInstallOnAppQuit = false; | ||
11 | autoUpdater.autoDownload = false; | ||
12 | } else if (process.platform === 'darwin' || process.platform === 'win32' || process.env.APPIMAGE) { | ||
8 | ipcMain.on('autoUpdate', (event, args) => { | 13 | ipcMain.on('autoUpdate', (event, args) => { |
9 | try { | 14 | const enableUpdate = !params.settings.app.get('noUpdates'); |
10 | autoUpdater.autoInstallOnAppQuit = false; | 15 | |
11 | autoUpdater.allowPrerelease = Boolean(params.settings.app.get('beta')); | 16 | if (enableUpdate) { |
12 | if (args.action === 'check') { | 17 | try { |
13 | autoUpdater.checkForUpdates(); | 18 | autoUpdater.autoInstallOnAppQuit = false; |
14 | } else if (args.action === 'install') { | 19 | autoUpdater.allowPrerelease = Boolean(params.settings.app.get('beta')); |
15 | debug('install update'); | 20 | if (args.action === 'check') { |
16 | autoUpdater.quitAndInstall(); | 21 | autoUpdater.checkForUpdates(); |
17 | // we need to send a quit event | 22 | } else if (args.action === 'install') { |
18 | setTimeout(() => { | 23 | debug('install update'); |
19 | app.quit(); | 24 | autoUpdater.quitAndInstall(); |
20 | }, 20); | 25 | // we need to send a quit event |
26 | setTimeout(() => { | ||
27 | app.quit(); | ||
28 | }, 20); | ||
29 | } | ||
30 | } catch (e) { | ||
31 | console.error(e); | ||
32 | event.sender.send('autoUpdate', { error: true }); | ||
21 | } | 33 | } |
22 | } catch (e) { | ||
23 | console.error(e); | ||
24 | event.sender.send('autoUpdate', { error: true }); | ||
25 | } | 34 | } |
26 | }); | 35 | }); |
27 | 36 | ||
@@ -32,10 +41,14 @@ export default (params) => { | |||
32 | 41 | ||
33 | autoUpdater.on('update-available', (event) => { | 42 | autoUpdater.on('update-available', (event) => { |
34 | debug('update-available'); | 43 | debug('update-available'); |
35 | params.mainWindow.webContents.send('autoUpdate', { | 44 | |
36 | version: event.version, | 45 | const enableUpdate = !params.settings.app.get('noUpdates'); |
37 | available: true, | 46 | if (enableUpdate) { |
38 | }); | 47 | params.mainWindow.webContents.send('autoUpdate', { |
48 | version: event.version, | ||
49 | available: true, | ||
50 | }); | ||
51 | } | ||
39 | }); | 52 | }); |
40 | 53 | ||
41 | autoUpdater.on('download-progress', (progressObj) => { | 54 | autoUpdater.on('download-progress', (progressObj) => { |
diff --git a/src/electron/ipc-api/download.js b/src/electron/ipc-api/download.js index e6703af2d..01b81d388 100644 --- a/src/electron/ipc-api/download.js +++ b/src/electron/ipc-api/download.js | |||
@@ -3,7 +3,7 @@ import { download } from 'electron-dl'; | |||
3 | import mime from 'mime-types'; | 3 | import mime from 'mime-types'; |
4 | import fs from 'fs-extra'; | 4 | import fs from 'fs-extra'; |
5 | 5 | ||
6 | const debug = require('debug')('Franz:ipcApi:download'); | 6 | const debug = require('debug')('Ferdi:ipcApi:download'); |
7 | 7 | ||
8 | function decodeBase64Image(dataString) { | 8 | function decodeBase64Image(dataString) { |
9 | const matches = dataString.match(/^data:([A-Za-z-+/]+);base64,(.+)$/); | 9 | const matches = dataString.match(/^data:([A-Za-z-+/]+);base64,(.+)$/); |
diff --git a/src/electron/ipc-api/index.js b/src/electron/ipc-api/index.js index be8e0815a..dcdef6b32 100644 --- a/src/electron/ipc-api/index.js +++ b/src/electron/ipc-api/index.js | |||
@@ -2,10 +2,14 @@ import autoUpdate from './autoUpdate'; | |||
2 | import settings from './settings'; | 2 | import settings from './settings'; |
3 | import appIndicator from './appIndicator'; | 3 | import appIndicator from './appIndicator'; |
4 | import download from './download'; | 4 | import download from './download'; |
5 | import processManager from './processManager'; | ||
6 | import localServer from './localServer'; | ||
5 | 7 | ||
6 | export default (params) => { | 8 | export default (params) => { |
7 | settings(params); | 9 | settings(params); |
8 | autoUpdate(params); | 10 | autoUpdate(params); |
9 | appIndicator(params); | 11 | appIndicator(params); |
10 | download(params); | 12 | download(params); |
13 | processManager(params); | ||
14 | localServer(params); | ||
11 | }; | 15 | }; |
diff --git a/src/electron/ipc-api/localServer.js b/src/electron/ipc-api/localServer.js new file mode 100644 index 000000000..d12fb5708 --- /dev/null +++ b/src/electron/ipc-api/localServer.js | |||
@@ -0,0 +1,51 @@ | |||
1 | import { ipcMain, app } from 'electron'; | ||
2 | import net from 'net'; | ||
3 | import startServer from '../../server/start'; | ||
4 | |||
5 | const DEFAULT_PORT = 45569; | ||
6 | |||
7 | const portInUse = function (port) { | ||
8 | return new Promise((resolve) => { | ||
9 | const server = net.createServer((socket) => { | ||
10 | socket.write('Echo server\r\n'); | ||
11 | socket.pipe(socket); | ||
12 | }); | ||
13 | |||
14 | server.listen(port, '127.0.0.1'); | ||
15 | server.on('error', () => { | ||
16 | resolve(true); | ||
17 | }); | ||
18 | server.on('listening', () => { | ||
19 | server.close(); | ||
20 | resolve(false); | ||
21 | }); | ||
22 | }); | ||
23 | }; | ||
24 | |||
25 | let localServerStarted = false; | ||
26 | |||
27 | export default (params) => { | ||
28 | ipcMain.on('startLocalServer', () => { | ||
29 | if (!localServerStarted) { | ||
30 | // Find next unused port for server | ||
31 | let port = DEFAULT_PORT; | ||
32 | (async () => { | ||
33 | // eslint-disable-next-line no-await-in-loop | ||
34 | while (await portInUse(port) && port < DEFAULT_PORT + 10) { | ||
35 | port += 1; | ||
36 | } | ||
37 | console.log('Starting local server on port', port); | ||
38 | |||
39 | startServer( | ||
40 | app.getPath('userData'), | ||
41 | port, | ||
42 | ); | ||
43 | |||
44 | params.mainWindow.webContents.send('localServerPort', { | ||
45 | port, | ||
46 | }); | ||
47 | })(); | ||
48 | localServerStarted = true; | ||
49 | } | ||
50 | }); | ||
51 | }; | ||
diff --git a/src/electron/ipc-api/processManager.js b/src/electron/ipc-api/processManager.js new file mode 100644 index 000000000..7197a2708 --- /dev/null +++ b/src/electron/ipc-api/processManager.js | |||
@@ -0,0 +1,8 @@ | |||
1 | import { ipcMain } from 'electron'; | ||
2 | import { openProcessManager } from 'electron-process-manager'; | ||
3 | |||
4 | export default () => { | ||
5 | ipcMain.on('openProcessManager', () => { | ||
6 | openProcessManager(); | ||
7 | }); | ||
8 | }; | ||