@shellui/core 0.3.0 → 0.3.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.
- package/package.json +2 -2
- package/src/app.tsx +20 -2
- package/src/features/admin/AdminView.tsx +6 -31
- package/src/features/admin/config.ts +15 -0
- package/src/features/admin/index.ts +4 -0
- package/src/features/admin/routes.tsx +14 -0
- package/src/features/admin/utils.ts +79 -0
- package/src/features/auth/components/LoginButton.tsx +5 -10
- package/src/features/auth/components/LoginView.tsx +3 -2
- package/src/features/auth/components/OAuthCallbackView.tsx +2 -4
- package/src/features/auth/utils/buildAuthUrlWithNext.spec.ts +18 -0
- package/src/features/auth/utils/buildAuthUrlWithNext.ts +12 -0
- package/src/features/auth/utils/index.ts +1 -0
- package/src/features/config/ConfigProvider.ts +1 -1
- package/src/features/config/types.ts +0 -5
- package/src/features/layouts/OverlayShell.tsx +7 -22
- package/src/features/layouts/resolveSdkNavigatePath.spec.ts +55 -0
- package/src/features/layouts/resolveSdkNavigatePath.ts +68 -0
- package/src/features/settings/SettingsProvider.tsx +10 -6
- package/src/features/settings/components/ServiceWorker.tsx +52 -25
- package/src/features/settings/components/UpdateApp.tsx +1 -1
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +1 -1
- package/src/features/settings/utils/mergePreferencesIntoSettings.spec.ts +1 -1
- package/src/features/sonner/SonnerContext.tsx +44 -60
- package/src/i18n/translations/en/settings.json +9 -0
- package/src/i18n/translations/fr/settings.json +9 -0
- package/src/routes/components/NavigationItemRoute.tsx +2 -1
- package/src/routes/routes.tsx +2 -13
- package/src/service-worker/register.ts +214 -90
- package/src/service-worker/sw-dev.ts +5 -1
- package/src/service-worker/sw.ts +5 -1
- package/src/shellui-target.d.ts +2 -0
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
getServiceWorkerStatus,
|
|
9
9
|
addStatusListener,
|
|
10
10
|
serviceWorkerFileExists,
|
|
11
|
+
showUpdateAvailableToastForTesting,
|
|
12
|
+
clearAppCaches,
|
|
13
|
+
reloadApp,
|
|
11
14
|
} from '../../../service-worker/register';
|
|
12
15
|
import { shellui } from '@shellui/sdk';
|
|
13
16
|
import { useState, useEffect } from 'react';
|
|
@@ -20,7 +23,7 @@ export const ServiceWorker = () => {
|
|
|
20
23
|
const [isLoading, setIsLoading] = useState(true);
|
|
21
24
|
const [swFileExists, setSwFileExists] = useState(true); // Track if service worker file exists
|
|
22
25
|
|
|
23
|
-
const serviceWorkerEnabled = settings?.serviceWorker?.enabled ??
|
|
26
|
+
const serviceWorkerEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
24
27
|
|
|
25
28
|
useEffect(() => {
|
|
26
29
|
// Don't check service worker status if disabled
|
|
@@ -36,7 +39,7 @@ export const ServiceWorker = () => {
|
|
|
36
39
|
// Initial check with loading state
|
|
37
40
|
const initialCheck = async () => {
|
|
38
41
|
// Double-check service worker is still enabled before proceeding
|
|
39
|
-
const stillEnabled = settings?.serviceWorker?.enabled ??
|
|
42
|
+
const stillEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
40
43
|
if (!stillEnabled) {
|
|
41
44
|
setIsLoading(false);
|
|
42
45
|
return;
|
|
@@ -48,7 +51,7 @@ export const ServiceWorker = () => {
|
|
|
48
51
|
const exists = await serviceWorkerFileExists();
|
|
49
52
|
|
|
50
53
|
// Check again if service worker was disabled during the async operation
|
|
51
|
-
const currentEnabled = settings?.serviceWorker?.enabled ??
|
|
54
|
+
const currentEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
52
55
|
if (!currentEnabled) {
|
|
53
56
|
setIsLoading(false);
|
|
54
57
|
return;
|
|
@@ -61,7 +64,7 @@ export const ServiceWorker = () => {
|
|
|
61
64
|
const status = await getServiceWorkerStatus();
|
|
62
65
|
|
|
63
66
|
// Final check before updating state
|
|
64
|
-
const finalCheck = settings?.serviceWorker?.enabled ??
|
|
67
|
+
const finalCheck = settings?.serviceWorker?.enabled ?? false;
|
|
65
68
|
if (finalCheck) {
|
|
66
69
|
setIsRegistered(status.registered);
|
|
67
70
|
setUpdateAvailable(status.updateAvailable);
|
|
@@ -69,7 +72,7 @@ export const ServiceWorker = () => {
|
|
|
69
72
|
} else {
|
|
70
73
|
// File doesn't exist, so service worker can't be registered
|
|
71
74
|
// Only update if service worker is still enabled
|
|
72
|
-
const finalCheck = settings?.serviceWorker?.enabled ??
|
|
75
|
+
const finalCheck = settings?.serviceWorker?.enabled ?? false;
|
|
73
76
|
if (finalCheck) {
|
|
74
77
|
setIsRegistered(false);
|
|
75
78
|
setUpdateAvailable(false);
|
|
@@ -82,7 +85,7 @@ export const ServiceWorker = () => {
|
|
|
82
85
|
// Background refresh without affecting loading state
|
|
83
86
|
const refreshStatus = async () => {
|
|
84
87
|
// Skip if service worker was disabled (check current setting value)
|
|
85
|
-
const currentEnabled = settings?.serviceWorker?.enabled ??
|
|
88
|
+
const currentEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
86
89
|
if (!currentEnabled) {
|
|
87
90
|
return;
|
|
88
91
|
}
|
|
@@ -91,7 +94,7 @@ export const ServiceWorker = () => {
|
|
|
91
94
|
const exists = await serviceWorkerFileExists();
|
|
92
95
|
|
|
93
96
|
// Check again if service worker was disabled during the async operation
|
|
94
|
-
const currentEnabledAfter = settings?.serviceWorker?.enabled ??
|
|
97
|
+
const currentEnabledAfter = settings?.serviceWorker?.enabled ?? false;
|
|
95
98
|
if (!currentEnabledAfter) {
|
|
96
99
|
return;
|
|
97
100
|
}
|
|
@@ -103,7 +106,7 @@ export const ServiceWorker = () => {
|
|
|
103
106
|
const status = await getServiceWorkerStatus();
|
|
104
107
|
|
|
105
108
|
// Final check before updating state
|
|
106
|
-
const finalCheck = settings?.serviceWorker?.enabled ??
|
|
109
|
+
const finalCheck = settings?.serviceWorker?.enabled ?? false;
|
|
107
110
|
if (finalCheck) {
|
|
108
111
|
setIsRegistered(status.registered);
|
|
109
112
|
setUpdateAvailable(status.updateAvailable);
|
|
@@ -111,7 +114,7 @@ export const ServiceWorker = () => {
|
|
|
111
114
|
} else {
|
|
112
115
|
// File doesn't exist, so service worker can't be registered
|
|
113
116
|
// Only update if service worker is still enabled
|
|
114
|
-
const finalCheck = settings?.serviceWorker?.enabled ??
|
|
117
|
+
const finalCheck = settings?.serviceWorker?.enabled ?? false;
|
|
115
118
|
if (finalCheck) {
|
|
116
119
|
setIsRegistered(false);
|
|
117
120
|
setUpdateAvailable(false);
|
|
@@ -125,7 +128,7 @@ export const ServiceWorker = () => {
|
|
|
125
128
|
// Listen for status changes
|
|
126
129
|
const unsubscribe = addStatusListener((status) => {
|
|
127
130
|
// Only update if service worker is still enabled (check current setting value)
|
|
128
|
-
const currentEnabled = settings?.serviceWorker?.enabled ??
|
|
131
|
+
const currentEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
129
132
|
if (currentEnabled) {
|
|
130
133
|
setIsRegistered(status.registered);
|
|
131
134
|
setUpdateAvailable(status.updateAvailable);
|
|
@@ -161,7 +164,7 @@ export const ServiceWorker = () => {
|
|
|
161
164
|
// Give it a moment to register/unregister
|
|
162
165
|
setTimeout(async () => {
|
|
163
166
|
// Double-check service worker is still enabled before updating state
|
|
164
|
-
const currentEnabled = settings?.serviceWorker?.enabled ??
|
|
167
|
+
const currentEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
165
168
|
if (enabled && currentEnabled) {
|
|
166
169
|
const registered = await isServiceWorkerRegistered();
|
|
167
170
|
setIsRegistered(registered);
|
|
@@ -183,13 +186,21 @@ export const ServiceWorker = () => {
|
|
|
183
186
|
}
|
|
184
187
|
};
|
|
185
188
|
|
|
189
|
+
const handleShowUpdateModal = async () => {
|
|
190
|
+
try {
|
|
191
|
+
await showUpdateAvailableToastForTesting();
|
|
192
|
+
} catch (_error) {
|
|
193
|
+
shellui.toast({
|
|
194
|
+
title: t('caching.testing.error.title'),
|
|
195
|
+
description: t('caching.testing.error.description'),
|
|
196
|
+
type: 'error',
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
186
201
|
const handleResetToLatest = async () => {
|
|
187
202
|
try {
|
|
188
|
-
|
|
189
|
-
if ('caches' in window) {
|
|
190
|
-
const cacheNames = await caches.keys();
|
|
191
|
-
await Promise.all(cacheNames.map((name) => caches.delete(name)));
|
|
192
|
-
}
|
|
203
|
+
await clearAppCaches();
|
|
193
204
|
|
|
194
205
|
shellui.toast({
|
|
195
206
|
title: t('caching.resetSuccess.title'),
|
|
@@ -197,16 +208,8 @@ export const ServiceWorker = () => {
|
|
|
197
208
|
type: 'success',
|
|
198
209
|
});
|
|
199
210
|
|
|
200
|
-
// Reload the app using shellUI refresh message (refreshes entire app, not just iframe)
|
|
201
211
|
setTimeout(() => {
|
|
202
|
-
|
|
203
|
-
type: 'SHELLUI_REFRESH_PAGE',
|
|
204
|
-
payload: {},
|
|
205
|
-
});
|
|
206
|
-
if (!sent) {
|
|
207
|
-
// Fallback to window.location.reload if message can't be sent
|
|
208
|
-
window.location.reload();
|
|
209
|
-
}
|
|
212
|
+
reloadApp();
|
|
210
213
|
}, 1000);
|
|
211
214
|
} catch (_error) {
|
|
212
215
|
shellui.toast({
|
|
@@ -354,6 +357,30 @@ export const ServiceWorker = () => {
|
|
|
354
357
|
</Button>
|
|
355
358
|
</div>
|
|
356
359
|
</div>
|
|
360
|
+
|
|
361
|
+
{/* Developer testing */}
|
|
362
|
+
<div className="space-y-2">
|
|
363
|
+
<div className="space-y-0.5">
|
|
364
|
+
<label
|
|
365
|
+
className="text-sm font-medium leading-none"
|
|
366
|
+
style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
367
|
+
>
|
|
368
|
+
{t('caching.testing.title')}
|
|
369
|
+
</label>
|
|
370
|
+
<p className="text-sm text-muted-foreground">
|
|
371
|
+
{t('caching.testing.description')}
|
|
372
|
+
</p>
|
|
373
|
+
</div>
|
|
374
|
+
<div className="mt-2">
|
|
375
|
+
<Button
|
|
376
|
+
variant="outline"
|
|
377
|
+
onClick={handleShowUpdateModal}
|
|
378
|
+
className="w-full sm:w-auto"
|
|
379
|
+
>
|
|
380
|
+
{t('caching.testing.button')}
|
|
381
|
+
</Button>
|
|
382
|
+
</div>
|
|
383
|
+
</div>
|
|
357
384
|
</>
|
|
358
385
|
)}
|
|
359
386
|
</div>
|
|
@@ -24,7 +24,7 @@ export const UpdateApp = () => {
|
|
|
24
24
|
const [showUpToDateInButton, setShowUpToDateInButton] = useState(false);
|
|
25
25
|
const [checkError, setCheckError] = useState(false);
|
|
26
26
|
|
|
27
|
-
const serviceWorkerEnabled = settings?.serviceWorker?.enabled ??
|
|
27
|
+
const serviceWorkerEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
28
28
|
|
|
29
29
|
useEffect(() => {
|
|
30
30
|
if (isTauri()) return;
|
|
@@ -45,6 +45,34 @@ interface SonnerProviderProps {
|
|
|
45
45
|
children: ReactNode;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/** Root-window toasts store callbacks locally; iframe toasts route via postMessage. */
|
|
49
|
+
function createToastButtonHandler(
|
|
50
|
+
toastId: string | undefined,
|
|
51
|
+
from: string[] | undefined,
|
|
52
|
+
kind: 'action' | 'cancel',
|
|
53
|
+
): (() => void) | undefined {
|
|
54
|
+
if (!toastId) return undefined;
|
|
55
|
+
let sent = false;
|
|
56
|
+
return () => {
|
|
57
|
+
if (sent) return;
|
|
58
|
+
sent = true;
|
|
59
|
+
if (!from?.length) {
|
|
60
|
+
if (kind === 'action') {
|
|
61
|
+
shellui.callbackRegistry.triggerAction(toastId);
|
|
62
|
+
} else {
|
|
63
|
+
shellui.callbackRegistry.triggerCancel(toastId);
|
|
64
|
+
}
|
|
65
|
+
shellui.callbackRegistry.clear(toastId);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
shellui.sendMessage({
|
|
69
|
+
type: kind === 'action' ? 'SHELLUI_TOAST_ACTION' : 'SHELLUI_TOAST_CANCEL',
|
|
70
|
+
payload: { id: toastId },
|
|
71
|
+
to: from,
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
48
76
|
export const SonnerProvider = ({ children }: SonnerProviderProps) => {
|
|
49
77
|
const toast = useCallback((options: ToastOptions) => {
|
|
50
78
|
const {
|
|
@@ -192,38 +220,16 @@ export const SonnerProvider = ({ children }: SonnerProviderProps) => {
|
|
|
192
220
|
},
|
|
193
221
|
action:
|
|
194
222
|
payload.action &&
|
|
195
|
-
(() => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
onClick: () => {
|
|
200
|
-
if (actionSent) return;
|
|
201
|
-
actionSent = true;
|
|
202
|
-
shellui.sendMessage({
|
|
203
|
-
type: 'SHELLUI_TOAST_ACTION',
|
|
204
|
-
payload: { id: payload.id },
|
|
205
|
-
to: data.from,
|
|
206
|
-
});
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
})(),
|
|
223
|
+
(() => ({
|
|
224
|
+
label: payload.action?.label ?? undefined,
|
|
225
|
+
onClick: createToastButtonHandler(payload.id, data.from, 'action') ?? (() => {}),
|
|
226
|
+
}))(),
|
|
210
227
|
cancel:
|
|
211
228
|
payload.cancel &&
|
|
212
|
-
(() => {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
onClick: () => {
|
|
217
|
-
if (cancelSent) return;
|
|
218
|
-
cancelSent = true;
|
|
219
|
-
shellui.sendMessage({
|
|
220
|
-
type: 'SHELLUI_TOAST_CANCEL',
|
|
221
|
-
payload: { id: payload.id },
|
|
222
|
-
to: data.from,
|
|
223
|
-
});
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
})(),
|
|
229
|
+
(() => ({
|
|
230
|
+
label: payload.cancel?.label ?? undefined,
|
|
231
|
+
onClick: createToastButtonHandler(payload.id, data.from, 'cancel') ?? (() => {}),
|
|
232
|
+
}))(),
|
|
227
233
|
});
|
|
228
234
|
});
|
|
229
235
|
|
|
@@ -240,38 +246,16 @@ export const SonnerProvider = ({ children }: SonnerProviderProps) => {
|
|
|
240
246
|
// These handlers send messages that trigger the callbackRegistry
|
|
241
247
|
action:
|
|
242
248
|
payload.action &&
|
|
243
|
-
(() => {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
onClick: () => {
|
|
248
|
-
if (actionSent) return;
|
|
249
|
-
actionSent = true;
|
|
250
|
-
shellui.sendMessage({
|
|
251
|
-
type: 'SHELLUI_TOAST_ACTION',
|
|
252
|
-
payload: { id: payload.id },
|
|
253
|
-
to: data.from,
|
|
254
|
-
});
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
})(),
|
|
249
|
+
(() => ({
|
|
250
|
+
label: payload.action?.label ?? undefined,
|
|
251
|
+
onClick: createToastButtonHandler(payload.id, data.from, 'action') ?? (() => {}),
|
|
252
|
+
}))(),
|
|
258
253
|
cancel:
|
|
259
254
|
payload.cancel &&
|
|
260
|
-
(() => {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
onClick: () => {
|
|
265
|
-
if (cancelSent) return;
|
|
266
|
-
cancelSent = true;
|
|
267
|
-
shellui.sendMessage({
|
|
268
|
-
type: 'SHELLUI_TOAST_CANCEL',
|
|
269
|
-
payload: { id: payload.id },
|
|
270
|
-
to: data.from,
|
|
271
|
-
});
|
|
272
|
-
},
|
|
273
|
-
};
|
|
274
|
-
})(),
|
|
255
|
+
(() => ({
|
|
256
|
+
label: payload.cancel?.label ?? undefined,
|
|
257
|
+
onClick: createToastButtonHandler(payload.id, data.from, 'cancel') ?? (() => {}),
|
|
258
|
+
}))(),
|
|
275
259
|
});
|
|
276
260
|
},
|
|
277
261
|
);
|
|
@@ -230,6 +230,15 @@
|
|
|
230
230
|
"resetError": {
|
|
231
231
|
"title": "Reset Failed",
|
|
232
232
|
"description": "Failed to clear cached files. Please try again later."
|
|
233
|
+
},
|
|
234
|
+
"testing": {
|
|
235
|
+
"title": "Test update notification",
|
|
236
|
+
"description": "Show the update notification to verify the Install Now button works.",
|
|
237
|
+
"button": "Show update modal",
|
|
238
|
+
"error": {
|
|
239
|
+
"title": "Test failed",
|
|
240
|
+
"description": "Could not show the update notification. Please try again."
|
|
241
|
+
}
|
|
233
242
|
}
|
|
234
243
|
},
|
|
235
244
|
"develop": {
|
|
@@ -230,6 +230,15 @@
|
|
|
230
230
|
"resetError": {
|
|
231
231
|
"title": "Échec de la réinitialisation",
|
|
232
232
|
"description": "Échec de l'effacement des fichiers mis en cache. Veuillez réessayer plus tard."
|
|
233
|
+
},
|
|
234
|
+
"testing": {
|
|
235
|
+
"title": "Tester la notification de mise à jour",
|
|
236
|
+
"description": "Afficher la notification de mise à jour pour vérifier que le bouton Installer maintenant fonctionne.",
|
|
237
|
+
"button": "Afficher la modale de mise à jour",
|
|
238
|
+
"error": {
|
|
239
|
+
"title": "Échec du test",
|
|
240
|
+
"description": "Impossible d'afficher la notification de mise à jour. Veuillez réessayer."
|
|
241
|
+
}
|
|
233
242
|
}
|
|
234
243
|
},
|
|
235
244
|
"develop": {
|
|
@@ -3,6 +3,7 @@ import { useNavigationItems } from '../hooks/useNavigationItems';
|
|
|
3
3
|
import { NotFoundView } from './NotFoundView';
|
|
4
4
|
import { Navigate, useLocation } from 'react-router';
|
|
5
5
|
import urls from '../../constants/urls';
|
|
6
|
+
import { buildAuthUrlWithNext } from '../../features/auth/utils';
|
|
6
7
|
import { useAuth } from '../../features/auth/hooks/useAuth';
|
|
7
8
|
import { RouteFallback } from './RouteFallback';
|
|
8
9
|
|
|
@@ -30,7 +31,7 @@ export const NavigationItemRoute = () => {
|
|
|
30
31
|
}
|
|
31
32
|
if (!isAuthenticated) {
|
|
32
33
|
const next = `${location.pathname}${location.search}`;
|
|
33
|
-
const loginUrl =
|
|
34
|
+
const loginUrl = buildAuthUrlWithNext(urls.login, next);
|
|
34
35
|
return (
|
|
35
36
|
<Navigate
|
|
36
37
|
to={loginUrl}
|
package/src/routes/routes.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import { RouteErrorBoundary } from './components/RouteErrorBoundary';
|
|
|
5
5
|
import { AppLayout } from '../features/layouts/AppLayout';
|
|
6
6
|
import { flattenNavigationItems } from '../features/layouts/utils';
|
|
7
7
|
import urls from '../constants/urls';
|
|
8
|
+
import { createAdminRoute } from '../features/admin/routes';
|
|
8
9
|
import { RouteFallback } from './components/RouteFallback';
|
|
9
10
|
|
|
10
11
|
// Lazy load route components
|
|
@@ -24,9 +25,6 @@ const OAuthCallbackView = lazy(() =>
|
|
|
24
25
|
default: m.OAuthCallbackView,
|
|
25
26
|
})),
|
|
26
27
|
);
|
|
27
|
-
const AdminView = lazy(() =>
|
|
28
|
-
import('../features/admin/AdminView').then((m) => ({ default: m.AdminView })),
|
|
29
|
-
);
|
|
30
28
|
const LegalDocumentView = lazy(() =>
|
|
31
29
|
import('../features/legal/LegalDocumentView').then((m) => ({ default: m.LegalDocumentView })),
|
|
32
30
|
);
|
|
@@ -46,11 +44,6 @@ const NotFoundView = lazy(() =>
|
|
|
46
44
|
);
|
|
47
45
|
|
|
48
46
|
export const createRoutes = (config: ShellUIConfig): RouteObject[] => {
|
|
49
|
-
const configuredAdminPathname = config.backend?.adminPathname?.trim();
|
|
50
|
-
const adminPath =
|
|
51
|
-
configuredAdminPathname && configuredAdminPathname.startsWith('/')
|
|
52
|
-
? configuredAdminPathname
|
|
53
|
-
: urls.admin;
|
|
54
47
|
const routes: RouteObject[] = [
|
|
55
48
|
{
|
|
56
49
|
path: '/',
|
|
@@ -133,11 +126,7 @@ export const createRoutes = (config: ShellUIConfig): RouteObject[] => {
|
|
|
133
126
|
</Suspense>
|
|
134
127
|
),
|
|
135
128
|
},
|
|
136
|
-
|
|
137
|
-
// Admin route
|
|
138
|
-
path: `${adminPath.replace(/^\//, '')}/*`,
|
|
139
|
-
element: <AdminView />,
|
|
140
|
-
},
|
|
129
|
+
createAdminRoute(config),
|
|
141
130
|
{
|
|
142
131
|
// Catch-all route
|
|
143
132
|
path: '*',
|