Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions hyperdrive/packages/homepage/ui/src/components/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ export default function Home() {
// try to automatically open it
useEffect(() => {
if (window?.location?.hash?.startsWith('#app-')) {
// could be a path on the hash, or a query. delete them
let appNameToOpen = window.location.hash.replace('#app-', '')
.replace(/\?.*/, '')
.replace(/\/.*/, '');
const hashWithoutPrefix = window.location.hash.replace('#app-', '');
// Extract app name (everything before first / or ?)
const appNameMatch = hashWithoutPrefix.match(/^([^/?]+)/);
const appNameToOpen = appNameMatch ? appNameMatch[1] : '';
// Capture path/query (everything after the app name)
const remainder = hashWithoutPrefix.slice(appNameToOpen.length);
const appToOpen = apps?.find(app => app?.id === appNameToOpen);
console.log('found window hash. attempting open', { hash: window.location.hash, appNameToOpen, appToOpen });
console.log('found window hash. attempting open', { hash: window.location.hash, appNameToOpen, remainder, appToOpen });
if (appToOpen) {
openApp(appToOpen)
openApp(appToOpen, remainder || undefined)
}
}
}, [apps, window.location]);
Expand Down
16 changes: 11 additions & 5 deletions hyperdrive/packages/homepage/ui/src/stores/navigationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,18 @@ export const useNavigationStore = create<NavigationStore>((set, get) => ({
return;
}

// Normalize query to avoid double slashes
let normalizedQuery = query || '';
if (normalizedQuery.startsWith('/') && app.path.endsWith('/')) {
normalizedQuery = normalizedQuery.slice(1);
}

// Check if we need to open in a new tab (localhost)
const isLocalhost = window.location.host.includes("localhost");
if (isLocalhost) {
console.log('[homepage] opening app in new tab:', { app });
// don't use secure subdomain for localhost
const path = app.path.replace(/^(https?:\/\/)(.*)localhost/, '$1localhost') + (query || '');
const path = app.path.replace(/^(https?:\/\/)(.*)localhost/, '$1localhost') + normalizedQuery;
console.log({ path })
window.open(path, '_blank');
set({ isAppDrawerOpen: false, isRecentAppsOpen: false });
Expand All @@ -100,7 +106,7 @@ export const useNavigationStore = create<NavigationStore>((set, get) => ({

let maybeSlash = '';

if (query && query[0] && query[0] !== '?' && query[0] !== '/') {
if (normalizedQuery && normalizedQuery[0] !== '?' && normalizedQuery[0] !== '/') {
// autoprepend a slash for the window history when the query type is unknown
console.log('autoprepended / to unknown query format');
maybeSlash = '/'
Expand All @@ -110,13 +116,13 @@ export const useNavigationStore = create<NavigationStore>((set, get) => ({
window?.history?.pushState(
{ type: 'app', appId: app.id, previousAppId: currentAppId },
'',
`#app-${app.id}${maybeSlash}${query || ''}`
`#app-${app.id}${maybeSlash}${normalizedQuery}`
);

if (existingApp) {
set({
runningApps: runningApps.map(rApp => {
const path = `${app.path}${query || ''}`;
const path = `${app.path}${normalizedQuery}`;
console.log(path, rApp.id, app.id);
if (rApp.id === app.id) {
console.log('found rApp')
Expand All @@ -135,7 +141,7 @@ export const useNavigationStore = create<NavigationStore>((set, get) => ({
set({
runningApps: [...runningApps, {
...app,
path: `${app.path}${query || ''}`,
path: `${app.path}${normalizedQuery}`,
openedAt: Date.now()
}],
currentAppId: app.id,
Expand Down