Skip to content

Commit

Permalink
feat: add deeplink to service (#1344)
Browse files Browse the repository at this point in the history
add deeplink to service
  • Loading branch information
SpecialAro authored Sep 3, 2023
1 parent 648f9a1 commit 970738c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/electron/deepLinking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BrowserWindow } from 'electron';
import { protocolClient } from '../environment-remote';

export default function handleDeepLink(
window: BrowserWindow,
Expand All @@ -8,7 +9,7 @@ export default function handleDeepLink(
return;
}

const url = rawUrl.replace('ferdium://', '');
const url = rawUrl.replace(`${protocolClient}://`, '');

// The next line is a workaround after this 71c5237 [chore: Mobx & React-Router upgrade (#406)].
// For some reason, the app won't start until because it's trying to route to './build'.
Expand Down
2 changes: 2 additions & 0 deletions src/environment-remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ export const API_VERSION: string = 'v1';
export const WS_API: string = wsApi;
export const WEBSITE: string = web;
export const TODOS_FRONTEND: string = todos;
// For deeplink protocol: 'ferdium' or 'ferdium-dev' if we want '{DEEPLINK_PROTOCOL_CLIENT}://'
export const protocolClient = isDevMode ? 'ferdium-dev' : 'ferdium';
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
isDevMode,
userDataRecipesPath,
userDataPath,
protocolClient,
} from './environment-remote';
import { ifUndefined } from './jsUtils';

Expand Down Expand Up @@ -469,7 +470,6 @@ app.on('ready', () => {
enforceMacOSAppLocation();

// Register App URL
const protocolClient = isDevMode ? 'ferdium-dev' : 'ferdium';
if (!app.isDefaultProtocolClient(protocolClient, process.execPath)) {
app.setAsDefaultProtocolClient(protocolClient, process.execPath);
}
Expand Down
14 changes: 14 additions & 0 deletions src/stores/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ export default class AppStore extends TypedStore {
url = url.replace(/\/$/, '');
url = url.replace(/\s?--(updated)/, '');

if (url.startsWith('service/')) {
const pattern = /service\/([^/]+)/;
// Use the exec method to extract the id from the URL
const match = pattern.exec(url);

if (match) {
const id = match[1]; // The id is captured in the first capture group
this.actions.service.setActive({
serviceId: id,
});
}
return;
}

this.stores.router.push(url);
});

Expand Down

0 comments on commit 970738c

Please sign in to comment.