diff options
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/badge.ts (renamed from src/webview/badge.js) | 18 | ||||
-rw-r--r-- | src/webview/darkmode.ts (renamed from src/webview/darkmode.js) | 6 | ||||
-rw-r--r-- | src/webview/spellchecker.ts (renamed from src/webview/spellchecker.js) | 14 | ||||
-rw-r--r-- | src/webview/zoom.ts (renamed from src/webview/zoom.js) | 2 |
4 files changed, 20 insertions, 20 deletions
diff --git a/src/webview/badge.js b/src/webview/badge.ts index 6be4cf609..fc420b903 100644 --- a/src/webview/badge.js +++ b/src/webview/badge.ts | |||
@@ -1,8 +1,10 @@ | |||
1 | const { ipcRenderer } = require('electron'); | 1 | import { ipcRenderer } from 'electron'; |
2 | 2 | ||
3 | const debug = require('debug')('Ferdi:Plugin:BadgeHandler'); | 3 | const debug = require('debug')('Ferdi:Plugin:BadgeHandler'); |
4 | 4 | ||
5 | export class BadgeHandler { | 5 | export class BadgeHandler { |
6 | countCache: { direct: number; indirect: number; }; | ||
7 | |||
6 | constructor() { | 8 | constructor() { |
7 | this.countCache = { | 9 | this.countCache = { |
8 | direct: 0, | 10 | direct: 0, |
@@ -10,27 +12,29 @@ export class BadgeHandler { | |||
10 | }; | 12 | }; |
11 | } | 13 | } |
12 | 14 | ||
13 | _normalizeNumber(count) { | 15 | _normalizeNumber(count: string | number) { |
14 | // Parse number to integer | 16 | // Parse number to integer |
15 | // This will correct errors that recipes may introduce, e.g. | 17 | // This will correct errors that recipes may introduce, e.g. |
16 | // by sending a String instead of an integer | 18 | // by sending a String instead of an integer |
17 | const parsedNumber = parseInt(count, 10); | 19 | const parsedNumber = parseInt(count.toString(), 10); |
18 | const adjustedNumber = Number.isNaN(parsedNumber) ? 0 : parsedNumber; | 20 | const adjustedNumber = Number.isNaN(parsedNumber) ? 0 : parsedNumber; |
19 | return Math.max(adjustedNumber, 0); | 21 | return Math.max(adjustedNumber, 0); |
20 | } | 22 | } |
21 | 23 | ||
22 | setBadge(direct, indirect) { | 24 | setBadge(direct: number, indirect: number) { |
23 | if (this.countCache.direct === direct | 25 | if (this.countCache.direct === direct |
24 | && this.countCache.indirect === indirect) return; | 26 | && this.countCache.indirect === indirect) { |
27 | return; | ||
28 | } | ||
25 | 29 | ||
26 | const count = { | 30 | const count = { |
27 | direct: this._normalizeNumber(direct), | 31 | direct: this._normalizeNumber(direct), |
28 | indirect: this._normalizeNumber(indirect), | 32 | indirect: this._normalizeNumber(indirect), |
29 | }; | 33 | }; |
30 | 34 | ||
35 | debug('Sending badge count to host', count); | ||
31 | ipcRenderer.sendToHost('message-counts', count); | 36 | ipcRenderer.sendToHost('message-counts', count); |
32 | Object.assign(this.countCache, count); | ||
33 | 37 | ||
34 | debug('Sending badge count to host', count); | 38 | Object.assign(this.countCache, count); |
35 | } | 39 | } |
36 | } | 40 | } |
diff --git a/src/webview/darkmode.js b/src/webview/darkmode.ts index 7435d6404..e06c22f11 100644 --- a/src/webview/darkmode.js +++ b/src/webview/darkmode.ts | |||
@@ -7,9 +7,9 @@ const debug = require('debug')('Ferdi:DarkMode'); | |||
7 | 7 | ||
8 | const chars = [...'abcdefghijklmnopqrstuvwxyz']; | 8 | const chars = [...'abcdefghijklmnopqrstuvwxyz']; |
9 | 9 | ||
10 | const ID = [...Array(20)].map(() => chars[Math.random() * chars.length | 0]).join``; | 10 | const ID = [...Array(20)].map(() => chars[Math.random() * chars.length | 0]).join(''); |
11 | 11 | ||
12 | export function injectDarkModeStyle(recipePath) { | 12 | export function injectDarkModeStyle(recipePath: string) { |
13 | const darkModeStyle = join(recipePath, 'darkmode.css'); | 13 | const darkModeStyle = join(recipePath, 'darkmode.css'); |
14 | if (pathExistsSync(darkModeStyle)) { | 14 | if (pathExistsSync(darkModeStyle)) { |
15 | const data = readFileSync(darkModeStyle); | 15 | const data = readFileSync(darkModeStyle); |
@@ -17,7 +17,7 @@ export function injectDarkModeStyle(recipePath) { | |||
17 | styles.id = ID; | 17 | styles.id = ID; |
18 | styles.innerHTML = data.toString(); | 18 | styles.innerHTML = data.toString(); |
19 | 19 | ||
20 | document.querySelector('head').appendChild(styles); | 20 | document.querySelector('head')?.appendChild(styles); |
21 | 21 | ||
22 | debug('Injected Dark Mode style with ID', ID); | 22 | debug('Injected Dark Mode style with ID', ID); |
23 | } | 23 | } |
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.ts index 0f4715207..aa9a2350f 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.ts | |||
@@ -8,17 +8,13 @@ const webContents = getCurrentWebContents(); | |||
8 | const [defaultLocale] = webContents.session.getSpellCheckerLanguages(); | 8 | const [defaultLocale] = webContents.session.getSpellCheckerLanguages(); |
9 | debug('Spellchecker default locale is', defaultLocale); | 9 | debug('Spellchecker default locale is', defaultLocale); |
10 | 10 | ||
11 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) { | 11 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { |
12 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter((key) => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); | 12 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter((key) => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); |
13 | 13 | ||
14 | if (locales.length >= 1) { | 14 | return locales.length >= 1 ? locales[0] : null; |
15 | return locales[0]; | ||
16 | } | ||
17 | |||
18 | return null; | ||
19 | } | 15 | } |
20 | 16 | ||
21 | export function switchDict(locale) { | 17 | export function switchDict(locale: string) { |
22 | if (isMac) { | 18 | if (isMac) { |
23 | debug('Ignoring dictionary changes on macOS'); | 19 | debug('Ignoring dictionary changes on macOS'); |
24 | return; | 20 | return; |
@@ -26,9 +22,9 @@ export function switchDict(locale) { | |||
26 | 22 | ||
27 | debug('Setting spellchecker locale to', locale); | 23 | debug('Setting spellchecker locale to', locale); |
28 | 24 | ||
29 | const locales = []; | 25 | const locales: string[] = []; |
30 | const foundLocale = getSpellcheckerLocaleByFuzzyIdentifier(locale); | ||
31 | 26 | ||
27 | const foundLocale = getSpellcheckerLocaleByFuzzyIdentifier(locale); | ||
32 | if (foundLocale) { | 28 | if (foundLocale) { |
33 | locales.push(foundLocale); | 29 | locales.push(foundLocale); |
34 | } | 30 | } |
diff --git a/src/webview/zoom.js b/src/webview/zoom.ts index ec2d672b6..53ddf46c6 100644 --- a/src/webview/zoom.js +++ b/src/webview/zoom.ts | |||
@@ -29,7 +29,7 @@ ipcRenderer.on('zoomReset', () => { | |||
29 | ipcRenderer.sendToHost('zoomLevel', { zoom: zoomLevel }); | 29 | ipcRenderer.sendToHost('zoomLevel', { zoom: zoomLevel }); |
30 | }); | 30 | }); |
31 | 31 | ||
32 | ipcRenderer.on('setZoom', (e, arg) => { | 32 | ipcRenderer.on('setZoom', (_e, arg) => { |
33 | zoomLevel = arg; | 33 | zoomLevel = arg; |
34 | webFrame.setZoomLevel(zoomLevel); | 34 | webFrame.setZoomLevel(zoomLevel); |
35 | }); | 35 | }); |