diff options
author | 2021-08-21 08:07:32 +0530 | |
---|---|---|
committer | 2021-08-21 08:55:38 +0530 | |
commit | b1cf1849f5bfa8f297f78a5ca58d797f466b3086 (patch) | |
tree | 658f3adeb740cf54021dfb6ad951649f0d539e6d | |
parent | refactor(cleanup): remove code that refers to paid subscription (diff) | |
download | ferdium-app-b1cf1849f5bfa8f297f78a5ca58d797f466b3086.tar.gz ferdium-app-b1cf1849f5bfa8f297f78a5ca58d797f466b3086.tar.zst ferdium-app-b1cf1849f5bfa8f297f78a5ca58d797f466b3086.zip |
chore: typescript conversion
-rw-r--r-- | src/config.ts (renamed from src/config.js) | 1 | ||||
-rw-r--r-- | src/prop-types.ts (renamed from src/prop-types.js) | 0 | ||||
-rw-r--r-- | src/sentry.ts (renamed from src/sentry.js) | 0 | ||||
-rw-r--r-- | src/stores/index.ts (renamed from src/stores/index.js) | 5 | ||||
-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 |
8 files changed, 25 insertions, 21 deletions
diff --git a/src/config.js b/src/config.ts index aeaec1089..005dd3601 100644 --- a/src/config.js +++ b/src/config.ts | |||
@@ -33,6 +33,7 @@ export const CDN_URL = 'https://cdn.franzinfra.com'; | |||
33 | 33 | ||
34 | export const KEEP_WS_LOADED_USID = '0a0aa000-0a0a-49a0-a000-a0a0a0a0a0a0'; | 34 | export const KEEP_WS_LOADED_USID = '0a0aa000-0a0a-49a0-a000-a0a0a0a0a0a0'; |
35 | 35 | ||
36 | // TODO: Need to convert many of these to i18n | ||
36 | export const HIBERNATION_STRATEGIES = { | 37 | export const HIBERNATION_STRATEGIES = { |
37 | 10: 'Extremely Fast Hibernation (10sec)', | 38 | 10: 'Extremely Fast Hibernation (10sec)', |
38 | 30: 'Very Fast Hibernation (30sec)', | 39 | 30: 'Very Fast Hibernation (30sec)', |
diff --git a/src/prop-types.js b/src/prop-types.ts index 459b9a7b9..459b9a7b9 100644 --- a/src/prop-types.js +++ b/src/prop-types.ts | |||
diff --git a/src/sentry.js b/src/sentry.ts index 4f6d7205d..4f6d7205d 100644 --- a/src/sentry.js +++ b/src/sentry.ts | |||
diff --git a/src/stores/index.js b/src/stores/index.ts index b6e481e8a..e980f2c5b 100644 --- a/src/stores/index.js +++ b/src/stores/index.ts | |||
@@ -34,9 +34,12 @@ export default (api, actions, router) => { | |||
34 | communityRecipes: communityRecipesStore, | 34 | communityRecipes: communityRecipesStore, |
35 | todos: todosStore, | 35 | todos: todosStore, |
36 | }); | 36 | }); |
37 | |||
37 | // Initialize all stores | 38 | // Initialize all stores |
38 | Object.keys(stores).forEach((name) => { | 39 | Object.keys(stores).forEach((name) => { |
39 | if (stores[name] && stores[name].initialize) stores[name].initialize(); | 40 | if (stores[name] && stores[name].initialize) { |
41 | stores[name].initialize(); | ||
42 | } | ||
40 | }); | 43 | }); |
41 | return stores; | 44 | return stores; |
42 | }; | 45 | }; |
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 | }); |