Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(suite): fix draggable window header #16437

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/src/components/NewModal/NewModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const Container = styled.div<
overflow: hidden;
background: ${mapElevationToBackground};
box-shadow: ${({ theme }) => theme.boxShadowElevated};
-webkit-app-region: no-drag;

${withFrameProps}
`;
Expand Down
3 changes: 2 additions & 1 deletion packages/suite-desktop-ui/src/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import TrezorConnect from '@trezor/connect';
import { initStore } from 'src/reducers/store';
import { preloadStore } from 'src/support/suite/preloadStore';
import { Metadata } from 'src/components/suite/Metadata';
import { Preloader, ToastContainer } from 'src/components/suite';
import { Preloader, ToastContainer, TrafficLightDraggableWindowHeader } from 'src/components/suite';
import { ConnectedIntlProvider } from 'src/support/suite/ConnectedIntlProvider';
import Resize from 'src/support/suite/Resize';
import Autodetect from 'src/support/suite/Autodetect';
Expand Down Expand Up @@ -45,6 +45,7 @@ const Main = () => {
// Todo: Enable when issues are fixed (ReactTruncate & BumpFee)
// <StrictMode>
<HelmetProvider>
<TrafficLightDraggableWindowHeader />
<ConnectedThemeProvider>
<RouterProvider history={history}>
<ModalContextProvider>
Expand Down
32 changes: 15 additions & 17 deletions packages/suite/src/components/suite/TrafficLightOffset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,40 @@ type Props = {
isVisible?: boolean;
};

// See: https://github.com/electron/electron/issues/5678
// Visible all the time in the app
const ThinFixForNotBeingAbleToDragWindow = styled.div`
const FixForNotBeingAbleToDragWindow = styled.div`
-webkit-app-region: drag;
height: 16px;
pointer-events: none;
height: 64px;
position: fixed;
z-index: ${zIndices.windowControls};
top: 0;
left: 0;
width: 100%;
`;

// Visible below content (but visible in the sidebar)
const ThickFixForNotBeingAbleToDragWindow = styled(ThinFixForNotBeingAbleToDragWindow)`
height: 64px;
z-index: unset;
`;

const Container = styled.div<{ $offset: number }>`
${({ $offset }) => `padding-top: ${$offset}px;`}
width: 100%;
height: 100%;
`;

// See: https://github.com/electron/electron/issues/5678
// Visible all the time in the app
export const TrafficLightDraggableWindowHeader = ({ children, isVisible = true }: Props) => {
const isMac = isMacOs();
const isDesktopApp = isDesktop();

if (!isVisible || !isMac || !isDesktopApp) return children;

return <FixForNotBeingAbleToDragWindow />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT (meaning nitpick, if won't added, it's okay): I would add a comment here explain of why this fix is needed in these conditions, what's the root of it.

};

// on Mac in desktop app we don't use window bar and close/maximize/minimize icons are positioned directly in the app
export const TrafficLightOffset = ({ children, offset = 35, isVisible = true }: Props) => {
const isMac = isMacOs();
const isDesktopApp = isDesktop();

if (!isVisible || !isMac || !isDesktopApp) return children;

return (
<>
<ThinFixForNotBeingAbleToDragWindow />
<ThickFixForNotBeingAbleToDragWindow />
<Container $offset={offset}>{children}</Container>
</>
);
return <Container $offset={offset}>{children}</Container>;
};
2 changes: 2 additions & 0 deletions packages/suite/src/components/suite/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { QrCode } from './QrCode';
import { CoinBalance } from './CoinBalance';
import { DeviceAuthenticationExplainer } from './DeviceAuthenticationExplainer';
import { Preloader } from './Preloader/Preloader';
import { TrafficLightDraggableWindowHeader } from './TrafficLightOffset';
import { PinMatrix } from './PinMatrix/PinMatrix';
import { UdevDownload } from './UdevDownload';
import { StakingFeature } from './StakingFeature';
Expand Down Expand Up @@ -100,6 +101,7 @@ export {
CoinBalance,
DeviceAuthenticationExplainer,
Preloader,
TrafficLightDraggableWindowHeader,
PinMatrix,
UdevDownload,
StakingFeature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type SwitchDeviceModalProps = {

const Container = styled.div`
width: 378px;
-webkit-app-region: no-drag;
`;

const initial = {
Expand Down Expand Up @@ -51,7 +52,11 @@ export const SwitchDeviceModal = ({
width: 369,
height: 'auto',
}}
style={{ originX: 0, originY: 0, overflow: 'hidden' }}
style={{
originX: 0,
originY: 0,
overflow: 'hidden',
}}
>
{children}
</motion.div>
Expand Down
Loading