aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar André Oliveira <37463445+SpecialAro@users.noreply.github.com>2024-05-13 22:47:35 +0100
committerLibravatar GitHub <noreply@github.com>2024-05-13 22:47:35 +0100
commit6167b6c7e9f49adee065646e2d28e28500753ebd (patch)
tree15d4746188e95af98ae7cf6e426c82ffdfed7ee1
parentFix notifications on all services (#1593) (diff)
downloadferdium-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
-rw-r--r--src/components/services/tabs/TabItem.tsx8
-rw-r--r--src/electron/ipc-api/dnd.ts2
-rw-r--r--src/features/workspaces/components/WorkspaceDrawerItem.tsx8
-rw-r--r--src/jsUtils.ts21
-rw-r--r--src/lib/Menu.ts17
-rw-r--r--src/models/Service.ts13
-rw-r--r--test/jsUtils.test.ts46
7 files changed, 93 insertions, 22 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
31export const acceleratorString = ( 31interface 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}
38export 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
38export const removeNewLines = (input: string): string => 47export 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';
7import { v4 as uuidV4 } from 'uuid'; 7import { v4 as uuidV4 } from 'uuid';
8import { needsToken } from '../api/apiBase'; 8import { needsToken } from '../api/apiBase';
9import { DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } from '../config'; 9import { DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } from '../config';
10import { isMac } from '../environment';
10import { todosStore } from '../features/todos'; 11import { todosStore } from '../features/todos';
11import { getFaviconUrl } from '../helpers/favicon-helpers'; 12import { getFaviconUrl } from '../helpers/favicon-helpers';
12import { isValidExternalURL, normalizedUrl } from '../helpers/url-helpers'; 13import { 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
diff --git a/test/jsUtils.test.ts b/test/jsUtils.test.ts
index 508f5dd9f..b40b21b2a 100644
--- a/test/jsUtils.test.ts
+++ b/test/jsUtils.test.ts
@@ -180,23 +180,59 @@ describe('jsUtils', () => {
180 180
181 describe('acceleratorString', () => { 181 describe('acceleratorString', () => {
182 it('handles without prefix and suffix', () => { 182 it('handles without prefix and suffix', () => {
183 expect(jsUtils.acceleratorString(5, 'abc')).toEqual('(abc+5)'); 183 expect(
184 jsUtils.acceleratorString({
185 index: 5,
186 keyCombo: 'abc',
187 }),
188 ).toEqual('(abc+5)');
184 }); 189 });
185 190
186 it('handles index = 0', () => { 191 it('handles index = 0', () => {
187 expect(jsUtils.acceleratorString(0, 'abc')).toEqual('(abc+0)'); 192 expect(
193 jsUtils.acceleratorString({
194 index: 0,
195 keyCombo: 'abc',
196 }),
197 ).toEqual('(abc+0)');
188 }); 198 });
189 199
190 it('handles index = 1', () => { 200 it('handles index = 1', () => {
191 expect(jsUtils.acceleratorString(1, 'abc')).toEqual('(abc+1)'); 201 expect(
202 jsUtils.acceleratorString({
203 index: 1,
204 keyCombo: 'abc',
205 }),
206 ).toEqual('(abc+1)');
192 }); 207 });
193 208
194 it('handles index = 10', () => { 209 it('handles index = 10', () => {
195 expect(jsUtils.acceleratorString(10, 'abc')).toEqual('(abc+0)'); 210 expect(
211 jsUtils.acceleratorString({
212 index: 10,
213 keyCombo: 'abc',
214 maxIndex: 10,
215 }),
216 ).toEqual('(abc+0)');
196 }); 217 });
197 218
198 it('handles index = 11', () => { 219 it('handles index = 11', () => {
199 expect(jsUtils.acceleratorString(11, 'abc')).toEqual(''); 220 expect(
221 jsUtils.acceleratorString({
222 index: 11,
223 keyCombo: 'abc',
224 }),
225 ).toEqual('');
226 });
227
228 it('handles index = 9, maxIndex = 8', () => {
229 expect(
230 jsUtils.acceleratorString({
231 index: 9,
232 maxIndex: 8,
233 keyCombo: 'abc',
234 }),
235 ).toEqual('');
200 }); 236 });
201 }); 237 });
202 238