@shellui/core 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +2 -2
- package/src/features/admin/AdminView.tsx +18 -4
- package/src/features/auth/AuthProvider.tsx +18 -1
- package/src/features/auth/utils/desktopSignIn.spec.ts +41 -0
- package/src/features/auth/utils/desktopSignIn.ts +38 -0
- package/src/features/chromeActions/ChromeActionsHost.tsx +7 -1
- package/src/features/chromeActions/computeActionInsets.ts +6 -0
- package/src/features/layouts/appbar/AppBarLayout.tsx +39 -9
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +14 -7
- package/src/features/layouts/chrome/DesktopChrome.tsx +3 -1
- package/src/features/layouts/floating/FloatingLayout.tsx +4 -1
- package/src/features/layouts/floating/FloatingSidebar.tsx +84 -28
- package/src/features/layouts/floating/computeFloatingInsets.spec.ts +19 -0
- package/src/features/layouts/floating/computeFloatingInsets.ts +40 -8
- package/src/features/layouts/floating/layoutChromeStore.ts +13 -0
- package/src/features/layouts/floating/useFloatingChrome.ts +11 -5
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +3 -0
- package/src/features/layouts/sidebar/SidebarInner.tsx +5 -0
- package/src/features/layouts/sidebar/SidebarLayout.tsx +1 -0
- package/src/features/layouts/windows/WindowsLayout.tsx +106 -46
- package/src/features/security/trustedFrames.spec.ts +17 -1
- package/src/features/security/trustedFrames.ts +31 -9
- package/src/features/settings/SettingsProvider.tsx +3 -0
- package/src/features/settings/utils/buildSettingsForPropagation.ts +9 -2
- package/src/index.css +16 -1
- package/src/lib/z-index.ts +5 -0
|
@@ -65,6 +65,25 @@ describe('computeFloatingInsets', () => {
|
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
it('drops the floating edge gap when edgeMargin is 0', () => {
|
|
69
|
+
expect(
|
|
70
|
+
computeFloatingInsets({
|
|
71
|
+
viewport: 'desktop',
|
|
72
|
+
chromeVisible: true,
|
|
73
|
+
safeArea: safe,
|
|
74
|
+
edgeMargin: 0,
|
|
75
|
+
}).left,
|
|
76
|
+
).toBe(3 + FLOATING_SIDEBAR_WIDTH + FLOATING_CONTENT_CLEARANCE);
|
|
77
|
+
expect(
|
|
78
|
+
computeFloatingInsets({
|
|
79
|
+
viewport: 'mobile',
|
|
80
|
+
chromeVisible: true,
|
|
81
|
+
safeArea: safe,
|
|
82
|
+
edgeMargin: 0,
|
|
83
|
+
}).bottom,
|
|
84
|
+
).toBe(20 / 2 + FLOATING_TAB_BAR_HEIGHT + FLOATING_CONTENT_CLEARANCE);
|
|
85
|
+
});
|
|
86
|
+
|
|
68
87
|
it('keeps content full-bleed when desktop sidebar is collapsed', () => {
|
|
69
88
|
expect(
|
|
70
89
|
computeFloatingInsets({
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { LayoutChromeInsets, LayoutChromeViewport } from '@shellui/sdk';
|
|
2
|
+
import { MAC_TRAFFIC_LIGHTS_WIDTH_PX } from '../chrome/constants';
|
|
3
|
+
import { isMacOSDesktop, isTauriRuntime } from '../chrome/runtime';
|
|
4
|
+
import { isTauri } from '../../../service-worker/register';
|
|
2
5
|
|
|
3
6
|
/** Floating tab bar content height (icon + short label) — phone. */
|
|
4
7
|
export const FLOATING_TAB_BAR_HEIGHT = 56;
|
|
@@ -13,6 +16,12 @@ export const FLOATING_CHROME_MARGIN = 12;
|
|
|
13
16
|
export const FLOATING_DOCK_SIDE_INSET = 8;
|
|
14
17
|
/** Extra clearance so the last content row clears the floating chrome comfortably. */
|
|
15
18
|
export const FLOATING_CONTENT_CLEARANCE = 12;
|
|
19
|
+
/**
|
|
20
|
+
* Tauri desktop: keep the action scrim off the sidebar’s right edge so the
|
|
21
|
+
* glass border and its glow stay visible. The content inset only clears 12px,
|
|
22
|
+
* which the opaque action background still covers.
|
|
23
|
+
*/
|
|
24
|
+
export const TAURI_FLOATING_ACTION_SIDEBAR_GAP_PX = 16;
|
|
16
25
|
/** Desktop floating sidebar width. */
|
|
17
26
|
export const FLOATING_SIDEBAR_WIDTH = 240;
|
|
18
27
|
/**
|
|
@@ -48,8 +57,9 @@ export function floatingMinTabSlotWidth(viewport: LayoutChromeViewport): number
|
|
|
48
57
|
export function floatingTabBarBottomPadPx(
|
|
49
58
|
safeBottom: number,
|
|
50
59
|
viewport: LayoutChromeViewport,
|
|
60
|
+
edgeMargin: number = FLOATING_CHROME_MARGIN,
|
|
51
61
|
): number {
|
|
52
|
-
const full =
|
|
62
|
+
const full = edgeMargin + safeBottom;
|
|
53
63
|
return viewport === 'mobile' ? full / 2 : full;
|
|
54
64
|
}
|
|
55
65
|
|
|
@@ -57,11 +67,14 @@ export function floatingTabBarBottomPadPx(
|
|
|
57
67
|
* Same bottom pad as the floating dock, as a CSS value so
|
|
58
68
|
* `--shellui-safe-area-bottom` / env() apply on iPhone (not a snapped 0px number).
|
|
59
69
|
*/
|
|
60
|
-
export function floatingTabBarBottomPadCss(
|
|
70
|
+
export function floatingTabBarBottomPadCss(
|
|
71
|
+
viewport: LayoutChromeViewport,
|
|
72
|
+
edgeMargin: number = FLOATING_CHROME_MARGIN,
|
|
73
|
+
): string {
|
|
61
74
|
if (viewport === 'mobile') {
|
|
62
|
-
return `calc((${
|
|
75
|
+
return `calc((${edgeMargin}px + var(--shellui-safe-area-bottom, 0px)) / 2)`;
|
|
63
76
|
}
|
|
64
|
-
return `calc(${
|
|
77
|
+
return `calc(${edgeMargin}px + var(--shellui-safe-area-bottom, 0px))`;
|
|
65
78
|
}
|
|
66
79
|
/** Collapsed desktop toggle control size (glass chip). */
|
|
67
80
|
export const FLOATING_SIDEBAR_TOGGLE_SIZE = 36;
|
|
@@ -72,6 +85,20 @@ export const FLOATING_SIDEBAR_TOGGLE_SIZE = 36;
|
|
|
72
85
|
*/
|
|
73
86
|
export const FLOATING_COLLAPSED_ACTIONS_LEADING_EXTRA =
|
|
74
87
|
FLOATING_SIDEBAR_TOGGLE_SIZE + FLOATING_CONTENT_CLEARANCE;
|
|
88
|
+
/** Back + forward pair ahead of the collapsed expand chip in Tauri. */
|
|
89
|
+
export const FLOATING_HISTORY_CLUSTER_PX = 72;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Left offset for the top action row when the desktop sidebar is collapsed.
|
|
93
|
+
* Tauri also clears the traffic lights and the history buttons before the chip.
|
|
94
|
+
*/
|
|
95
|
+
export function floatingCollapsedActionsLeadingPx(): number {
|
|
96
|
+
let leading = FLOATING_COLLAPSED_ACTIONS_LEADING_EXTRA;
|
|
97
|
+
if (typeof window === 'undefined' || !isTauri()) return leading;
|
|
98
|
+
leading += FLOATING_HISTORY_CLUSTER_PX;
|
|
99
|
+
if (isTauriRuntime() && isMacOSDesktop()) leading += MAC_TRAFFIC_LIGHTS_WIDTH_PX;
|
|
100
|
+
return leading;
|
|
101
|
+
}
|
|
75
102
|
/**
|
|
76
103
|
* Floating sidebar brand header: `py-2.5` (10+10) + `size-8` toggle (32).
|
|
77
104
|
* Keep in sync with FloatingSidebar brand row.
|
|
@@ -94,6 +121,11 @@ export function computeFloatingInsets(options: {
|
|
|
94
121
|
/** Desktop only: sidebar hidden — no left content inset (chip cleared by actions pad). */
|
|
95
122
|
sidebarCollapsed?: boolean;
|
|
96
123
|
safeArea?: Partial<FloatingSafeArea>;
|
|
124
|
+
/**
|
|
125
|
+
* Gap between floating chrome and the window edge.
|
|
126
|
+
* Tauri passes `0` so the title row meets the traffic lights.
|
|
127
|
+
*/
|
|
128
|
+
edgeMargin?: number;
|
|
97
129
|
}): LayoutChromeInsets {
|
|
98
130
|
const safe: FloatingSafeArea = {
|
|
99
131
|
top: options.safeArea?.top ?? 0,
|
|
@@ -107,14 +139,15 @@ export function computeFloatingInsets(options: {
|
|
|
107
139
|
}
|
|
108
140
|
|
|
109
141
|
const { viewport } = options;
|
|
142
|
+
const edge = options.edgeMargin ?? FLOATING_CHROME_MARGIN;
|
|
110
143
|
if (viewport === 'mobile' || viewport === 'tablet') {
|
|
111
144
|
return {
|
|
112
145
|
top: safe.top,
|
|
113
146
|
right: safe.right,
|
|
114
147
|
bottom:
|
|
115
|
-
floatingTabBarBottomPadPx(safe.bottom, viewport) +
|
|
148
|
+
floatingTabBarBottomPadPx(safe.bottom, viewport, edge) +
|
|
116
149
|
floatingTabBarHeight(viewport) +
|
|
117
|
-
|
|
150
|
+
edge +
|
|
118
151
|
FLOATING_CONTENT_CLEARANCE,
|
|
119
152
|
left: safe.left,
|
|
120
153
|
};
|
|
@@ -133,8 +166,7 @@ export function computeFloatingInsets(options: {
|
|
|
133
166
|
top: safe.top,
|
|
134
167
|
right: safe.right,
|
|
135
168
|
bottom: safe.bottom,
|
|
136
|
-
left:
|
|
137
|
-
safe.left + FLOATING_SIDEBAR_WIDTH + FLOATING_CHROME_MARGIN * 2 + FLOATING_CONTENT_CLEARANCE,
|
|
169
|
+
left: safe.left + FLOATING_SIDEBAR_WIDTH + edge * 2 + FLOATING_CONTENT_CLEARANCE,
|
|
138
170
|
};
|
|
139
171
|
}
|
|
140
172
|
|
|
@@ -29,6 +29,19 @@ export function getPublishedLayoutChrome(): LayoutChrome | null {
|
|
|
29
29
|
return currentChrome;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Layout chrome for one iframe, including that frame's action-bar insets.
|
|
34
|
+
* Settings must carry this — the base snapshot has no action padding, so the
|
|
35
|
+
* first paint misses the top gap until a later resize republishes it.
|
|
36
|
+
*/
|
|
37
|
+
export function getLayoutChromeForFrame(frameUuid: string): LayoutChrome | null {
|
|
38
|
+
if (!currentChrome) return null;
|
|
39
|
+
const actions = getChromeActionsForFrame(frameUuid);
|
|
40
|
+
return buildFrameLayoutChrome(currentChrome, actionChromeFlags(actions), {
|
|
41
|
+
topInTitleBar: isTopActionsInTitleBar(currentChrome),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
/** Subscribe to published layout-chrome changes (e.g. floating hide-on-scroll). */
|
|
33
46
|
export function subscribeLayoutChrome(listener: LayoutChromeListener): () => void {
|
|
34
47
|
layoutChromeListeners.add(listener);
|
|
@@ -9,9 +9,10 @@ import {
|
|
|
9
9
|
type LayoutChromeViewport,
|
|
10
10
|
type ScrollChromeState,
|
|
11
11
|
} from '@shellui/sdk';
|
|
12
|
+
import { useIsTauriRuntime } from '../chrome/runtime';
|
|
12
13
|
import {
|
|
13
14
|
computeFloatingInsets,
|
|
14
|
-
|
|
15
|
+
floatingCollapsedActionsLeadingPx,
|
|
15
16
|
readShellSafeAreaPx,
|
|
16
17
|
} from './computeFloatingInsets';
|
|
17
18
|
import { publishLayoutChrome } from './layoutChromeStore';
|
|
@@ -43,7 +44,7 @@ function syncChromeActionsLeadingExtra(desktopCollapsed: boolean): void {
|
|
|
43
44
|
if (typeof document === 'undefined') return;
|
|
44
45
|
document.documentElement.style.setProperty(
|
|
45
46
|
ACTIONS_LEADING_EXTRA_VAR,
|
|
46
|
-
`${desktopCollapsed ?
|
|
47
|
+
`${desktopCollapsed ? floatingCollapsedActionsLeadingPx() : 0}px`,
|
|
47
48
|
);
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -52,6 +53,7 @@ function buildChrome(
|
|
|
52
53
|
chromeVisible: boolean,
|
|
53
54
|
sidebarCollapsed: boolean,
|
|
54
55
|
autoPadding = true,
|
|
56
|
+
edgeMargin?: number,
|
|
55
57
|
): LayoutChrome {
|
|
56
58
|
const safeArea =
|
|
57
59
|
typeof document !== 'undefined'
|
|
@@ -70,6 +72,7 @@ function buildChrome(
|
|
|
70
72
|
chromeVisible: true,
|
|
71
73
|
sidebarCollapsed: desktopCollapsed,
|
|
72
74
|
safeArea,
|
|
75
|
+
edgeMargin,
|
|
73
76
|
}),
|
|
74
77
|
};
|
|
75
78
|
}
|
|
@@ -80,6 +83,8 @@ function buildChrome(
|
|
|
80
83
|
*/
|
|
81
84
|
export function useFloatingChrome(viewport: LayoutChromeViewport) {
|
|
82
85
|
const location = useLocation();
|
|
86
|
+
const tauriRuntime = useIsTauriRuntime();
|
|
87
|
+
const edgeMargin = tauriRuntime && viewport === 'desktop' ? 0 : undefined;
|
|
83
88
|
const [chromeVisible, setChromeVisible] = useState(true);
|
|
84
89
|
const [sidebarCollapsed, setSidebarCollapsedState] = useState(readSidebarCollapsed);
|
|
85
90
|
const scrollStateRef = useRef<ScrollChromeState>({ visible: true, lastY: 0 });
|
|
@@ -93,9 +98,9 @@ export function useFloatingChrome(viewport: LayoutChromeViewport) {
|
|
|
93
98
|
(visible: boolean, vp: LayoutChromeViewport, collapsed: boolean) => {
|
|
94
99
|
const desktopCollapsed = vp === 'desktop' && collapsed;
|
|
95
100
|
syncChromeActionsLeadingExtra(desktopCollapsed);
|
|
96
|
-
publishLayoutChrome(buildChrome(vp, visible, collapsed));
|
|
101
|
+
publishLayoutChrome(buildChrome(vp, visible, collapsed, true, edgeMargin));
|
|
97
102
|
},
|
|
98
|
-
[],
|
|
103
|
+
[edgeMargin],
|
|
99
104
|
);
|
|
100
105
|
|
|
101
106
|
const setSidebarCollapsed = useCallback((collapsed: boolean) => {
|
|
@@ -192,8 +197,9 @@ export function useFloatingChrome(viewport: LayoutChromeViewport) {
|
|
|
192
197
|
chromeVisible: true,
|
|
193
198
|
sidebarCollapsed: viewport === 'desktop' && sidebarCollapsed,
|
|
194
199
|
safeArea,
|
|
200
|
+
edgeMargin,
|
|
195
201
|
});
|
|
196
|
-
}, [viewport, sidebarCollapsed]);
|
|
202
|
+
}, [viewport, sidebarCollapsed, edgeMargin]);
|
|
197
203
|
|
|
198
204
|
return {
|
|
199
205
|
chromeVisible: effectiveVisible,
|
|
@@ -61,6 +61,9 @@ export function FullscreenLayout({ title, navigation, children }: FullscreenLayo
|
|
|
61
61
|
paddingTop: DESKTOP_TITLEBAR_PAD_TOP_PX,
|
|
62
62
|
paddingLeft: trafficLights ? MAC_TRAFFIC_LIGHTS_WIDTH_PX : 8,
|
|
63
63
|
}}
|
|
64
|
+
{...(trafficLights
|
|
65
|
+
? { 'data-shellui-drag-region': '', 'data-tauri-drag-region': '' }
|
|
66
|
+
: {})}
|
|
64
67
|
>
|
|
65
68
|
<DesktopHistoryButtons />
|
|
66
69
|
</div>
|
|
@@ -26,12 +26,15 @@ export function SidebarInner({
|
|
|
26
26
|
showAuthButton,
|
|
27
27
|
title,
|
|
28
28
|
appIcon,
|
|
29
|
+
inset = false,
|
|
29
30
|
}: {
|
|
30
31
|
startNav: (NavigationItem | NavigationGroup)[];
|
|
31
32
|
endItems: (NavigationItem | NavigationGroup)[];
|
|
32
33
|
showAuthButton: boolean;
|
|
33
34
|
title?: string;
|
|
34
35
|
appIcon?: ThemeAsset;
|
|
36
|
+
/** Sidebar-inset: the column is padded, so the title row must break out to meet the lights. */
|
|
37
|
+
inset?: boolean;
|
|
35
38
|
}) {
|
|
36
39
|
const isTauriEnv = useIsTauriClient();
|
|
37
40
|
const overlay = useMacOverlayChrome();
|
|
@@ -81,6 +84,8 @@ export function SidebarInner({
|
|
|
81
84
|
'gap-0 border-b border-sidebar-border select-none',
|
|
82
85
|
showOverlayHeader || mobileSheetHeader ? 'p-0' : 'px-2 py-0',
|
|
83
86
|
showCollapsedTopBar && 'hidden',
|
|
87
|
+
// Inset `p-3` sits this row 12px under the lights. Pull it to the window edge.
|
|
88
|
+
inset && showOverlayHeader && '-mt-3 -ml-3 w-[calc(100%+1.5rem)]',
|
|
84
89
|
)}
|
|
85
90
|
style={{
|
|
86
91
|
height: DESKTOP_TITLEBAR_HEIGHT_PX,
|
|
@@ -35,6 +35,13 @@ import { getExternalFaviconUrl, isAppIcon } from '../sidebar/sidebarUtils';
|
|
|
35
35
|
import { AppBrandIcon } from '../branding/AppBrandIcon';
|
|
36
36
|
import { useIsMobile } from '../../../hooks/use-mobile';
|
|
37
37
|
import { readSafeAreaInsetBottom, readSafeAreaInsetTop } from '../chrome/viewport';
|
|
38
|
+
import {
|
|
39
|
+
DESKTOP_TITLEBAR_HEIGHT_PX,
|
|
40
|
+
DESKTOP_TITLEBAR_PAD_TOP_PX,
|
|
41
|
+
MAC_TRAFFIC_LIGHTS_WIDTH_PX,
|
|
42
|
+
} from '../chrome/constants';
|
|
43
|
+
import { DesktopHistoryButtons } from '../chrome/DesktopHistoryButtons';
|
|
44
|
+
import { useIsTauriClient, useIsTauriRuntime, useMacTrafficLights } from '../chrome/runtime';
|
|
38
45
|
import { WindowTitleBarActions } from '../../chromeActions';
|
|
39
46
|
|
|
40
47
|
interface WindowsLayoutProps {
|
|
@@ -104,39 +111,47 @@ function getDesktopSize(): { width: number; height: number } {
|
|
|
104
111
|
};
|
|
105
112
|
}
|
|
106
113
|
|
|
107
|
-
|
|
114
|
+
/** Top inset for window bounds. `extraTop` reserves the Tauri overlay titlebar. */
|
|
115
|
+
function readWindowsTopInset(extraTop = 0): number {
|
|
116
|
+
return Math.max(readSafeAreaInsetTop(), extraTop);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function getMaximizedBounds(extraTop = 0): WindowBounds {
|
|
108
120
|
const { width, height } = getDesktopSize();
|
|
109
|
-
const
|
|
110
|
-
return { x: 0, y:
|
|
121
|
+
const top = readWindowsTopInset(extraTop);
|
|
122
|
+
return { x: 0, y: top, w: width, h: Math.max(0, height - top) };
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
/** Keep a window fully inside the desktop (never larger than the viewport). */
|
|
114
|
-
function clampBounds(bounds: WindowBounds): WindowBounds {
|
|
126
|
+
function clampBounds(bounds: WindowBounds, extraTop = 0): WindowBounds {
|
|
115
127
|
const { width: maxW, height: maxH } = getDesktopSize();
|
|
116
|
-
const
|
|
117
|
-
const usableH = Math.max(0, maxH -
|
|
128
|
+
const top = readWindowsTopInset(extraTop);
|
|
129
|
+
const usableH = Math.max(0, maxH - top);
|
|
118
130
|
const minW = Math.min(MIN_WIDTH, maxW);
|
|
119
131
|
const minH = Math.min(MIN_HEIGHT, usableH);
|
|
120
132
|
const w = Math.min(Math.max(bounds.w, minW), maxW);
|
|
121
133
|
const h = Math.min(Math.max(bounds.h, minH), usableH);
|
|
122
134
|
const x = Math.min(Math.max(0, bounds.x), Math.max(0, maxW - w));
|
|
123
|
-
const y = Math.min(Math.max(
|
|
135
|
+
const y = Math.min(Math.max(top, bounds.y), Math.max(top, top + usableH - h));
|
|
124
136
|
return { x, y, w, h };
|
|
125
137
|
}
|
|
126
138
|
|
|
127
139
|
/** Default open size: cascade on desktop; fill the screen on phones / small viewports. */
|
|
128
|
-
function getDefaultOpenBounds(cascadeIndex: number): WindowBounds {
|
|
140
|
+
function getDefaultOpenBounds(cascadeIndex: number, extraTop = 0): WindowBounds {
|
|
129
141
|
const desktop = getDesktopSize();
|
|
130
142
|
if (desktop.width < DEFAULT_WIDTH || desktop.height < DEFAULT_HEIGHT) {
|
|
131
|
-
return getMaximizedBounds();
|
|
143
|
+
return getMaximizedBounds(extraTop);
|
|
132
144
|
}
|
|
133
145
|
const cascade = cascadeIndex * 24;
|
|
134
|
-
return clampBounds(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
146
|
+
return clampBounds(
|
|
147
|
+
{
|
|
148
|
+
x: 60 + cascade,
|
|
149
|
+
y: 60 + cascade,
|
|
150
|
+
w: DEFAULT_WIDTH,
|
|
151
|
+
h: DEFAULT_HEIGHT,
|
|
152
|
+
},
|
|
153
|
+
extraTop,
|
|
154
|
+
);
|
|
140
155
|
}
|
|
141
156
|
|
|
142
157
|
function isCompactDesktop(): boolean {
|
|
@@ -205,10 +220,16 @@ function AppWindow({
|
|
|
205
220
|
cascadeIndex: number;
|
|
206
221
|
}) {
|
|
207
222
|
const windowLabel = resolveNavLabel(navItem.label, currentLanguage);
|
|
223
|
+
const tauriRuntime = useIsTauriRuntime();
|
|
224
|
+
const isTauriEnv = useIsTauriClient();
|
|
225
|
+
const trafficLights = useMacTrafficLights();
|
|
226
|
+
const topInset = trafficLights ? DESKTOP_TITLEBAR_HEIGHT_PX : 0;
|
|
227
|
+
const topInsetRef = useRef(topInset);
|
|
228
|
+
topInsetRef.current = topInset;
|
|
208
229
|
const [frameUuid, setFrameUuid] = useState<string | null>(null);
|
|
209
230
|
const [isMaximized, setIsMaximized] = useState(() => {
|
|
210
231
|
if (mobileFullscreen || isCompactDesktop()) return true;
|
|
211
|
-
const maximized = getMaximizedBounds();
|
|
232
|
+
const maximized = getMaximizedBounds(topInset);
|
|
212
233
|
return (
|
|
213
234
|
win.bounds.x === maximized.x &&
|
|
214
235
|
win.bounds.y === maximized.y &&
|
|
@@ -217,27 +238,30 @@ function AppWindow({
|
|
|
217
238
|
);
|
|
218
239
|
});
|
|
219
240
|
const [bounds, setBounds] = useState(() => {
|
|
220
|
-
if (mobileFullscreen || isCompactDesktop()) return getMaximizedBounds();
|
|
221
|
-
const maximized = getMaximizedBounds();
|
|
241
|
+
if (mobileFullscreen || isCompactDesktop()) return getMaximizedBounds(topInset);
|
|
242
|
+
const maximized = getMaximizedBounds(topInset);
|
|
222
243
|
if (
|
|
223
244
|
win.bounds.x === maximized.x &&
|
|
224
245
|
win.bounds.y === maximized.y &&
|
|
225
246
|
win.bounds.w >= maximized.w &&
|
|
226
247
|
win.bounds.h >= maximized.h
|
|
227
248
|
) {
|
|
228
|
-
return getMaximizedBounds();
|
|
249
|
+
return getMaximizedBounds(topInset);
|
|
229
250
|
}
|
|
230
|
-
return clampBounds(win.bounds);
|
|
251
|
+
return clampBounds(win.bounds, topInset);
|
|
231
252
|
});
|
|
232
253
|
const boundsBeforeMaximizeRef = useRef<WindowBounds>(
|
|
233
254
|
mobileFullscreen || isCompactDesktop()
|
|
234
|
-
? clampBounds(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
255
|
+
? clampBounds(
|
|
256
|
+
{
|
|
257
|
+
x: 8,
|
|
258
|
+
y: 8,
|
|
259
|
+
w: Math.min(DEFAULT_WIDTH, Math.max(0, getDesktopSize().width - 16)),
|
|
260
|
+
h: Math.min(DEFAULT_HEIGHT, Math.max(0, getDesktopSize().height - 16)),
|
|
261
|
+
},
|
|
262
|
+
topInset,
|
|
263
|
+
)
|
|
264
|
+
: clampBounds(win.bounds, topInset),
|
|
241
265
|
);
|
|
242
266
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
243
267
|
const dragRef = useRef<{
|
|
@@ -292,16 +316,17 @@ function AppWindow({
|
|
|
292
316
|
|
|
293
317
|
useEffect(() => {
|
|
294
318
|
const onResize = () => {
|
|
319
|
+
const inset = topInsetRef.current;
|
|
295
320
|
if (mobileFullscreenRef.current) {
|
|
296
321
|
setIsMaximized(true);
|
|
297
|
-
setBounds(getMaximizedBounds());
|
|
322
|
+
setBounds(getMaximizedBounds(inset));
|
|
298
323
|
return;
|
|
299
324
|
}
|
|
300
325
|
if (isMaximizedRef.current) {
|
|
301
|
-
setBounds(getMaximizedBounds());
|
|
326
|
+
setBounds(getMaximizedBounds(inset));
|
|
302
327
|
return;
|
|
303
328
|
}
|
|
304
|
-
setBounds((prev) => clampBounds(prev));
|
|
329
|
+
setBounds((prev) => clampBounds(prev, inset));
|
|
305
330
|
};
|
|
306
331
|
window.addEventListener('resize', onResize);
|
|
307
332
|
window.addEventListener('orientationchange', onResize);
|
|
@@ -317,23 +342,28 @@ function AppWindow({
|
|
|
317
342
|
useEffect(() => {
|
|
318
343
|
if (mobileFullscreen) {
|
|
319
344
|
setIsMaximized(true);
|
|
320
|
-
setBounds(getMaximizedBounds());
|
|
345
|
+
setBounds(getMaximizedBounds(topInset));
|
|
321
346
|
} else if (wasMobileFullscreenRef.current) {
|
|
322
347
|
// Only leave fullscreen when there is real room for window mode.
|
|
323
348
|
if (isCompactDesktop()) {
|
|
324
349
|
setIsMaximized(true);
|
|
325
|
-
setBounds(getMaximizedBounds());
|
|
350
|
+
setBounds(getMaximizedBounds(topInset));
|
|
326
351
|
} else {
|
|
327
|
-
const normal = getDefaultOpenBounds(cascadeIndex);
|
|
352
|
+
const normal = getDefaultOpenBounds(cascadeIndex, topInset);
|
|
328
353
|
boundsBeforeMaximizeRef.current = normal;
|
|
329
354
|
setIsMaximized(false);
|
|
330
355
|
setBounds(normal);
|
|
331
356
|
}
|
|
357
|
+
} else if (isMaximizedRef.current) {
|
|
358
|
+
setBounds(getMaximizedBounds(topInset));
|
|
359
|
+
} else {
|
|
360
|
+
setBounds((prev) => clampBounds(prev, topInset));
|
|
332
361
|
}
|
|
333
362
|
wasMobileFullscreenRef.current = mobileFullscreen;
|
|
334
|
-
}, [mobileFullscreen, cascadeIndex]);
|
|
363
|
+
}, [mobileFullscreen, cascadeIndex, topInset]);
|
|
335
364
|
|
|
336
365
|
const lockedChrome = mobileFullscreen || isMaximized;
|
|
366
|
+
const flushTitlebar = tauriRuntime && isMaximized && bounds.y <= readSafeAreaInsetTop();
|
|
337
367
|
const onPointerMove = useCallback((e: PointerEvent) => {
|
|
338
368
|
if (!dragRef.current) return;
|
|
339
369
|
const d = dragRef.current;
|
|
@@ -362,11 +392,14 @@ function AppWindow({
|
|
|
362
392
|
el.style.transform = '';
|
|
363
393
|
el.style.willChange = '';
|
|
364
394
|
}
|
|
365
|
-
const finalBounds = clampBounds(
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
395
|
+
const finalBounds = clampBounds(
|
|
396
|
+
{
|
|
397
|
+
...d.startBounds,
|
|
398
|
+
x: d.startBounds.x + d.lastDx,
|
|
399
|
+
y: d.startBounds.y + d.lastDy,
|
|
400
|
+
},
|
|
401
|
+
topInsetRef.current,
|
|
402
|
+
);
|
|
370
403
|
setBounds(finalBounds);
|
|
371
404
|
dragRef.current = null;
|
|
372
405
|
}
|
|
@@ -401,14 +434,14 @@ function AppWindow({
|
|
|
401
434
|
const handleMaximizeToggle = useCallback(() => {
|
|
402
435
|
if (mobileFullscreen) return;
|
|
403
436
|
if (isMaximized) {
|
|
404
|
-
setBounds(clampBounds(boundsBeforeMaximizeRef.current));
|
|
437
|
+
setBounds(clampBounds(boundsBeforeMaximizeRef.current, topInset));
|
|
405
438
|
setIsMaximized(false);
|
|
406
439
|
} else {
|
|
407
440
|
boundsBeforeMaximizeRef.current = { ...bounds };
|
|
408
|
-
setBounds(getMaximizedBounds());
|
|
441
|
+
setBounds(getMaximizedBounds(topInset));
|
|
409
442
|
setIsMaximized(true);
|
|
410
443
|
}
|
|
411
|
-
}, [mobileFullscreen, isMaximized, bounds]);
|
|
444
|
+
}, [mobileFullscreen, isMaximized, bounds, topInset]);
|
|
412
445
|
|
|
413
446
|
const onResizePointerMove = useCallback((e: PointerEvent) => {
|
|
414
447
|
if (!resizeRef.current) return;
|
|
@@ -439,7 +472,7 @@ function AppWindow({
|
|
|
439
472
|
next.y = startBounds.y + startBounds.h - h;
|
|
440
473
|
next.h = h;
|
|
441
474
|
}
|
|
442
|
-
pendingResizeBoundsRef.current = clampBounds(next);
|
|
475
|
+
pendingResizeBoundsRef.current = clampBounds(next, topInsetRef.current);
|
|
443
476
|
if (resizeRafRef.current === null) {
|
|
444
477
|
resizeRafRef.current = requestAnimationFrame(() => {
|
|
445
478
|
const pending = pendingResizeBoundsRef.current;
|
|
@@ -516,9 +549,20 @@ function AppWindow({
|
|
|
516
549
|
{/* Title bar: pointer capture so drag continues when cursor is over iframe or outside window */}
|
|
517
550
|
<div
|
|
518
551
|
className={cn(
|
|
519
|
-
'flex items-center gap-2
|
|
552
|
+
'flex items-center gap-2 pr-1 bg-muted/80 border-b border-border select-none shrink-0',
|
|
553
|
+
flushTitlebar ? 'box-border' : 'py-1 pl-2',
|
|
520
554
|
lockedChrome ? 'cursor-default' : 'cursor-move',
|
|
521
555
|
)}
|
|
556
|
+
style={
|
|
557
|
+
flushTitlebar
|
|
558
|
+
? {
|
|
559
|
+
height: DESKTOP_TITLEBAR_HEIGHT_PX,
|
|
560
|
+
paddingTop: DESKTOP_TITLEBAR_PAD_TOP_PX,
|
|
561
|
+
paddingLeft: trafficLights ? MAC_TRAFFIC_LIGHTS_WIDTH_PX : 8,
|
|
562
|
+
}
|
|
563
|
+
: undefined
|
|
564
|
+
}
|
|
565
|
+
{...(flushTitlebar ? { 'data-shellui-drag-region': '', 'data-tauri-drag-region': '' } : {})}
|
|
522
566
|
onPointerDown={handleTitlePointerDown}
|
|
523
567
|
>
|
|
524
568
|
{win.icon && (
|
|
@@ -531,6 +575,7 @@ function AppWindow({
|
|
|
531
575
|
)}
|
|
532
576
|
/>
|
|
533
577
|
)}
|
|
578
|
+
{flushTitlebar && isTauriEnv ? <DesktopHistoryButtons /> : null}
|
|
534
579
|
<WindowTitleBarActions
|
|
535
580
|
frameUuid={frameUuid}
|
|
536
581
|
fallbackTitle={windowLabel}
|
|
@@ -731,6 +776,8 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
731
776
|
const { settings } = useSettings();
|
|
732
777
|
/** Fullscreen phone chrome — includes iPhone landscape (wide but short). */
|
|
733
778
|
const phoneMode = useWindowsPhoneMode();
|
|
779
|
+
const trafficLights = useMacTrafficLights();
|
|
780
|
+
const topInset = trafficLights ? DESKTOP_TITLEBAR_HEIGHT_PX : 0;
|
|
734
781
|
const currentLanguage = i18n.language || 'en';
|
|
735
782
|
const hasCustomLoginNav = useMemo(() => hasLoginNavigationItem(navigation), [navigation]);
|
|
736
783
|
const authAwareNavigation = useMemo(
|
|
@@ -787,7 +834,9 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
787
834
|
item.openIn === 'external' && !item.icon ? getExternalFaviconUrl(item.url) : null;
|
|
788
835
|
const icon = item.icon ?? faviconUrl ?? null;
|
|
789
836
|
const id = genId();
|
|
790
|
-
const bounds = phoneMode
|
|
837
|
+
const bounds = phoneMode
|
|
838
|
+
? getMaximizedBounds(topInset)
|
|
839
|
+
: getDefaultOpenBounds(windows.length, topInset);
|
|
791
840
|
const next: WindowState = {
|
|
792
841
|
id,
|
|
793
842
|
path: item.path,
|
|
@@ -802,7 +851,7 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
802
851
|
setFrontWindowId(id);
|
|
803
852
|
setStartMenuOpen(false);
|
|
804
853
|
},
|
|
805
|
-
[currentLanguage, phoneMode, windows.length],
|
|
854
|
+
[currentLanguage, phoneMode, topInset, windows.length],
|
|
806
855
|
);
|
|
807
856
|
|
|
808
857
|
// On first load only: open a window for the current URL if it matches a nav item (no reaction to later URL changes)
|
|
@@ -911,6 +960,17 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
911
960
|
}}
|
|
912
961
|
/>
|
|
913
962
|
|
|
963
|
+
{trafficLights ? (
|
|
964
|
+
<div
|
|
965
|
+
data-shellui-windows-titlebar=""
|
|
966
|
+
data-shellui-drag-region=""
|
|
967
|
+
data-tauri-drag-region=""
|
|
968
|
+
aria-hidden
|
|
969
|
+
className="absolute inset-x-0 top-0 border-b border-border bg-sidebar-background"
|
|
970
|
+
style={{ height: DESKTOP_TITLEBAR_HEIGHT_PX, zIndex: Z_INDEX.WINDOWS_TITLEBAR }}
|
|
971
|
+
/>
|
|
972
|
+
) : null}
|
|
973
|
+
|
|
914
974
|
{/* Desktop area: windows */}
|
|
915
975
|
{windows.map((win, index) => {
|
|
916
976
|
const navItem = navigationItems.find((n) => n.path === win.path);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import type { ShellUIConfig } from '../config/types';
|
|
3
3
|
import {
|
|
4
4
|
getAiRequestTrustDenial,
|
|
5
5
|
getStorageRequestTrustDenial,
|
|
6
6
|
isRegisteredTrustedFrame,
|
|
7
7
|
isShellSettingsFrameMessage,
|
|
8
|
+
isShellSettingsFrameSrc,
|
|
8
9
|
isTrustedFrameForAuthToken,
|
|
9
10
|
resolveRegisteredFrameSrc,
|
|
10
11
|
} from './trustedFrames';
|
|
@@ -130,6 +131,21 @@ describe('isTrustedFrameForAuthToken', () => {
|
|
|
130
131
|
it('denies unrelated origins', () => {
|
|
131
132
|
expect(isTrustedFrameForAuthToken('https://evil.example.com/payload', config)).toBe(false);
|
|
132
133
|
});
|
|
134
|
+
|
|
135
|
+
it('shares the access token with the shell settings modal', () => {
|
|
136
|
+
vi.stubGlobal('window', { location: { origin: 'http://localhost:4000' } });
|
|
137
|
+
expect(
|
|
138
|
+
isShellSettingsFrameSrc('http://localhost:4000/__settings/storage', 'http://localhost:4000'),
|
|
139
|
+
).toBe(true);
|
|
140
|
+
expect(isTrustedFrameForAuthToken('http://localhost:4000/__settings', config)).toBe(true);
|
|
141
|
+
expect(isTrustedFrameForAuthToken('http://localhost:4000/__settings/storage', config)).toBe(
|
|
142
|
+
true,
|
|
143
|
+
);
|
|
144
|
+
expect(isTrustedFrameForAuthToken('/__settings/storage', config)).toBe(true);
|
|
145
|
+
expect(isTrustedFrameForAuthToken('http://localhost:4000/__settings-fake', config)).toBe(false);
|
|
146
|
+
expect(isTrustedFrameForAuthToken('http://evil.test/__settings/storage', config)).toBe(false);
|
|
147
|
+
vi.unstubAllGlobals();
|
|
148
|
+
});
|
|
133
149
|
});
|
|
134
150
|
|
|
135
151
|
describe('resolveRegisteredFrameSrc', () => {
|
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
import type { ShellUIConfig } from '../config/types';
|
|
2
|
+
import urls from '../../constants/urls';
|
|
2
3
|
import { isAdminFrame } from '../admin/utils';
|
|
3
4
|
import { flattenNavigationItems, isFrameForAppUrl } from '../layouts/utils';
|
|
4
5
|
|
|
6
|
+
function currentShellOrigin(): string | null {
|
|
7
|
+
const origin = globalThis.window?.location?.origin;
|
|
8
|
+
return typeof origin === 'string' && origin.length > 0 ? origin : null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Same-origin shell settings document, including routes under `/__settings/`. */
|
|
12
|
+
export function isShellSettingsFrameSrc(
|
|
13
|
+
frameSrc: string,
|
|
14
|
+
shellOrigin: string,
|
|
15
|
+
settingsPath: string = urls.settings,
|
|
16
|
+
): boolean {
|
|
17
|
+
try {
|
|
18
|
+
const url = new URL(frameSrc, shellOrigin);
|
|
19
|
+
const base = `/${settingsPath.replace(/^\/+|\/+$/g, '')}`;
|
|
20
|
+
return (
|
|
21
|
+
url.origin === shellOrigin && (url.pathname === base || url.pathname.startsWith(`${base}/`))
|
|
22
|
+
);
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
5
28
|
/** Minimal frame registry surface for trust checks (shared with #60 message gating). */
|
|
6
29
|
export type FrameRegistryLike = {
|
|
7
30
|
getAllIframes(): Array<[string, HTMLIFrameElement]>;
|
|
@@ -13,6 +36,13 @@ export type FrameRegistryLike = {
|
|
|
13
36
|
* First-party admin URLs and `storage.filesUrl` remain trusted by default.
|
|
14
37
|
*/
|
|
15
38
|
export function isTrustedFrameForAuthToken(frameSrc: string, config?: ShellUIConfig): boolean {
|
|
39
|
+
// Settings opened as a modal or drawer is a shell iframe. It is not a companion
|
|
40
|
+
// app, so it has no `safeForAuthToken` flag, but pages such as Storage need the JWT.
|
|
41
|
+
const shellOrigin = currentShellOrigin();
|
|
42
|
+
if (shellOrigin && isShellSettingsFrameSrc(frameSrc, shellOrigin)) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
16
46
|
if (isAdminFrame(frameSrc, config)) {
|
|
17
47
|
return true;
|
|
18
48
|
}
|
|
@@ -83,15 +113,7 @@ export function isShellSettingsFrameMessage(
|
|
|
83
113
|
if (!frameSrc) {
|
|
84
114
|
return false;
|
|
85
115
|
}
|
|
86
|
-
|
|
87
|
-
const url = new URL(frameSrc, shellOrigin);
|
|
88
|
-
const base = `/${settingsPath.replace(/^\/+|\/+$/g, '')}`;
|
|
89
|
-
return (
|
|
90
|
-
url.origin === shellOrigin && (url.pathname === base || url.pathname.startsWith(`${base}/`))
|
|
91
|
-
);
|
|
92
|
-
} catch {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
116
|
+
return isShellSettingsFrameSrc(frameSrc, shellOrigin, settingsPath);
|
|
95
117
|
}
|
|
96
118
|
|
|
97
119
|
export type StorageTrustDenial = { message: string; status: 403 };
|