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
Binary file added src/lib/assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/lib/assets/favicon.svg

This file was deleted.

Binary file added src/lib/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/lib/components/OfflinePill.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<div
class={cn(
'pointer-events-none fixed inset-x-0 top-0 z-20 flex justify-center pt-[env(safe-area-inset-top)] transition-[translate,opacity] duration-300 ease-out',
'pointer-events-none fixed inset-x-0 top-0 z-20 flex justify-center pt-[calc(env(safe-area-inset-top)+var(--web-header-height))] transition-[translate,opacity] duration-300 ease-out',
!liveDataManager.isOffline && '-translate-y-full opacity-0',
)}
aria-hidden={!liveDataManager.isOffline}
Expand Down
25 changes: 25 additions & 0 deletions src/lib/components/WebHeader.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script lang="ts">
import logo from '$lib/assets/logo.png';
import Button from '$lib/components/ui/button/button.svelte';
import { detectStorePlatform, storeUrl } from '$lib/utils/app-store';
import { Download } from '@lucide/svelte';

const storePlatform = detectStorePlatform(navigator.userAgent, navigator.maxTouchPoints);
</script>

<header
data-web-header
class="fixed inset-x-0 top-0 z-20 flex h-(--web-header-height) items-center justify-between border-b bg-background px-4 dark:bg-card"
>
<div class="flex items-center gap-2">
<img src={logo} alt="" class="size-8 rounded-lg" />
<span class="text-lg font-semibold">Maroon Rides</span>
</div>

{#if storePlatform}
<Button href={storeUrl(storePlatform)} class="rounded-full" size="sm">
<Download />
Get the App
</Button>
{/if}
</header>
4 changes: 2 additions & 2 deletions src/lib/components/ui/map/MapControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
const loaded = $derived(mapCtx.isLoaded());

const positionClasses = {
'top-left': 'top-[calc(env(safe-area-inset-top)+8px)] left-2',
'top-right': 'top-[calc(env(safe-area-inset-top)+8px)] right-2',
'top-left': 'top-[calc(env(safe-area-inset-top)+var(--web-header-height)+8px)] left-2',
'top-right': 'top-[calc(env(safe-area-inset-top)+var(--web-header-height)+8px)] right-2',
'bottom-left': 'bottom-2 left-2',
'bottom-right': 'bottom-10 right-2',
};
Expand Down
30 changes: 30 additions & 0 deletions src/lib/utils/app-store.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, expect, it } from 'vitest';
import { detectStorePlatform, StorePlatform } from './app-store';

const IPHONE =
'Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1';
const ANDROID =
'Mozilla/5.0 (Linux; Android 15; Pixel 9) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Mobile Safari/537.36';
const MAC =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15';
const WINDOWS =
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36';

describe('detectStorePlatform', () => {
it('sends iPhones to the App Store', () => {
expect(detectStorePlatform(IPHONE, 5)).toBe(StorePlatform.IOS);
});

it('sends Android phones to the Play Store', () => {
expect(detectStorePlatform(ANDROID, 5)).toBe(StorePlatform.ANDROID);
});

it('treats a touch-capable Mac user agent as an iPad', () => {
expect(detectStorePlatform(MAC, 5)).toBe(StorePlatform.IOS);
});

it('has no store for desktop browsers', () => {
expect(detectStorePlatform(MAC, 0)).toBeNull();
expect(detectStorePlatform(WINDOWS, 0)).toBeNull();
});
});
29 changes: 29 additions & 0 deletions src/lib/utils/app-store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export enum StorePlatform {
IOS = 'ios',
ANDROID = 'android',
}

const STORE_URLS: Record<StorePlatform, string> = {
[StorePlatform.IOS]: 'https://apps.apple.com/app/id6475358068',
[StorePlatform.ANDROID]:
'https://play.google.com/store/apps/details?id=com.maroonrides.maroonrides',
};

const IOS_USER_AGENT = /iPhone|iPad|iPod/;
const ANDROID_USER_AGENT = /Android/;
const MAC_USER_AGENT = /Macintosh/;

export function storeUrl(platform: StorePlatform): string {
return STORE_URLS[platform];
}

// iPadOS Safari reports itself as a Mac, so touch support is what tells them apart.
export function detectStorePlatform(
userAgent: string,
maxTouchPoints: number,
): StorePlatform | null {
if (ANDROID_USER_AGENT.test(userAgent)) return StorePlatform.ANDROID;
if (IOS_USER_AGENT.test(userAgent)) return StorePlatform.IOS;
if (MAC_USER_AGENT.test(userAgent) && maxTouchPoints > 1) return StorePlatform.IOS;
return null;
}
9 changes: 4 additions & 5 deletions src/lib/utils/app-version.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { AppLauncher } from '@capacitor/app-launcher';
import { Capacitor } from '@capacitor/core';
import semver from 'semver';
import { StorePlatform, storeUrl } from './app-store';

export const APP_VERSION = __APP_VERSION__;

const APP_STORE_URL = 'https://apps.apple.com/app/id6475358068';
const PLAY_STORE_URL = 'https://play.google.com/store/apps/details?id=com.maroonrides.maroonrides';

export function isAppVersionSupported(minimumVersion: string): boolean {
return semver.gte(APP_VERSION, minimumVersion);
}

export async function openAppStore() {
const url = Capacitor.getPlatform() === 'android' ? PLAY_STORE_URL : APP_STORE_URL;
await AppLauncher.openUrl({ url });
const platform =
Capacitor.getPlatform() === StorePlatform.ANDROID ? StorePlatform.ANDROID : StorePlatform.IOS;
await AppLauncher.openUrl({ url: storeUrl(platform) });
}
8 changes: 7 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
import favicon from '$lib/assets/favicon.svg';
import favicon from '$lib/assets/favicon.png';
import MapElements from '$lib/components/map/MapElements.svelte';
import PlanMapElements from '$lib/components/map/PlanMapElements.svelte';
import OfflinePill from '$lib/components/OfflinePill.svelte';
import UpdateRequired from '$lib/components/UpdateRequired.svelte';
import WebHeader from '$lib/components/WebHeader.svelte';
import Map from '$lib/components/ui/map/Map.svelte';
import MapControls from '$lib/components/ui/map/MapControls.svelte';
import { frontPageManager } from '$lib/managers/frontpage.manager.svelte';
Expand All @@ -13,6 +14,7 @@
import { installDynamicType } from '$lib/utils/dynamic-type';
import { migratePrefs } from '$lib/utils/prefs';
import { queryClient } from '$lib/utils/queries';
import { Capacitor } from '@capacitor/core';
import { QueryClientProvider } from '@tanstack/svelte-query';
import { page } from '$app/state';
import { ModeWatcher } from 'mode-watcher';
Expand Down Expand Up @@ -71,6 +73,10 @@
</div>
</QueryClientProvider>

{#if !Capacitor.isNativePlatform()}
<WebHeader />
{/if}

<OfflinePill />

{#if syncManager.versionStatus === VersionStatus.UNSUPPORTED}
Expand Down
5 changes: 5 additions & 0 deletions src/routes/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
--spacing: 4px;
}

:root:has([data-web-header]) {
--web-header-height: 56px;
}

:root {
--web-header-height: 0px;
--dynamic-type-scale: 1;
font-size: calc(1rem * var(--dynamic-type-scale));

Expand Down
Loading