diff options
author | 2022-04-30 21:02:01 -0500 | |
---|---|---|
committer | 2022-04-30 22:09:51 -0500 | |
commit | 694f24f7ff9767b81e7e2b0f68febe2441177119 (patch) | |
tree | 447e49d1bbd9d64a0a7421a770c53d4752d47667 /src | |
parent | 6.0.0-nightly.17 [skip ci] (diff) | |
download | ferdium-app-694f24f7ff9767b81e7e2b0f68febe2441177119.tar.gz ferdium-app-694f24f7ff9767b81e7e2b0f68febe2441177119.tar.zst ferdium-app-694f24f7ff9767b81e7e2b0f68febe2441177119.zip |
Replace dependency on 'cld' with 'languagedetect' to remove native compilation issu
Diffstat (limited to 'src')
-rw-r--r-- | src/electron/ipc-api/cld.ts | 28 | ||||
-rw-r--r-- | src/electron/ipc-api/index.ts | 4 | ||||
-rw-r--r-- | src/electron/ipc-api/languageDetect.ts | 19 |
3 files changed, 21 insertions, 30 deletions
diff --git a/src/electron/ipc-api/cld.ts b/src/electron/ipc-api/cld.ts deleted file mode 100644 index a6332e22d..000000000 --- a/src/electron/ipc-api/cld.ts +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | import { ipcMain } from 'electron'; | ||
2 | // @ts-ignore | ||
3 | import cld from 'cld'; | ||
4 | |||
5 | const debug = require('../../preload-safe-debug')('Ferdium:ipcApi:cld'); | ||
6 | |||
7 | export default async () => { | ||
8 | ipcMain.handle('detect-language', async (_event, { sample }) => { | ||
9 | if (!cld) { | ||
10 | return null; | ||
11 | } | ||
12 | try { | ||
13 | const result = await cld.detect(sample); | ||
14 | debug('Checking language', 'probability', result.languages); | ||
15 | if (result.reliable) { | ||
16 | debug( | ||
17 | 'Language detected reliably, setting spellchecker language to', | ||
18 | result.languages[0].code, | ||
19 | ); | ||
20 | |||
21 | return result.languages[0].code; | ||
22 | } | ||
23 | } catch (error) { | ||
24 | console.error(error); | ||
25 | return null; | ||
26 | } | ||
27 | }); | ||
28 | }; | ||
diff --git a/src/electron/ipc-api/index.ts b/src/electron/ipc-api/index.ts index 1f69c04ee..f8306d591 100644 --- a/src/electron/ipc-api/index.ts +++ b/src/electron/ipc-api/index.ts | |||
@@ -5,7 +5,7 @@ import sessionStorage from './sessionStorage'; | |||
5 | import appIndicator from './appIndicator'; | 5 | import appIndicator from './appIndicator'; |
6 | import download from './download'; | 6 | import download from './download'; |
7 | import localServer from './localServer'; | 7 | import localServer from './localServer'; |
8 | import cld from './cld'; | 8 | import languageDetect from './languageDetect'; |
9 | import dnd from './dnd'; | 9 | import dnd from './dnd'; |
10 | import focusState from './focusState'; | 10 | import focusState from './focusState'; |
11 | 11 | ||
@@ -20,7 +20,7 @@ export default (params: { | |||
20 | appIndicator(params); | 20 | appIndicator(params); |
21 | download(params); | 21 | download(params); |
22 | localServer(params); | 22 | localServer(params); |
23 | cld(); | 23 | languageDetect(); |
24 | dnd(); | 24 | dnd(); |
25 | focusState(params); | 25 | focusState(params); |
26 | }; | 26 | }; |
diff --git a/src/electron/ipc-api/languageDetect.ts b/src/electron/ipc-api/languageDetect.ts new file mode 100644 index 000000000..d344f7097 --- /dev/null +++ b/src/electron/ipc-api/languageDetect.ts | |||
@@ -0,0 +1,19 @@ | |||
1 | import { ipcMain } from 'electron'; | ||
2 | |||
3 | import LanguageDetect from 'languagedetect'; | ||
4 | |||
5 | const debug = require('../../preload-safe-debug')('Ferdium:ipcApi:languageDetect'); | ||
6 | |||
7 | export default async () => { | ||
8 | ipcMain.handle('detect-language', async (_event, { sample }) => { | ||
9 | if (!LanguageDetect) { | ||
10 | return null; | ||
11 | } | ||
12 | const langDetector = new LanguageDetect(); | ||
13 | langDetector.setLanguageType('iso2'); | ||
14 | debug('Checking language for sample:', sample); | ||
15 | const result = langDetector.detect(sample, 1); | ||
16 | debug('Language detection result:', result); | ||
17 | return result[0][0]; | ||
18 | }); | ||
19 | }; | ||