aboutsummaryrefslogtreecommitdiffstats
path: root/src/electron
diff options
context:
space:
mode:
authorLibravatar Amine El Mouafik <412895+kytwb@users.noreply.github.com>2021-02-08 10:34:45 +0100
committerLibravatar GitHub <noreply@github.com>2021-02-08 10:34:45 +0100
commit035002ceedf78d5ec73eabc0df7f06139939b967 (patch)
tree1c0d1e9531bae05fb65d70b9ea25baf404b74fe1 /src/electron
parentdocs: add k0staa as a contributor (#1193) (diff)
downloadferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.tar.gz
ferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.tar.zst
ferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.zip
Synchronize with Franz 5.6.0 (#1033)
Co-authored-by: FranzBot <i18n@meetfranz.com> Co-authored-by: vantezzen <hello@vantezzen.io> Co-authored-by: Makazzz <makazzzpro@live.ca> Co-authored-by: Stefan Malzner <stefan@adlk.io> Co-authored-by: Amine Mouafik <amine@mouafik.fr>
Diffstat (limited to 'src/electron')
-rw-r--r--src/electron/Settings.js4
-rw-r--r--src/electron/ipc-api/cld.js20
-rw-r--r--src/electron/ipc-api/dnd.js16
-rw-r--r--src/electron/ipc-api/download.js26
-rw-r--r--src/electron/ipc-api/index.js4
-rw-r--r--src/electron/ipc-api/settings.js4
6 files changed, 64 insertions, 10 deletions
diff --git a/src/electron/Settings.js b/src/electron/Settings.js
index d4f0d25bf..743d48632 100644
--- a/src/electron/Settings.js
+++ b/src/electron/Settings.js
@@ -33,6 +33,10 @@ export default class Settings {
33 return this.store; 33 return this.store;
34 } 34 }
35 35
36 get allSerialized() {
37 return toJS(this.store);
38 }
39
36 get(key) { 40 get(key) {
37 return this.store[key]; 41 return this.store[key];
38 } 42 }
diff --git a/src/electron/ipc-api/cld.js b/src/electron/ipc-api/cld.js
new file mode 100644
index 000000000..23f18aa94
--- /dev/null
+++ b/src/electron/ipc-api/cld.js
@@ -0,0 +1,20 @@
1import { ipcMain } from 'electron';
2import cld from 'cld';
3
4const debug = require('debug')('Franz:ipcApi:cld');
5
6export default async () => {
7 ipcMain.handle('detect-language', async (event, { sample }) => {
8 try {
9 const result = await cld.detect(sample);
10 debug('Checking language', 'probability', result.languages);
11 if (result.reliable) {
12 debug('Language detected reliably, setting spellchecker language to', result.languages[0].code);
13
14 return result.languages[0].code;
15 }
16 } catch (e) {
17 console.error(e);
18 }
19 });
20};
diff --git a/src/electron/ipc-api/dnd.js b/src/electron/ipc-api/dnd.js
new file mode 100644
index 000000000..4589aa222
--- /dev/null
+++ b/src/electron/ipc-api/dnd.js
@@ -0,0 +1,16 @@
1import { ipcMain } from 'electron';
2import { getDoNotDisturb } from '@meetfranz/electron-notification-state';
3
4const debug = require('debug')('Franz:ipcApi:dnd');
5
6export default async () => {
7 ipcMain.handle('get-dnd', async () => {
8 try {
9 const isDND = getDoNotDisturb();
10 debug('Fetching DND state, set to', isDND);
11 return isDND;
12 } catch (e) {
13 console.error(e);
14 }
15 });
16};
diff --git a/src/electron/ipc-api/download.js b/src/electron/ipc-api/download.js
index 36eca3c9f..16de66229 100644
--- a/src/electron/ipc-api/download.js
+++ b/src/electron/ipc-api/download.js
@@ -17,9 +17,15 @@ function decodeBase64Image(dataString) {
17 17
18export default (params) => { 18export default (params) => {
19 ipcMain.on('download-file', async (event, { url, content, fileOptions = {} }) => { 19 ipcMain.on('download-file', async (event, { url, content, fileOptions = {} }) => {
20 // We're passing a fake browserWindow to `electron-dl` in order to access the
21 // webContents of the webview that has initiated the download
22 const fakeWindow = {
23 webContents: event.sender.webContents,
24 };
25
20 try { 26 try {
21 if (!content) { 27 if (!content) {
22 const dl = await download(params.mainWindow, url, { 28 const dl = await download(fakeWindow, url, {
23 saveAs: true, 29 saveAs: true,
24 }); 30 });
25 debug('File saved to', dl.savePath); 31 debug('File saved to', dl.savePath);
@@ -27,14 +33,20 @@ export default (params) => {
27 const extension = mime.extension(fileOptions.mime); 33 const extension = mime.extension(fileOptions.mime);
28 const filename = `${fileOptions.name}.${extension}`; 34 const filename = `${fileOptions.name}.${extension}`;
29 35
30 dialog.showSaveDialog(params.mainWindow, { 36 try {
31 defaultPath: filename, 37 const saveDialog = await dialog.showSaveDialog(params.mainWindow, {
32 }, (name) => { 38 defaultPath: filename,
39 });
40
41 if (saveDialog.canceled) return;
42
33 const binaryImage = decodeBase64Image(content); 43 const binaryImage = decodeBase64Image(content);
34 fs.writeFileSync(name, binaryImage, 'binary'); 44 fs.writeFileSync(saveDialog.filePath, binaryImage, 'binary');
35 45
36 debug('File blob saved to', name); 46 debug('File blob saved to', saveDialog.filePath);
37 }); 47 } catch (err) {
48 console.log(err);
49 }
38 } 50 }
39 } catch (e) { 51 } catch (e) {
40 console.error(e); 52 console.error(e);
diff --git a/src/electron/ipc-api/index.js b/src/electron/ipc-api/index.js
index dcdef6b32..6181e5628 100644
--- a/src/electron/ipc-api/index.js
+++ b/src/electron/ipc-api/index.js
@@ -4,6 +4,8 @@ import appIndicator from './appIndicator';
4import download from './download'; 4import download from './download';
5import processManager from './processManager'; 5import processManager from './processManager';
6import localServer from './localServer'; 6import localServer from './localServer';
7import cld from './cld';
8import dnd from './dnd';
7 9
8export default (params) => { 10export default (params) => {
9 settings(params); 11 settings(params);
@@ -12,4 +14,6 @@ export default (params) => {
12 download(params); 14 download(params);
13 processManager(params); 15 processManager(params);
14 localServer(params); 16 localServer(params);
17 cld(params);
18 dnd();
15}; 19};
diff --git a/src/electron/ipc-api/settings.js b/src/electron/ipc-api/settings.js
index 6d48c54e3..15182739c 100644
--- a/src/electron/ipc-api/settings.js
+++ b/src/electron/ipc-api/settings.js
@@ -2,11 +2,9 @@ import { ipcMain } from 'electron';
2 2
3export default (params) => { 3export default (params) => {
4 ipcMain.on('getAppSettings', (event, type) => { 4 ipcMain.on('getAppSettings', (event, type) => {
5 const cleanData = JSON.parse(JSON.stringify(params.settings[type].all));
6
7 params.mainWindow.webContents.send('appSettings', { 5 params.mainWindow.webContents.send('appSettings', {
8 type, 6 type,
9 data: cleanData, 7 data: params.settings[type].allSerialized,
10 }); 8 });
11 }); 9 });
12 10