aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/components/sidebar
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-04-24 17:01:25 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-05-16 00:55:02 +0200
commit0b632445a933644c7eb10015eb04b7c21d562900 (patch)
tree5bd1fe200cc747086220dbcba90097bfe2cc4cdc /packages/renderer/src/components/sidebar
parentchore(deps): upgrade dependencies (diff)
downloadsophie-0b632445a933644c7eb10015eb04b7c21d562900.tar.gz
sophie-0b632445a933644c7eb10015eb04b7c21d562900.tar.zst
sophie-0b632445a933644c7eb10015eb04b7c21d562900.zip
refactor: reduce service switcher tearing
We render the location bar and notification banners separately for each service and keep track of the BrowserView size separately for each service to reduce the tearing that appears when people switch services. The tearing cannot be eliminated completely, because it comes from the separation between the main and renderer processes. But we can at least try and reduce the IPC round-tripping and layout calculations required to accurately position the services. This approach has an overhead compared to the single BrowserViewPlaceholder approach, because the renderer process has to layout the location bar and notification for all services, not only the selected one. The number of IPC messages during windows resize is also increased. To compensate, we increase the throttle interval for resize IPC messages and let electron itself resize the BrowserView between IPC updates. (We must still keep pumping IPC messages during window resize, because, e.g., changes in notification banner size due to re-layouting will still affect the required BrowserView size). If further reduction of IPC traffic is needed, we could implement batching for resize IPC messages and more intelligent throttling via a token bucker mechanism. Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/renderer/src/components/sidebar')
-rw-r--r--packages/renderer/src/components/sidebar/ServiceSwitcher.tsx2
-rw-r--r--packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx8
2 files changed, 8 insertions, 2 deletions
diff --git a/packages/renderer/src/components/sidebar/ServiceSwitcher.tsx b/packages/renderer/src/components/sidebar/ServiceSwitcher.tsx
index 0ebd359..24cfd0c 100644
--- a/packages/renderer/src/components/sidebar/ServiceSwitcher.tsx
+++ b/packages/renderer/src/components/sidebar/ServiceSwitcher.tsx
@@ -27,6 +27,7 @@ import React from 'react';
27import { useTranslation } from 'react-i18next'; 27import { useTranslation } from 'react-i18next';
28 28
29import type Service from '../../stores/Service'; 29import type Service from '../../stores/Service';
30import { getServicePanelID } from '../ServicePanel';
30import { useStore } from '../StoreProvider'; 31import { useStore } from '../StoreProvider';
31 32
32import ServiceIcon from './ServiceIcon'; 33import ServiceIcon from './ServiceIcon';
@@ -112,6 +113,7 @@ function ServiceSwitcher(): JSX.Element {
112 value={service.id} 113 value={service.id}
113 icon={<ServiceIcon service={service} />} 114 icon={<ServiceIcon service={service} />}
114 aria-label={getServiceTitle(service, t)} 115 aria-label={getServiceTitle(service, t)}
116 aria-controls={getServicePanelID(service)}
115 /> 117 />
116 ))} 118 ))}
117 </ServiceSwitcherRoot> 119 </ServiceSwitcherRoot>
diff --git a/packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx b/packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx
index 7fc559d..c697170 100644
--- a/packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx
+++ b/packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx
@@ -28,7 +28,7 @@ import React from 'react';
28import { useTranslation } from 'react-i18next'; 28import { useTranslation } from 'react-i18next';
29 29
30import { useStore } from '../StoreProvider'; 30import { useStore } from '../StoreProvider';
31import { LOCATION_BAR_ID } from '../locationBar/LocationBar'; 31import { getLocaltionBarID } from '../locationBar/LocationBar';
32 32
33function ToggleLocationBarIcon({ 33function ToggleLocationBarIcon({
34 loading, 34 loading,
@@ -54,13 +54,17 @@ function ToggleLocationBarButton(): JSX.Element {
54 const { selectedService } = settings; 54 const { selectedService } = settings;
55 55
56 return ( 56 return (
57 /* eslint-disable react/jsx-props-no-spreading -- Conditionally set the aria-controls prop. */
57 <IconButton 58 <IconButton
58 disabled={!canToggleLocationBar} 59 disabled={!canToggleLocationBar}
59 aria-pressed={locationBarVisible} 60 aria-pressed={locationBarVisible}
60 aria-controls={LOCATION_BAR_ID} 61 {...(selectedService === undefined
62 ? {}
63 : { 'aria-controls': getLocaltionBarID(selectedService) })}
61 aria-label={t('toolbar.toggleLocationBar')} 64 aria-label={t('toolbar.toggleLocationBar')}
62 onClick={() => settings.toggleLocationBar()} 65 onClick={() => settings.toggleLocationBar()}
63 > 66 >
67 {/* eslint-enable react/jsx-props-no-spreading */}
64 <ToggleLocationBarIcon 68 <ToggleLocationBarIcon
65 loading={selectedService?.loading ?? false} 69 loading={selectedService?.loading ?? false}
66 show={locationBarVisible} 70 show={locationBarVisible}