diff options
author | 2023-01-28 04:55:49 +0530 | |
---|---|---|
committer | 2023-01-28 04:55:49 +0530 | |
commit | 68e85c3e2678efcdb1127d400fbe01e1ce3b2265 (patch) | |
tree | fbe82e7f68b51135a6817c19655772cdbfde417b /src/webview | |
parent | Merge branch 'develop' into 'release' and bump version to 6.2.3 (diff) | |
parent | 6.2.4-nightly.12 [skip ci] (diff) | |
download | ferdium-app-68e85c3e2678efcdb1127d400fbe01e1ce3b2265.tar.gz ferdium-app-68e85c3e2678efcdb1127d400fbe01e1ce3b2265.tar.zst ferdium-app-68e85c3e2678efcdb1127d400fbe01e1ce3b2265.zip |
Merge branch 'develop' into release: Bump version to '6.2.4'v6.2.4
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/badge.ts | 19 | ||||
-rw-r--r-- | src/webview/lib/RecipeWebview.ts | 3 | ||||
-rw-r--r-- | src/webview/recipe.ts | 15 |
3 files changed, 15 insertions, 22 deletions
diff --git a/src/webview/badge.ts b/src/webview/badge.ts index afecd22d4..b33d05255 100644 --- a/src/webview/badge.ts +++ b/src/webview/badge.ts | |||
@@ -1,29 +1,16 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { safeParseInt } from '../jsUtils'; | ||
2 | 3 | ||
3 | const debug = require('../preload-safe-debug')('Ferdium:Plugin:BadgeHandler'); | 4 | const debug = require('../preload-safe-debug')('Ferdium:Plugin:BadgeHandler'); |
4 | 5 | ||
5 | export default class BadgeHandler { | 6 | export default class BadgeHandler { |
6 | // TODO: Need to extract this into a utility class and reuse outside of the recipes | ||
7 | safeParseInt(text: string | number | undefined | null) { | ||
8 | if (text === undefined || text === null) { | ||
9 | return 0; | ||
10 | } | ||
11 | |||
12 | // Parse number to integer | ||
13 | // This will correct errors that recipes may introduce, e.g. | ||
14 | // by sending a String instead of an integer | ||
15 | const parsedNumber = Number.parseInt(text.toString(), 10); | ||
16 | const adjustedNumber = Number.isNaN(parsedNumber) ? 0 : parsedNumber; | ||
17 | return Math.max(adjustedNumber, 0); | ||
18 | } | ||
19 | |||
20 | setBadge( | 7 | setBadge( |
21 | direct: string | number | undefined | null, | 8 | direct: string | number | undefined | null, |
22 | indirect: string | number | undefined | null, | 9 | indirect: string | number | undefined | null, |
23 | ) { | 10 | ) { |
24 | const count = { | 11 | const count = { |
25 | direct: this.safeParseInt(direct), | 12 | direct: safeParseInt(direct), |
26 | indirect: this.safeParseInt(indirect), | 13 | indirect: safeParseInt(indirect), |
27 | }; | 14 | }; |
28 | 15 | ||
29 | debug('Sending badge count to host: %j', count); | 16 | debug('Sending badge count to host: %j', count); |
diff --git a/src/webview/lib/RecipeWebview.ts b/src/webview/lib/RecipeWebview.ts index 20be3f866..436525b9e 100644 --- a/src/webview/lib/RecipeWebview.ts +++ b/src/webview/lib/RecipeWebview.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { BrowserWindow } from '@electron/remote'; | 2 | import { BrowserWindow } from '@electron/remote'; |
3 | import { pathExistsSync, readFileSync, existsSync } from 'fs-extra'; | 3 | import { pathExistsSync, readFileSync, existsSync } from 'fs-extra'; |
4 | import { safeParseInt } from '../../jsUtils'; | ||
4 | 5 | ||
5 | const debug = require('../../preload-safe-debug')( | 6 | const debug = require('../../preload-safe-debug')( |
6 | 'Ferdium:Plugin:RecipeWebview', | 7 | 'Ferdium:Plugin:RecipeWebview', |
@@ -91,7 +92,7 @@ class RecipeWebview { | |||
91 | * @param {string | number | undefined | null} text to be parsed | 92 | * @param {string | number | undefined | null} text to be parsed |
92 | */ | 93 | */ |
93 | safeParseInt(text) { | 94 | safeParseInt(text) { |
94 | return this.badgeHandler.safeParseInt(text); | 95 | return safeParseInt(text); |
95 | } | 96 | } |
96 | 97 | ||
97 | /** | 98 | /** |
diff --git a/src/webview/recipe.ts b/src/webview/recipe.ts index dc3f39401..ed45192d3 100644 --- a/src/webview/recipe.ts +++ b/src/webview/recipe.ts | |||
@@ -44,7 +44,7 @@ import { | |||
44 | } from './spellchecker'; | 44 | } from './spellchecker'; |
45 | 45 | ||
46 | import { DEFAULT_APP_SETTINGS } from '../config'; | 46 | import { DEFAULT_APP_SETTINGS } from '../config'; |
47 | import { ifUndefined } from '../jsUtils'; | 47 | import { ifUndefined, safeParseInt } from '../jsUtils'; |
48 | import { AppStore } from '../@types/stores.types'; | 48 | import { AppStore } from '../@types/stores.types'; |
49 | import Service from '../models/Service'; | 49 | import Service from '../models/Service'; |
50 | 50 | ||
@@ -116,10 +116,15 @@ window.open = (url, frameName, features): WindowProxy | null => { | |||
116 | // then overwrite the corresponding field of the window object by injected JS. | 116 | // then overwrite the corresponding field of the window object by injected JS. |
117 | contextBridge.exposeInMainWorld('ferdium', { | 117 | contextBridge.exposeInMainWorld('ferdium', { |
118 | open: window.open, | 118 | open: window.open, |
119 | setBadge: (direct, indirect) => badgeHandler.setBadge(direct, indirect), | 119 | setBadge: ( |
120 | safeParseInt: text => badgeHandler.safeParseInt(text), | 120 | direct: string | number | null | undefined, |
121 | setDialogTitle: title => dialogTitleHandler.setDialogTitle(title), | 121 | indirect: string | number | null | undefined, |
122 | displayNotification: (title, options) => | 122 | ) => badgeHandler.setBadge(direct, indirect), |
123 | safeParseInt: (text: string | number | null | undefined) => | ||
124 | safeParseInt(text), | ||
125 | setDialogTitle: (title: string | null | undefined) => | ||
126 | dialogTitleHandler.setDialogTitle(title), | ||
127 | displayNotification: (title: string, options: any) => | ||
123 | notificationsHandler.displayNotification(title, options), | 128 | notificationsHandler.displayNotification(title, options), |
124 | getDisplayMediaSelector, | 129 | getDisplayMediaSelector, |
125 | }); | 130 | }); |