@shellui/core 0.3.1 → 0.4.1

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.
Files changed (59) hide show
  1. package/package.json +2 -2
  2. package/src/app.tsx +11 -1
  3. package/src/components/ui/dialog.tsx +26 -6
  4. package/src/components/ui/sonner.tsx +9 -5
  5. package/src/features/admin/AdminView.tsx +1 -20
  6. package/src/features/auth/AuthProvider.tsx +68 -13
  7. package/src/features/auth/backends/shellui.ts +8 -1
  8. package/src/features/auth/components/AccessPendingView.tsx +112 -0
  9. package/src/features/auth/components/LoginView.tsx +17 -0
  10. package/src/features/auth/components/OAuthCallbackView.tsx +211 -48
  11. package/src/features/auth/hooks/useAuth.tsx +8 -1
  12. package/src/features/auth/utils/authRequestError.spec.ts +52 -0
  13. package/src/features/auth/utils/authRequestError.ts +45 -0
  14. package/src/features/auth/utils/index.ts +7 -0
  15. package/src/features/auth/utils/isTokenAutoRefreshDisabled.spec.ts +71 -0
  16. package/src/features/auth/utils/isTokenAutoRefreshDisabled.ts +18 -0
  17. package/src/features/config/types.ts +46 -0
  18. package/src/features/layouts/AppLayout.tsx +3 -3
  19. package/src/features/layouts/OverlayShell.tsx +10 -6
  20. package/src/features/modal/ModalContext.spec.ts +77 -0
  21. package/src/features/modal/ModalContext.tsx +12 -50
  22. package/src/features/modal/validateAndNormalizeUrl.ts +96 -0
  23. package/src/features/settings/SettingsIcons.tsx +35 -0
  24. package/src/features/settings/SettingsProvider.tsx +69 -4
  25. package/src/features/settings/SettingsRoutes.tsx +14 -6
  26. package/src/features/settings/SettingsView.tsx +11 -5
  27. package/src/features/settings/components/Advanced.tsx +117 -44
  28. package/src/features/settings/components/Develop.tsx +38 -0
  29. package/src/features/settings/components/Storage.tsx +138 -0
  30. package/src/features/settings/components/develop/StoragePickerTestButtons.tsx +148 -0
  31. package/src/features/settings/components/develop/UploadToastTestButton.tsx +29 -0
  32. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +54 -0
  33. package/src/features/settings/utils/buildSettingsForPropagation.ts +34 -0
  34. package/src/features/settings/utils/toSettingsUser.spec.ts +4 -0
  35. package/src/features/settings/utils/toSettingsUser.ts +2 -0
  36. package/src/features/storage/StorageBridge.tsx +50 -0
  37. package/src/features/storage/StoragePickerContext.tsx +214 -0
  38. package/src/features/storage/api.spec.ts +303 -0
  39. package/src/features/storage/api.ts +414 -0
  40. package/src/features/storage/handleRequest.spec.ts +88 -0
  41. package/src/features/storage/handleRequest.ts +53 -0
  42. package/src/features/storage/quota.spec.ts +151 -0
  43. package/src/features/storage/quota.ts +104 -0
  44. package/src/features/storage/uploads/UploadToastCard.tsx +442 -0
  45. package/src/features/storage/uploads/UploadToaster.tsx +41 -0
  46. package/src/features/storage/uploads/handleTrackedUpload.spec.ts +170 -0
  47. package/src/features/storage/uploads/handleTrackedUpload.ts +97 -0
  48. package/src/features/storage/uploads/types.ts +24 -0
  49. package/src/features/storage/uploads/uploadQueue.spec.ts +118 -0
  50. package/src/features/storage/uploads/uploadQueue.ts +349 -0
  51. package/src/features/storage/uploads/useUploadQueue.ts +30 -0
  52. package/src/i18n/translations/en/common.json +33 -0
  53. package/src/i18n/translations/en/settings.json +47 -4
  54. package/src/i18n/translations/fr/common.json +33 -0
  55. package/src/i18n/translations/fr/settings.json +47 -4
  56. package/src/index.css +2 -1
  57. package/src/index.ts +2 -0
  58. package/src/lib/z-index.ts +9 -3
  59. package/src/service-worker/register.ts +4 -12
