Skip to content

Commit

Permalink
255 app installed should handle links (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJustChew authored Apr 15, 2024
2 parents 59350f0 + efad927 commit d72c412
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 2 deletions.
7 changes: 7 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="nthumods.com" />
</intent-filter>
</activity>

<provider
Expand Down
4 changes: 2 additions & 2 deletions capacitor.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const config: CapacitorConfig = {
appName: 'NTHUMods',
webDir: 'fakeout',
server: {
url: process.env.NODE_ENV === 'production' ? 'https://nthumods.com' : 'http://192.168.31.109:3000',
androidScheme: process.env.NODE_ENV === 'production' ? 'https' : 'http',
url: 'https://nthumods.com',
androidScheme: 'https',
},

};
Expand Down
12 changes: 12 additions & 0 deletions public/.well-known/apple-app-site-association
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"applinks": {
"apps": [],
"details": [
{
"appID": "87D52NF2QC.com.nthumods.courseweb",
"paths": ["*"]
}
]
}
}

5 changes: 5 additions & 0 deletions public/.well-known/assetlinks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target" : { "namespace": "android_app", "package_name": "com.nthumods.courseweb",
"sha256_cert_fingerprints": ["4E:9C:0E:DA:DC:44:55:3E:97:73:9C:F3:EF:2E:DA:03:49:5E:52:A1:33:1F:23:D4:08:20:F6:31:8A:27:1A:73"] }
}]
2 changes: 2 additions & 0 deletions src/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Toaster } from '@/components/ui/toaster';
import ReactQuery from '@/components/ReactQuery';

import './globals.css'
import AppUrlListener from '@/components/AppUrlListener';

export const metadata: Metadata = {
title: {
Expand Down Expand Up @@ -120,6 +121,7 @@ export default function RootLayout({
<html lang={params.lang} className={`${theme?.value ?? ''} ${inter.variable} ${noto.variable}`} suppressHydrationWarning>
<body>
{children}
<AppUrlListener/>
<Toaster />
</body>
</html>
Expand Down
24 changes: 24 additions & 0 deletions src/components/AppUrlListener.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use client';
import { useRouter } from "next/navigation";
import { useEffect } from "react";
import { App, URLOpenListenerEvent } from '@capacitor/app';

const AppUrlListener: React.FC<any> = () => {
const router = useRouter();
useEffect(() => {
App.addListener('appUrlOpen', (event: URLOpenListenerEvent) => {
// Example url: https://beerswift.app/tabs/tab2
// slug = /tabs/tab2
const slug = event.url.split('.app').pop();
if (slug) {
router.push(slug);
}
});
}, []);

return <></>;
};

export default AppUrlListener;


0 comments on commit d72c412

Please sign in to comment.