@shellui/core 0.6.0 → 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/schemas/shellui.config.schema.json +15 -0
- package/src/features/admin/AdminView.tsx +18 -4
- package/src/features/auth/AuthProvider.tsx +184 -69
- package/src/features/auth/backends/shellui.spec.ts +115 -0
- package/src/features/auth/backends/shellui.ts +8 -2
- package/src/features/auth/backends/types.ts +9 -1
- package/src/features/auth/hooks/useAuth.tsx +1 -0
- package/src/features/auth/utils/accessTokenRefreshDue.spec.ts +15 -0
- package/src/features/auth/utils/accessTokenRefreshDue.ts +8 -0
- package/src/features/auth/utils/desktopAuthCallback.spec.ts +68 -0
- package/src/features/auth/utils/desktopAuthCallback.ts +126 -0
- package/src/features/auth/utils/desktopSignIn.spec.ts +203 -0
- package/src/features/auth/utils/desktopSignIn.ts +483 -0
- package/src/features/auth/utils/frameSessionRefresher.spec.ts +23 -0
- package/src/features/auth/utils/frameSessionRefresher.ts +21 -0
- package/src/features/auth/utils/pkce.spec.ts +36 -0
- package/src/features/auth/utils/pkce.ts +38 -0
- package/src/features/chromeActions/ChromeActionsHost.tsx +7 -1
- package/src/features/chromeActions/computeActionInsets.ts +6 -0
- package/src/features/config/types.ts +17 -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 +86 -31
- package/src/features/settings/utils/buildSettingsForPropagation.ts +9 -2
- package/src/index.css +16 -1
- package/src/index.ts +6 -0
- package/src/lib/z-index.ts +5 -0
|
@@ -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 };
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
type ReactNode,
|
|
9
9
|
} from 'react';
|
|
10
10
|
import {
|
|
11
|
+
bindVisibleResume,
|
|
12
|
+
deliverSessionHandoff,
|
|
11
13
|
getLogger,
|
|
12
14
|
shellui,
|
|
13
15
|
type ShellUIMessage,
|
|
@@ -29,6 +31,7 @@ import {
|
|
|
29
31
|
toSettingsUser,
|
|
30
32
|
} from './utils';
|
|
31
33
|
import { unregisterServiceWorker } from '../../service-worker/register';
|
|
34
|
+
import { refreshFrameAccessTokenIfNeeded } from '../auth/utils/frameSessionRefresher';
|
|
32
35
|
|
|
33
36
|
const logger = getLogger('shellcore');
|
|
34
37
|
|
|
@@ -210,6 +213,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
210
213
|
includeAuthAccessToken,
|
|
211
214
|
accessToken,
|
|
212
215
|
includeLayoutChrome: isMainLayoutFrame(iframe),
|
|
216
|
+
frameUuid: uuid,
|
|
213
217
|
});
|
|
214
218
|
shellui.sendMessage({
|
|
215
219
|
type: 'SHELLUI_SETTINGS',
|
|
@@ -232,6 +236,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
232
236
|
includeAuthAccessToken,
|
|
233
237
|
accessToken: accessTokenRef.current,
|
|
234
238
|
includeLayoutChrome: isMainLayoutFrame(iframe),
|
|
239
|
+
frameUuid: iframeUuid,
|
|
235
240
|
});
|
|
236
241
|
shellui.sendMessage({
|
|
237
242
|
type: 'SHELLUI_SETTINGS',
|
|
@@ -242,15 +247,38 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
242
247
|
[config, isTrustedFrameForAuthTokenCallback],
|
|
243
248
|
);
|
|
244
249
|
|
|
250
|
+
const applyHandoffToken = useCallback((token: string | null | undefined) => {
|
|
251
|
+
if (token !== undefined) accessTokenRef.current = token;
|
|
252
|
+
}, []);
|
|
253
|
+
|
|
254
|
+
const handoffSettingsToIframes = useCallback(() => {
|
|
255
|
+
const base = settingsRef.current ?? defaultSettings;
|
|
256
|
+
return deliverSessionHandoff(() => propagateSettingsToIframes(base));
|
|
257
|
+
}, [propagateSettingsToIframes]);
|
|
258
|
+
|
|
245
259
|
// When the shell rotates the JWT, `authUser` often does not change, so the user-sync effect
|
|
246
260
|
// above skips — still push `SHELLUI_SETTINGS` so trusted iframes get the new `accessToken`.
|
|
261
|
+
// The follow-up turn covers an app that subscribes after the first post.
|
|
247
262
|
const accessTokenForChildren = session?.accessToken ?? null;
|
|
248
263
|
useEffect(() => {
|
|
249
264
|
if (typeof window === 'undefined' || window.parent !== window || !accessTokenForChildren) {
|
|
250
265
|
return;
|
|
251
266
|
}
|
|
252
|
-
|
|
253
|
-
}, [accessTokenForChildren,
|
|
267
|
+
return handoffSettingsToIframes();
|
|
268
|
+
}, [accessTokenForChildren, handoffSettingsToIframes]);
|
|
269
|
+
|
|
270
|
+
// Background tabs throttle the refresh interval. On show, refresh if due and
|
|
271
|
+
// re-send the session even when the token string did not change.
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
if (typeof window === 'undefined' || window.parent !== window) return;
|
|
274
|
+
return bindVisibleResume(() => {
|
|
275
|
+
void (async () => {
|
|
276
|
+
const token = await refreshFrameAccessTokenIfNeeded();
|
|
277
|
+
applyHandoffToken(token);
|
|
278
|
+
handoffSettingsToIframes();
|
|
279
|
+
})();
|
|
280
|
+
});
|
|
281
|
+
}, [applyHandoffToken, handoffSettingsToIframes]);
|
|
254
282
|
|
|
255
283
|
// Keep load/sync helpers stable across access-token rotation (refresh after preference sync).
|
|
256
284
|
const loadUserPreferencesRef = useRef(loadUserPreferences);
|
|
@@ -449,35 +477,51 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
449
477
|
const cleanupSettingsRequested = shellui.addMessageListener(
|
|
450
478
|
'SHELLUI_SETTINGS_REQUESTED',
|
|
451
479
|
(message: ShellUIMessage) => {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
const
|
|
459
|
-
.
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
480
|
+
void (async () => {
|
|
481
|
+
// An app that asks while the access token is expired must get a fresh one,
|
|
482
|
+
// not the JWT that died while the tab was hidden.
|
|
483
|
+
const token = await refreshFrameAccessTokenIfNeeded();
|
|
484
|
+
applyHandoffToken(token);
|
|
485
|
+
|
|
486
|
+
const send = () => {
|
|
487
|
+
const currentSettings = settingsRef.current ?? defaultSettings;
|
|
488
|
+
const requestingPath = (message.from ?? []).filter(Boolean);
|
|
489
|
+
|
|
490
|
+
if (requestingPath.length > 0) {
|
|
491
|
+
const [firstHopIframeUuid] = requestingPath;
|
|
492
|
+
const frame = shellui.frameRegistry
|
|
493
|
+
.getAllIframes()
|
|
494
|
+
.find(([uuid]) => uuid === firstHopIframeUuid)?.[1];
|
|
495
|
+
const lang = currentSettings.language?.code || 'en';
|
|
496
|
+
const includeAuthAccessToken = frame
|
|
497
|
+
? isTrustedFrameForAuthTokenCallback(frame.src ?? '')
|
|
498
|
+
: false;
|
|
499
|
+
const settingsToPropagate = buildSettingsForPropagation(
|
|
500
|
+
currentSettings,
|
|
501
|
+
config,
|
|
502
|
+
lang,
|
|
503
|
+
{
|
|
504
|
+
includeAuthAccessToken,
|
|
505
|
+
accessToken: accessTokenRef.current,
|
|
506
|
+
includeLayoutChrome: isMainLayoutFrame(frame),
|
|
507
|
+
frameUuid: firstHopIframeUuid,
|
|
508
|
+
},
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
// Route through the full parent -> child -> ... -> requester path so deep descendants
|
|
512
|
+
// receive settings even when they are nested more than one level under root.
|
|
513
|
+
shellui.sendMessage({
|
|
514
|
+
type: 'SHELLUI_SETTINGS',
|
|
515
|
+
payload: { settings: settingsToPropagate },
|
|
516
|
+
to: requestingPath,
|
|
517
|
+
});
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
propagateSettingsToIframes(currentSettings);
|
|
521
|
+
};
|
|
470
522
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
shellui.sendMessage({
|
|
474
|
-
type: 'SHELLUI_SETTINGS',
|
|
475
|
-
payload: { settings: settingsToPropagate },
|
|
476
|
-
to: requestingPath,
|
|
477
|
-
});
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
propagateSettingsToIframes(currentSettings);
|
|
523
|
+
deliverSessionHandoff(send);
|
|
524
|
+
})();
|
|
481
525
|
},
|
|
482
526
|
);
|
|
483
527
|
|
|
@@ -518,7 +562,17 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
518
562
|
.find(([, iframe]) => iframe?.contentWindow === source);
|
|
519
563
|
if (!match) return;
|
|
520
564
|
const [iframeUuid, iframe] = match;
|
|
521
|
-
|
|
565
|
+
void (async () => {
|
|
566
|
+
const token = await refreshFrameAccessTokenIfNeeded();
|
|
567
|
+
applyHandoffToken(token);
|
|
568
|
+
deliverSessionHandoff(() =>
|
|
569
|
+
pushSettingsToFrame(
|
|
570
|
+
iframeUuid,
|
|
571
|
+
iframe?.src ?? '',
|
|
572
|
+
settingsRef.current ?? defaultSettings,
|
|
573
|
+
),
|
|
574
|
+
);
|
|
575
|
+
})();
|
|
522
576
|
},
|
|
523
577
|
);
|
|
524
578
|
|
|
@@ -531,6 +585,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
531
585
|
}, [
|
|
532
586
|
config,
|
|
533
587
|
isTrustedFrameForAuthTokenCallback,
|
|
588
|
+
applyHandoffToken,
|
|
534
589
|
propagateSettingsToIframes,
|
|
535
590
|
pushSettingsToFrame,
|
|
536
591
|
schedulePropagateSettingsToIframes,
|
|
@@ -4,7 +4,10 @@ import { flattenNavigationItems } from './flattenNavigationItems';
|
|
|
4
4
|
import { getAvailableThemesForSettings } from './getAvailableThemesForSettings';
|
|
5
5
|
import { getResolvedAppearanceForSettings } from './getResolvedAppearanceForSettings';
|
|
6
6
|
import { resolveLabel } from './resolveLabel';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
getLayoutChromeForFrame,
|
|
9
|
+
getPublishedLayoutChrome,
|
|
10
|
+
} from '../../layouts/floating/layoutChromeStore';
|
|
8
11
|
|
|
9
12
|
/** Production email-service origin. No trailing slash. */
|
|
10
13
|
const DEFAULT_EMAIL_SERVICE_URL = 'https://email.shellui.com';
|
|
@@ -31,6 +34,8 @@ export const buildSettingsForPropagation = (
|
|
|
31
34
|
accessToken?: string | null;
|
|
32
35
|
/** When false, omit layoutChrome (modal / drawer frames). Default true. */
|
|
33
36
|
includeLayoutChrome?: boolean;
|
|
37
|
+
/** Merge this frame's action-bar insets into layoutChrome. */
|
|
38
|
+
frameUuid?: string;
|
|
34
39
|
},
|
|
35
40
|
): Settings => {
|
|
36
41
|
const appearance = getResolvedAppearanceForSettings(settings, config);
|
|
@@ -40,7 +45,9 @@ export const buildSettingsForPropagation = (
|
|
|
40
45
|
};
|
|
41
46
|
|
|
42
47
|
if (options?.includeLayoutChrome !== false) {
|
|
43
|
-
const layoutChrome =
|
|
48
|
+
const layoutChrome = options?.frameUuid
|
|
49
|
+
? getLayoutChromeForFrame(options.frameUuid)
|
|
50
|
+
: getPublishedLayoutChrome();
|
|
44
51
|
if (layoutChrome) {
|
|
45
52
|
result = { ...result, layoutChrome };
|
|
46
53
|
} else if ('layoutChrome' in result) {
|
package/src/index.css
CHANGED
|
@@ -169,6 +169,11 @@
|
|
|
169
169
|
border-radius: var(--shellui-floating-sidebar-radius);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
/* Tauri floating sidebar is flush to the window, so the frame itself is square. */
|
|
173
|
+
.shellui-floating-sidebar-panel .shellui-floating-glass[data-shellui-tauri-flush] {
|
|
174
|
+
border-radius: 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
172
177
|
.dark .shellui-floating-glass {
|
|
173
178
|
background:
|
|
174
179
|
linear-gradient(
|
|
@@ -1369,12 +1374,22 @@ html[data-shellui-collapsed-titlebar][data-shellui-safe-area-topbar]
|
|
|
1369
1374
|
}
|
|
1370
1375
|
|
|
1371
1376
|
html[data-shellui-collapsed-titlebar]
|
|
1372
|
-
[data-shellui-sidebar-layout]
|
|
1377
|
+
[data-shellui-sidebar-layout]:not([data-shellui-layout-variant='inset'])
|
|
1373
1378
|
> [data-slot='sidebar-wrapper']
|
|
1374
1379
|
> [data-slot='sidebar-inset'] {
|
|
1375
1380
|
padding-top: var(--shellui-titlebar-height, 42px);
|
|
1376
1381
|
}
|
|
1377
1382
|
|
|
1383
|
+
/* Inset card keeps its own radius: sit the frame under the titlebar instead of
|
|
1384
|
+
padding inside the rounded border (that left the top corners covered). */
|
|
1385
|
+
html[data-shellui-collapsed-titlebar]
|
|
1386
|
+
[data-shellui-layout-variant='inset']
|
|
1387
|
+
> [data-slot='sidebar-wrapper']
|
|
1388
|
+
> [data-slot='sidebar-inset'] {
|
|
1389
|
+
margin-top: var(--shellui-titlebar-height, 42px);
|
|
1390
|
+
padding-top: 0;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1378
1393
|
/* Root safe-area topbar: collapsed chrome sits below the status band. */
|
|
1379
1394
|
html[data-shellui-safe-area-topbar] [data-shellui-collapsed-titlebar] {
|
|
1380
1395
|
top: var(--shellui-safe-area-top);
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ export type {
|
|
|
26
26
|
LayoutType,
|
|
27
27
|
BackendType,
|
|
28
28
|
BackendConfig,
|
|
29
|
+
AuthConfig,
|
|
29
30
|
AdministrationConfig,
|
|
30
31
|
StorageConfig,
|
|
31
32
|
HostingConfig,
|
|
@@ -102,6 +103,11 @@ export {
|
|
|
102
103
|
} from './features/theme/themes.js';
|
|
103
104
|
export { useConfig } from './features/config/useConfig.js';
|
|
104
105
|
export { useAuth } from './features/auth/hooks/useAuth.js';
|
|
106
|
+
export {
|
|
107
|
+
configureDesktopAuth,
|
|
108
|
+
handleDesktopAuthCallback,
|
|
109
|
+
} from './features/auth/utils/desktopSignIn.js';
|
|
110
|
+
export type { DesktopAuthAdapters } from './features/auth/utils/desktopSignIn.js';
|
|
105
111
|
export { AuthProvider } from './features/auth/AuthProvider.js';
|
|
106
112
|
export { ConfigProvider } from './features/config/ConfigProvider.js';
|
|
107
113
|
export type { ConfigContextValue, ConfigProviderProps } from './features/config/ConfigProvider.js';
|