diff options
author | André Oliveira <37463445+SpecialAro@users.noreply.github.com> | 2024-05-13 22:47:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-13 22:47:35 +0100 |
commit | 6167b6c7e9f49adee065646e2d28e28500753ebd (patch) | |
tree | 15d4746188e95af98ae7cf6e426c82ffdfed7ee1 /src | |
parent | Fix notifications on all services (#1593) (diff) | |
download | ferdium-app-6167b6c7e9f49adee065646e2d28e28500753ebd.tar.gz ferdium-app-6167b6c7e9f49adee065646e2d28e28500753ebd.tar.zst ferdium-app-6167b6c7e9f49adee065646e2d28e28500753ebd.zip |
Fix accelerators (#1752)
* fix: accelerators with numbers
* fix: control zoom in
* fix logic on macOS
* fix for linux
* chore: prepare-code
* chore: adjust comments
Diffstat (limited to 'src')
-rw-r--r-- | src/components/services/tabs/TabItem.tsx | 8 | ||||
-rw-r--r-- | src/electron/ipc-api/dnd.ts | 2 | ||||
-rw-r--r-- | src/features/workspaces/components/WorkspaceDrawerItem.tsx | 8 | ||||
-rw-r--r-- | src/jsUtils.ts | 21 | ||||
-rw-r--r-- | src/lib/Menu.ts | 17 | ||||
-rw-r--r-- | src/models/Service.ts | 13 |
6 files changed, 52 insertions, 17 deletions
diff --git a/src/components/services/tabs/TabItem.tsx b/src/components/services/tabs/TabItem.tsx index 0e999506a..94c0b7e7f 100644 --- a/src/components/services/tabs/TabItem.tsx +++ b/src/components/services/tabs/TabItem.tsx | |||
@@ -364,10 +364,10 @@ class TabItem extends Component<IProps, IState> { | |||
364 | role="presentation" | 364 | role="presentation" |
365 | onContextMenu={() => menu.popup()} | 365 | onContextMenu={() => menu.popup()} |
366 | data-tooltip-id="tooltip-sidebar-button" | 366 | data-tooltip-id="tooltip-sidebar-button" |
367 | data-tooltip-content={`${service.name} ${acceleratorString( | 367 | data-tooltip-content={`${service.name} ${acceleratorString({ |
368 | shortcutIndex, | 368 | index: shortcutIndex, |
369 | cmdOrCtrlShortcutKey(false), | 369 | keyCombo: cmdOrCtrlShortcutKey(false), |
370 | )}`} | 370 | })}`} |
371 | > | 371 | > |
372 | <img src={service.icon} className="tab-item__icon" alt="" /> | 372 | <img src={service.icon} className="tab-item__icon" alt="" /> |
373 | {showServiceNameSetting && ( | 373 | {showServiceNameSetting && ( |
diff --git a/src/electron/ipc-api/dnd.ts b/src/electron/ipc-api/dnd.ts index 30ace7c84..240e4a1cf 100644 --- a/src/electron/ipc-api/dnd.ts +++ b/src/electron/ipc-api/dnd.ts | |||
@@ -8,7 +8,7 @@ export default async () => { | |||
8 | if (!isMac) { | 8 | if (!isMac) { |
9 | return false; | 9 | return false; |
10 | } | 10 | } |
11 | 11 | // @ts-expect-error | |
12 | const { getDoNotDisturb } = await import('macos-notification-state'); | 12 | const { getDoNotDisturb } = await import('macos-notification-state'); |
13 | 13 | ||
14 | if (!getDoNotDisturb) { | 14 | if (!getDoNotDisturb) { |
diff --git a/src/features/workspaces/components/WorkspaceDrawerItem.tsx b/src/features/workspaces/components/WorkspaceDrawerItem.tsx index 01a18ffb0..23851edf6 100644 --- a/src/features/workspaces/components/WorkspaceDrawerItem.tsx +++ b/src/features/workspaces/components/WorkspaceDrawerItem.tsx | |||
@@ -125,10 +125,10 @@ class WorkspaceDrawerItem extends Component<IProps> { | |||
125 | }} | 125 | }} |
126 | onKeyDown={noop} | 126 | onKeyDown={noop} |
127 | data-tooltip-id="tooltip-workspaces-drawer" | 127 | data-tooltip-id="tooltip-workspaces-drawer" |
128 | data-tooltip-content={acceleratorString( | 128 | data-tooltip-content={acceleratorString({ |
129 | shortcutIndex, | 129 | index: shortcutIndex, |
130 | `${cmdOrCtrlShortcutKey(false)}+${altKey(false)}`, | 130 | keyCombo: `${cmdOrCtrlShortcutKey(false)}+${altKey(false)}`, |
131 | )} | 131 | })} |
132 | > | 132 | > |
133 | <span | 133 | <span |
134 | className={classnames([ | 134 | className={classnames([ |
diff --git a/src/jsUtils.ts b/src/jsUtils.ts index 0befb8d56..145875cfa 100644 --- a/src/jsUtils.ts +++ b/src/jsUtils.ts | |||
@@ -28,12 +28,21 @@ export const safeParseInt = (text?: string | number | null) => { | |||
28 | return Math.max(adjustedNumber, 0); | 28 | return Math.max(adjustedNumber, 0); |
29 | }; | 29 | }; |
30 | 30 | ||
31 | export const acceleratorString = ( | 31 | interface IAcceleratorString { |
32 | index: number, | 32 | keyCombo: string; |
33 | keyCombo: string, | 33 | index: number; |
34 | prefix: string = '(', | 34 | prefix?: string; |
35 | suffix: string = ')', | 35 | suffix?: string; |
36 | ) => (index <= 10 ? `${prefix}${keyCombo}+${index % 10}${suffix}` : ''); | 36 | maxIndex?: number; |
37 | } | ||
38 | export const acceleratorString = ({ | ||
39 | index, | ||
40 | keyCombo, | ||
41 | prefix = '(', | ||
42 | suffix = ')', | ||
43 | maxIndex = 9, | ||
44 | }: IAcceleratorString) => | ||
45 | index <= maxIndex ? `${prefix}${keyCombo}+${index % 10}${suffix}` : ''; | ||
37 | 46 | ||
38 | export const removeNewLines = (input: string): string => | 47 | export const removeNewLines = (input: string): string => |
39 | input.replaceAll(/\r?\n|\r/g, ''); | 48 | input.replaceAll(/\r?\n|\r/g, ''); |
diff --git a/src/lib/Menu.ts b/src/lib/Menu.ts index bb8eead3a..8fd8e0a73 100644 --- a/src/lib/Menu.ts +++ b/src/lib/Menu.ts | |||
@@ -496,7 +496,15 @@ function titleBarTemplateFactory( | |||
496 | }, | 496 | }, |
497 | { | 497 | { |
498 | label: intl.formatMessage(menuItems.zoomIn), | 498 | label: intl.formatMessage(menuItems.zoomIn), |
499 | accelerator: `${cmdOrCtrlShortcutKey()}+plus`, | 499 | // TODO: Modify this logic once https://github.com/electron/electron/issues/40674 is fixed |
500 | // This is a workaround for the issue where the zoom in shortcut is not working | ||
501 | // This makes sure the accelerator is not registered | ||
502 | accelerator: isWindows | ||
503 | ? `${cmdOrCtrlShortcutKey()}++` | ||
504 | : `${cmdOrCtrlShortcutKey()}+Plus`, | ||
505 | registerAccelerator: !!isMac, | ||
506 | acceleratorWorksWhenHidden: !!isMac, | ||
507 | // --------------------------- | ||
500 | click() { | 508 | click() { |
501 | const activeService = getActiveService(); | 509 | const activeService = getActiveService(); |
502 | if (!activeService) { | 510 | if (!activeService) { |
@@ -1134,7 +1142,12 @@ class FranzMenu implements StoresProps { | |||
1134 | for (const [i, service] of services.allDisplayed.entries()) { | 1142 | for (const [i, service] of services.allDisplayed.entries()) { |
1135 | menu.push({ | 1143 | menu.push({ |
1136 | label: this._getServiceName(service), | 1144 | label: this._getServiceName(service), |
1137 | accelerator: acceleratorString(i + 1, cmdOrCtrlShortcutKey(), '', ''), | 1145 | accelerator: acceleratorString({ |
1146 | index: i + 1, | ||
1147 | keyCombo: cmdOrCtrlShortcutKey(), | ||
1148 | prefix: '', | ||
1149 | suffix: '', | ||
1150 | }), | ||
1138 | type: 'radio', | 1151 | type: 'radio', |
1139 | checked: service.isActive, | 1152 | checked: service.isActive, |
1140 | click: () => { | 1153 | click: () => { |
diff --git a/src/models/Service.ts b/src/models/Service.ts index a61df5570..ae04b8b58 100644 --- a/src/models/Service.ts +++ b/src/models/Service.ts | |||
@@ -7,6 +7,7 @@ import type ElectronWebView from 'react-electron-web-view'; | |||
7 | import { v4 as uuidV4 } from 'uuid'; | 7 | import { v4 as uuidV4 } from 'uuid'; |
8 | import { needsToken } from '../api/apiBase'; | 8 | import { needsToken } from '../api/apiBase'; |
9 | import { DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } from '../config'; | 9 | import { DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } from '../config'; |
10 | import { isMac } from '../environment'; | ||
10 | import { todosStore } from '../features/todos'; | 11 | import { todosStore } from '../features/todos'; |
11 | import { getFaviconUrl } from '../helpers/favicon-helpers'; | 12 | import { getFaviconUrl } from '../helpers/favicon-helpers'; |
12 | import { isValidExternalURL, normalizedUrl } from '../helpers/url-helpers'; | 13 | import { isValidExternalURL, normalizedUrl } from '../helpers/url-helpers'; |
@@ -536,6 +537,18 @@ export default class Service { | |||
536 | }); | 537 | }); |
537 | 538 | ||
538 | if (webviewWebContents) { | 539 | if (webviewWebContents) { |
540 | // TODO: Modify this logic once https://github.com/electron/electron/issues/40674 is fixed | ||
541 | // This is a workaround for the issue where the zoom in shortcut is not working | ||
542 | if (!isMac) { | ||
543 | webviewWebContents.on('before-input-event', (event, input) => { | ||
544 | if (input.control && input.key === '+' && input.type === 'keyDown') { | ||
545 | event.preventDefault(); | ||
546 | const currentZoom = this.webview?.getZoomLevel(); | ||
547 | this.webview?.setZoomLevel(currentZoom + 0.5); | ||
548 | } | ||
549 | }); | ||
550 | } | ||
551 | |||
539 | webviewWebContents.session.on('will-download', (event, item) => { | 552 | webviewWebContents.session.on('will-download', (event, item) => { |
540 | event.preventDefault(); | 553 | event.preventDefault(); |
541 | 554 | ||