Skip to content

Commit

Permalink
fix: improve protocol handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Dec 31, 2024
1 parent 66f97c0 commit 0a0b39b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions apps/main/src/lib/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { callWindowExpose } from "@follow/shared/bridge"
import { DEEPLINK_SCHEME } from "@follow/shared/constants"
import { extractElectronWindowOptions } from "@follow/shared/electron"
import type { BrowserWindow } from "electron/main"

Expand All @@ -9,7 +8,15 @@ import { createMainWindow, createWindow, getMainWindow } from "~/window"
export const handleUrlRouting = (url: string) => {
const options = extractElectronWindowOptions(url)

const uri = url.replace(DEEPLINK_SCHEME, "/")
// For example, the url is "follow://add?id=123&type=list&url=https://example.com"
const doubleSlash = url.indexOf("://")
if (doubleSlash === -1) {
logger.error("url routing error: no protocol found", url)
return
}
// Remove the protocol
// For example, the uri is "/add?id=123&type=list&url=https://example.com"
const uri = url.slice(doubleSlash + 2)
try {
const { pathname, searchParams } = new URL(uri, "https://follow.dev")

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare const globalThis: {
}

export const APP_PROTOCOL = isDev ? "follow-dev" : "follow"
export const DEEPLINK_SCHEME = `${APP_PROTOCOL}://`
export const DEEPLINK_SCHEME = `${APP_PROTOCOL}://` as const

export const WEB_URL = env.VITE_WEB_URL

Expand Down

0 comments on commit 0a0b39b

Please sign in to comment.