@@ -5,20 +5,20 @@ import { shellui } from '@shellui/sdk';
5
5
  import type { NavigationItem } from '../config/types';
6
6
  import { Dialog, DialogContent, DialogTitle, DialogDescription } from '../../components/ui/dialog';
7
7
  import { Drawer, DrawerContent } from '../../components/ui/drawer';
8
- import { Toaster } from '../../components/ui/sonner';
9
8
  import { ContentView } from '../../components/ContentView';
10
9
  import { useModal } from '../modal/ModalContext';
11
10
  import { useDrawer } from '../drawer/DrawerContext';
11
+ import { useStoragePicker } from '../storage/StoragePickerContext';
12
12
  import { useNavigationItems } from '../../routes/hooks/useNavigationItems';
13
13
  import { useConfig } from '../config/useConfig';
14
- import { getNavPathPrefix, resolveLocalizedString } from './utils';
14
+ import { resolveLocalizedString } from './utils';
15
15
  import { resolveSdkNavigatePath } from './resolveSdkNavigatePath';
16
16
 
17
17
  interface OverlayShellProps {
18
18
  children: ReactNode;
19
19
  }
20
20
 
21
- /** Renders modal, drawer and toaster overlays and handles SHELLUI_OPEN_MODAL / SHELLUI_NAVIGATE. */
21
+ /** Renders modal and drawer overlays and handles SHELLUI_OPEN_MODAL / SHELLUI_NAVIGATE. */
22
22
  export const OverlayShell = ({ children }: OverlayShellProps) => {
23
23
  const location = useLocation();
24
24
  const navigate = useNavigate();
@@ -32,6 +32,7 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
32
32
  size: drawerSize,
33
33
  closeDrawer,
34
34
  } = useDrawer();
35
+ const { isOpen: isPickerOpen, closePicker } = useStoragePicker();
35
36
  const { t, i18n } = useTranslation('common');
36
37
  const currentLanguage = i18n.language || 'en';
37
38
 
@@ -42,9 +43,10 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
42
43
  if (locationKeyRef.current !== currentKey) {
43
44
  closeModal();
44
45
  closeDrawer();
46
+ closePicker();
45
47
  locationKeyRef.current = currentKey;
46
48
  }
47
- }, [location.pathname, location.search, location.hash, closeModal, closeDrawer]);
49
+ }, [location.pathname, location.search, location.hash, closeModal, closeDrawer, closePicker]);
48
50
 
49
51
  useEffect(() => {
50
52
  const cleanup = shellui.addMessageListener('SHELLUI_OPEN_MODAL', () => {
@@ -81,7 +83,10 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
81
83
  {children}
82
84
  <Dialog
83
85
  open={isOpen}
84
- onOpenChange={(open) => !open && closeModal()}
86
+ onOpenChange={(open) => {
87
+ if (!open && isPickerOpen) return;
88
+ if (!open) closeModal();
89
+ }}
85
90
  >
86
91
  <DialogContent className="max-w-4xl w-full h-[80vh] max-h-[680px] flex flex-col p-0 overflow-hidden">
87
92
  {modalUrl ? (
@@ -164,7 +169,6 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
164
169
  )}
165
170
  </DrawerContent>
166
171
  </Drawer>
167
- <Toaster />
168
172
  </>
169
173
  );
170
174
  };
@@ -0,0 +1,77 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { DEFAULT_ADMIN_URL } from '../admin/config';
3
+ import type { ShellUIConfig } from '../config/types';
4
+ import { validateAndNormalizeUrl } from './validateAndNormalizeUrl';
5
+
6
+ const config = {
7
+ storage: {
8
+ url: 'https://storage.example.com/',
9
+ filesUrl: 'https://files.example.com/',
10
+ },
11
+ backend: {
12
+ type: 'shellui',
13
+ url: 'https://api.example.com',
14
+ adminUrl: 'https://admin.example.com',
15
+ },
16
+ administration: {
17
+ title: 'Apps',
18
+ navigation: [
19
+ {
20
+ label: 'Billing',
21
+ path: 'billing',
22
+ url: 'https://billing.example.com/app',
23
+ },
24
+ {
25
+ label: 'Django admin',
26
+ path: 'django-admin',
27
+ url: 'https://untrusted.example.com/admin',
28
+ openIn: 'external',
29
+ },
30
+ ],
31
+ },
32
+ } as ShellUIConfig;
33
+
34
+ describe('validateAndNormalizeUrl', () => {
35
+ it('allows relative paths', () => {
36
+ expect(validateAndNormalizeUrl('/settings')).toBe('/settings');
37
+ });
38
+
39
+ it('allows localhost urls', () => {
40
+ expect(validateAndNormalizeUrl('http://localhost:5175/#/select')).toBe(
41
+ 'http://localhost:5175/#/select',
42
+ );
43
+ });
44
+
45
+ it('rejects unrelated origins', () => {
46
+ expect(validateAndNormalizeUrl('https://evil.example.com/form', config)).toBeNull();
47
+ });
48
+
49
+ it('allows storage.url and storage.filesUrl origins', () => {
50
+ expect(validateAndNormalizeUrl('https://storage.example.com/storage/v1/quota', config)).toBe(
51
+ 'https://storage.example.com/storage/v1/quota',
52
+ );
53
+ expect(validateAndNormalizeUrl('https://files.example.com/#/select?mode=files', config)).toBe(
54
+ 'https://files.example.com/#/select?mode=files',
55
+ );
56
+ });
57
+
58
+ it('allows the configured administration adminUrl', () => {
59
+ expect(validateAndNormalizeUrl('https://admin.example.com/#/users', config)).toBe(
60
+ 'https://admin.example.com/#/users',
61
+ );
62
+ expect(validateAndNormalizeUrl(`${DEFAULT_ADMIN_URL}/#/users`, config)).toBeNull();
63
+ });
64
+
65
+ it('allows the default administration url when adminUrl is not configured', () => {
66
+ expect(validateAndNormalizeUrl(`${DEFAULT_ADMIN_URL}/#/dashboard`)).toBe(
67
+ `${DEFAULT_ADMIN_URL}/#/dashboard`,
68
+ );
69
+ });
70
+
71
+ it('allows administration navigation urls but not external ones', () => {
72
+ expect(validateAndNormalizeUrl('https://billing.example.com/app/#/invoices', config)).toBe(
73
+ 'https://billing.example.com/app/#/invoices',
74
+ );
75
+ expect(validateAndNormalizeUrl('https://untrusted.example.com/admin', config)).toBeNull();
76
+ });
77
+ });
@@ -1,51 +1,9 @@
1
1
  import { shellui, type ShellUIMessage } from '@shellui/sdk';
2
2
  import { createContext, useContext, useState, useEffect, useCallback, type ReactNode } from 'react';
3
+ import { useConfig } from '../config/useConfig';
4
+ import { validateAndNormalizeUrl } from './validateAndNormalizeUrl';
3
5
 
4
- /**
5
- * Validates and normalizes a URL to ensure it's from the same domain or localhost
6
- * @param url - The URL or path to validate
7
- * @returns The normalized absolute URL or null if invalid
8
- */
9
- export const validateAndNormalizeUrl = (url: string | undefined | null): string | null => {
10
- if (!url || typeof url !== 'string') {
11
- return null;
12
- }
13
-
14
- try {
15
- // If it's already an absolute URL, check if it's same origin or localhost
16
- if (url.startsWith('http://') || url.startsWith('https://')) {
17
- const urlObj = new URL(url);
18
- const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
19
-
20
- // Allow same origin
21
- if (urlObj.origin === currentOrigin) {
22
- return url;
23
- }
24
-
25
- // Allow localhost URLs (for development)
26
- if (urlObj.hostname === 'localhost' || urlObj.hostname === '127.0.0.1') {
27
- return url;
28
- }
29
-
30
- return null; // Different origin, reject for security
31
- }
32
-
33
- // If it's a relative URL, make it absolute using current origin
34
- if (url.startsWith('/') || url.startsWith('./') || !url.startsWith('//')) {
35
- const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
36
- // Ensure relative paths start with /
37
- const normalizedPath = url.startsWith('/') ? url : `/${url}`;
38
- return `${currentOrigin}${normalizedPath}`;
39
- }
40
-
41
- // Reject protocol-relative URLs (//example.com) for security
42
- return null;
43
- } catch (error) {
44
- // eslint-disable-next-line no-console
45
- console.error('Invalid URL:', url, error);
46
- return null;
47
- }
48
- };
6
+ export { validateAndNormalizeUrl } from './validateAndNormalizeUrl';
49
7
 
50
8
  interface ModalContextValue {
51
9
  isOpen: boolean;
@@ -69,14 +27,18 @@ interface ModalProviderProps {
69
27
  }
70
28
 
71
29
  export const ModalProvider = ({ children }: ModalProviderProps) => {
30
+ const { config } = useConfig();
72
31
  const [isOpen, setIsOpen] = useState(false);
73
32
  const [modalUrl, setModalUrl] = useState<string | null>(null);
74
33
 
75
- const openModal = useCallback((url?: string) => {
76
- const validatedUrl = url ? validateAndNormalizeUrl(url) : null;
77
- setModalUrl(validatedUrl);
78
- setIsOpen(true);
79
- }, []);
34
+ const openModal = useCallback(
35
+ (url?: string) => {
36
+ const validatedUrl = url ? validateAndNormalizeUrl(url, config) : null;
37
+ setModalUrl(validatedUrl);
38
+ setIsOpen(true);
39
+ },
40
+ [config],
41
+ );
80
42
 
81
43
  const closeModal = useCallback(() => {
82
44
  setIsOpen(false);
@@ -0,0 +1,96 @@
1
+ import { getAdminContentUrl } from '../admin/config';
2
+ import type { ShellUIConfig } from '../config/types';
3
+
4
+ const originFromAbsoluteUrl = (value: string | undefined | null): string | null => {
5
+ if (!value || typeof value !== 'string') {
6
+ return null;
7
+ }
8
+ const trimmed = value.trim();
9
+ if (!trimmed.startsWith('http://') && !trimmed.startsWith('https://')) {
10
+ return null;
11
+ }
12
+ try {
13
+ return new URL(trimmed).origin;
14
+ } catch {
15
+ return null;
16
+ }
17
+ };
18
+
19
+ /** Origins allowed in modal iframes: storage service/files app, admin panel, and administration nav apps. */
20
+ const getAllowedModalOrigins = (config?: ShellUIConfig | null): Set<string> => {
21
+ const origins = new Set<string>();
22
+ const add = (value?: string | null) => {
23
+ const origin = originFromAbsoluteUrl(value);
24
+ if (origin) {
25
+ origins.add(origin);
26
+ }
27
+ };
28
+
29
+ add(config?.storage?.url);
30
+ add(config?.storage?.filesUrl);
31
+ add(getAdminContentUrl(config ?? undefined));
32
+
33
+ for (const item of config?.administration?.navigation ?? []) {
34
+ if (item.openIn === 'external') {
35
+ continue;
36
+ }
37
+ add(item.url);
38
+ }
39
+
40
+ return origins;
41
+ };
42
+
43
+ /**
44
+ * Validates and normalizes a URL to ensure it's from the same domain, localhost,
45
+ * storage, or administration origins configured on the host.
46
+ * @param url - The URL or path to validate
47
+ * @param config - Host config used to allow storage and administration origins
48
+ * @returns The normalized absolute URL or null if invalid
49
+ */
50
+ export const validateAndNormalizeUrl = (
51
+ url: string | undefined | null,
52
+ config?: ShellUIConfig | null,
53
+ ): string | null => {
54
+ if (!url || typeof url !== 'string') {
55
+ return null;
56
+ }
57
+
58
+ try {
59
+ // If it's already an absolute URL, check if it's same origin, localhost, or trusted
60
+ if (url.startsWith('http://') || url.startsWith('https://')) {
61
+ const urlObj = new URL(url);
62
+ const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
63
+
64
+ // Allow same origin
65
+ if (urlObj.origin === currentOrigin) {
66
+ return url;
67
+ }
68
+
69
+ // Allow localhost URLs (for development)
70
+ if (urlObj.hostname === 'localhost' || urlObj.hostname === '127.0.0.1') {
71
+ return url;
72
+ }
73
+
74
+ if (getAllowedModalOrigins(config).has(urlObj.origin)) {
75
+ return url;
76
+ }
77
+
78
+ return null; // Different origin, reject for security
79
+ }
80
+
81
+ // If it's a relative URL, make it absolute using current origin
82
+ if (url.startsWith('/') || url.startsWith('./') || !url.startsWith('//')) {
83
+ const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
84
+ // Ensure relative paths start with /
85
+ const normalizedPath = url.startsWith('/') ? url : `/${url}`;
86
+ return `${currentOrigin}${normalizedPath}`;
87
+ }
88
+
89
+ // Reject protocol-relative URLs (//example.com) for security
90
+ return null;
91
+ } catch (error) {
92
+ // eslint-disable-next-line no-console
93
+ console.error('Invalid URL:', url, error);
94
+ return null;
95
+ }
96
+ };
@@ -291,6 +291,23 @@ export const ChevronLeftIcon = () => (
291
291
  </svg>
292
292
  );
293
293
 
294
+ export const ChevronDownIcon = ({ className }: { className?: string }) => (
295
+ <svg
296
+ xmlns="http://www.w3.org/2000/svg"
297
+ width="16"
298
+ height="16"
299
+ viewBox="0 0 24 24"
300
+ fill="none"
301
+ stroke="currentColor"
302
+ strokeWidth="2"
303
+ strokeLinecap="round"
304
+ strokeLinejoin="round"
305
+ className={className}
306
+ >
307
+ <polyline points="6 9 12 15 18 9" />
308
+ </svg>
309
+ );
310
+
294
311
  export const ShieldIcon = () => (
295
312
  <svg
296
313
  xmlns="http://www.w3.org/2000/svg"
@@ -307,6 +324,24 @@ export const ShieldIcon = () => (
307
324
  </svg>
308
325
  );
309
326
 
327
+ export const AlertTriangleIcon = () => (
328
+ <svg
329
+ xmlns="http://www.w3.org/2000/svg"
330
+ width="16"
331
+ height="16"
332
+ viewBox="0 0 24 24"
333
+ fill="none"
334
+ stroke="currentColor"
335
+ strokeWidth="2"
336
+ strokeLinecap="round"
337
+ strokeLinejoin="round"
338
+ >
339
+ <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" />
340
+ <path d="M12 9v4" />
341
+ <path d="M12 17h.01" />
342
+ </svg>
343
+ );
344
+
310
345
  export const HardDriveIcon = () => (
311
346
  <svg
312
347
  xmlns="http://www.w3.org/2000/svg"
@@ -90,6 +90,7 @@ const defaultAppearance: Appearance = {
90
90
  const defaultSettings: Settings = {
91
91
  developerFeatures: {
92
92
  enabled: false,
93
+ disableTokenAutoRefresh: false,
93
94
  },
94
95
  errorReporting: {
95
96
  enabled: true,
@@ -153,6 +154,13 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
153
154
  ...parsed.logging?.namespaces,
154
155
  },
155
156
  },
157
+ developerFeatures: {
158
+ enabled:
159
+ parsed.developerFeatures?.enabled ?? defaultSettings.developerFeatures.enabled,
160
+ disableTokenAutoRefresh:
161
+ parsed.developerFeatures?.disableTokenAutoRefresh ??
162
+ defaultSettings.developerFeatures.disableTokenAutoRefresh,
163
+ },
156
164
  appearance: {
157
165
  ...defaultAppearance,
158
166
  ...parsed.appearance,
@@ -211,6 +219,22 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
211
219
  if (isAdminFrame(frameSrc, config)) {
212
220
  return true;
213
221
  }
222
+ // Trust admin-panel iframe apps (navigation + storage files explorer / viewer modals).
223
+ const adminNavItems = config?.administration?.navigation ?? [];
224
+ if (
225
+ adminNavItems.some(
226
+ (item) =>
227
+ item.openIn !== 'external' &&
228
+ Boolean(item.url?.trim()) &&
229
+ isFrameForNavigationItem(frameSrc, item.url),
230
+ )
231
+ ) {
232
+ return true;
233
+ }
234
+ const filesUrl = config?.storage?.filesUrl?.trim();
235
+ if (filesUrl && isFrameForNavigationItem(frameSrc, filesUrl)) {
236
+ return true;
237
+ }
214
238
  return navigationItems.some(
215
239
  (item) => item.safeForAuthToken !== false && isFrameForNavigationItem(frameSrc, item.url),
216
240
  );
@@ -218,17 +242,21 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
218
242
  [config, navigationItems],
219
243
  );
220
244
 
245
+ const accessTokenRef = useRef<string | null>(session?.accessToken ?? null);
246
+ accessTokenRef.current = session?.accessToken ?? null;
247
+
221
248
  const propagateSettingsToIframes = useCallback(
222
249
  (baseSettings: Settings) => {
223
250
  const iframes = shellui.frameRegistry.getAllIframes();
224
251
  if (iframes.length === 0) return;
225
252
  const lang = baseSettings.language?.code || 'en';
253
+ const accessToken = accessTokenRef.current;
226
254
  for (const [uuid, iframe] of iframes) {
227
255
  const frameSrc = iframe?.src ?? '';
228
256
  const includeAuthAccessToken = isTrustedFrameForAuthToken(frameSrc);
229
257
  const settingsToPropagate = buildSettingsForPropagation(baseSettings, config, lang, {
230
258
  includeAuthAccessToken,
231
- accessToken: session?.accessToken ?? null,
259
+ accessToken,
232
260
  });
233
261
  shellui.sendMessage({
234
262
  type: 'SHELLUI_SETTINGS',
@@ -237,7 +265,24 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
237
265
  });
238
266
  }
239
267
  },
240
- [config, isTrustedFrameForAuthToken, session?.accessToken],
268
+ [config, isTrustedFrameForAuthToken],
269
+ );
270
+
271
+ const pushSettingsToFrame = useCallback(
272
+ (iframeUuid: string, frameSrc: string, baseSettings: Settings) => {
273
+ const lang = baseSettings.language?.code || 'en';
274
+ const includeAuthAccessToken = isTrustedFrameForAuthToken(frameSrc);
275
+ const settingsToPropagate = buildSettingsForPropagation(baseSettings, config, lang, {
276
+ includeAuthAccessToken,
277
+ accessToken: accessTokenRef.current,
278
+ });
279
+ shellui.sendMessage({
280
+ type: 'SHELLUI_SETTINGS',
281
+ payload: { settings: settingsToPropagate },
282
+ to: [iframeUuid],
283
+ });
284
+ },
285
+ [config, isTrustedFrameForAuthToken],
241
286
  );
242
287
 
243
288
  // When the shell rotates the JWT, `authUser` often does not change, so the user-sync effect
@@ -431,7 +476,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
431
476
  : false;
432
477
  const settingsToPropagate = buildSettingsForPropagation(currentSettings, config, lang, {
433
478
  includeAuthAccessToken,
434
- accessToken: session?.accessToken ?? null,
479
+ accessToken: accessTokenRef.current,
435
480
  });
436
481
 
437
482
  // Route through the full parent -> child -> ... -> requester path so deep descendants
@@ -469,12 +514,32 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
469
514
  },
470
515
  );
471
516
 
517
+ // After an iframe finishes SDK init, re-push current settings (incl. rotated JWT).
518
+ // Covers races where the frame registered after a refresh broadcast, or remounted.
519
+ const cleanupInitialized = shellui.addMessageListener(
520
+ 'SHELLUI_INITIALIZED',
521
+ (_message: ShellUIMessage, event: MessageEvent) => {
522
+ if (typeof window === 'undefined' || window.parent !== window) {
523
+ return;
524
+ }
525
+ const source = event.source;
526
+ if (!source) return;
527
+ const match = shellui.frameRegistry
528
+ .getAllIframes()
529
+ .find(([, iframe]) => iframe?.contentWindow === source);
530
+ if (!match) return;
531
+ const [iframeUuid, iframe] = match;
532
+ pushSettingsToFrame(iframeUuid, iframe?.src ?? '', settingsRef.current ?? defaultSettings);
533
+ },
534
+ );
535
+
472
536
  return () => {
473
537
  cleanup();
474
538
  cleanupSettings();
475
539
  cleanupSettingsRequested();
540
+ cleanupInitialized();
476
541
  };
477
- }, [config, isTrustedFrameForAuthToken, propagateSettingsToIframes, session?.accessToken]);
542
+ }, [config, isTrustedFrameForAuthToken, propagateSettingsToIframes, pushSettingsToFrame]);
478
543
 
479
544
  useEffect(() => {
480
545
  if (
@@ -7,6 +7,7 @@ import {
7
7
  FileTextIcon,
8
8
  PackageIcon,
9
9
  RefreshDoubleIcon,
10
+ HardDriveIcon,
10
11
  } from './SettingsIcons';
11
12
  import { Appearance } from './components/Appearance';
12
13
  import { LanguageAndRegion } from './components/LanguageAndRegion';
@@ -16,6 +17,7 @@ import { Develop } from './components/Develop';
16
17
  import { DataPrivacy } from './components/DataPrivacy';
17
18
  import { ServiceWorker } from './components/ServiceWorker';
18
19
  import { LegalDocumentsPanel } from './components/LegalDocumentsPanel';
20
+ import { Storage } from './components/Storage';
19
21
  import { isTauri } from '../../service-worker/register';
20
22
 
21
23
  export const createSettingsRoutes = (t: (key: string) => string) => [
@@ -31,6 +33,18 @@ export const createSettingsRoutes = (t: (key: string) => string) => [
31
33
  path: 'language-and-region',
32
34
  element: <LanguageAndRegion />,
33
35
  },
36
+ {
37
+ name: t('routes.dataPrivacy'),
38
+ icon: ShieldIcon,
39
+ path: 'data-privacy',
40
+ element: <DataPrivacy />,
41
+ },
42
+ {
43
+ name: t('routes.storage'),
44
+ icon: HardDriveIcon,
45
+ path: 'storage',
46
+ element: <Storage />,
47
+ },
34
48
  {
35
49
  name: t('routes.updateApp'),
36
50
  icon: RefreshDoubleIcon,
@@ -43,12 +57,6 @@ export const createSettingsRoutes = (t: (key: string) => string) => [
43
57
  path: 'advanced',
44
58
  element: <Advanced />,
45
59
  },
46
- {
47
- name: t('routes.dataPrivacy'),
48
- icon: ShieldIcon,
49
- path: 'data-privacy',
50
- element: <DataPrivacy />,
51
- },
52
60
  {
53
61
  name: t('routes.legalDocuments'),
54
62
  icon: FileTextIcon,
@@ -32,13 +32,14 @@ import type { NavigationItem } from '../config/types';
32
32
  import { cn } from '../../lib/utils';
33
33
  import { useAuth } from '../auth/hooks/useAuth';
34
34
  import { getLegalDocuments } from '../legal/legalDocuments';
35
+ import { isStorageSettingsEnabled } from '../storage/quota';
35
36
 
36
37
  export const SettingsView = () => {
37
38
  const location = useLocation();
38
39
  const navigate = useNavigate();
39
40
  const { settings } = useSettings();
40
41
  const { config } = useConfig();
41
- const { user, session, logout } = useAuth();
42
+ const { user, session, logout, isAuthenticated } = useAuth();
42
43
  const { t, i18n } = useTranslation('settings');
43
44
  // Re-check isTauri after mount and after a short delay so we catch late-injected __TAURI__ in dev
44
45
  const [isTauriEnv, setIsTauriEnv] = useState(() => isTauri());
@@ -78,11 +79,15 @@ export const SettingsView = () => {
78
79
  }, [settings.developerFeatures.enabled, routesWithoutTauriSw]);
79
80
 
80
81
  const settingsNavRoutes = useMemo(() => {
81
- if (getLegalDocuments(config).length > 0) {
82
- return filteredRoutes;
82
+ let routes = filteredRoutes;
83
+ if (getLegalDocuments(config).length === 0) {
84
+ routes = routes.filter((route) => route.path !== 'legal-documents');
83
85
  }
84
- return filteredRoutes.filter((route) => route.path !== 'legal-documents');
85
- }, [filteredRoutes, config]);
86
+ if (!isStorageSettingsEnabled(config) || !isAuthenticated) {
87
+ routes = routes.filter((route) => route.path !== 'storage');
88
+ }
89
+ return routes;
90
+ }, [filteredRoutes, config, isAuthenticated]);
86
91
 
87
92
  // Application settings from navigation items with settings URL
88
93
  const applicationRoutes = useMemo(() => {
@@ -150,6 +155,7 @@ export const SettingsView = () => {
150
155
  ['appearance', 'language-and-region', 'data-privacy'].includes(route.path),
151
156
  ),
152
157
  ...userRoute,
158
+ ...settingsNavRoutes.filter((route) => route.path === 'storage'),
153
159
  ],
154
160
  },
155
161
  {