forked from RSSNext/Follow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
158 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { callWindowExpose } from "@follow/shared/bridge" | ||
import { DEEPLINK_SCHEME } from "@follow/shared/constants" | ||
import { extractElectronWindowOptions } from "@follow/shared/electron" | ||
|
||
import { logger } from "~/logger" | ||
import { createMainWindow, createWindow, getMainWindow } from "~/window" | ||
|
||
export const handleUrlRouting = (url: string) => { | ||
const options = extractElectronWindowOptions(url) | ||
|
||
const uri = url.replace(DEEPLINK_SCHEME, "/") | ||
try { | ||
const { pathname, searchParams } = new URL(uri, "https://follow.dev") | ||
|
||
switch (pathname) { | ||
case "/add": { | ||
const mainWindow = getMainWindow() | ||
if (!mainWindow) { | ||
createMainWindow() | ||
|
||
return handleUrlRouting(url) | ||
} | ||
mainWindow.restore() | ||
mainWindow.focus() | ||
const caller = callWindowExpose(mainWindow) | ||
|
||
const id = searchParams.get("id") | ||
const isList = searchParams.get("type") === "list" | ||
if (!id) return | ||
caller.follow(id, { isList }) | ||
return | ||
} | ||
default: { | ||
break | ||
} | ||
} | ||
|
||
return | ||
} catch (err) { | ||
logger.error("routing error:", err) | ||
} | ||
const { height, resizable = true, width } = options || {} | ||
createWindow({ | ||
extraPath: `#${uri}`, | ||
width: width ?? 800, | ||
height: height ?? 700, | ||
minWidth: 600, | ||
minHeight: 600, | ||
resizable, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { registerGlobalContext } from "@follow/shared/bridge" | ||
import { useEffect, useLayoutEffect } from "react" | ||
import { useTranslation } from "react-i18next" | ||
import { toast } from "sonner" | ||
|
||
import { getGeneralSettings } from "~/atoms/settings/general" | ||
import { getUISettings } from "~/atoms/settings/ui" | ||
import { useModalStack } from "~/components/ui/modal" | ||
import { FeedForm } from "~/modules/discover/feed-form" | ||
|
||
import { ElectronCloseEvent, ElectronShowEvent } from "./invalidate-query-provider" | ||
|
||
export const ExtensionExposeProvider = () => { | ||
const { present } = useModalStack() | ||
useLayoutEffect(() => { | ||
registerGlobalContext({ | ||
showSetting: (path) => window.router.showSettings(path), | ||
getGeneralSettings, | ||
getUISettings, | ||
/** | ||
* Electron app only | ||
*/ | ||
onWindowClose() { | ||
document.dispatchEvent(new ElectronCloseEvent()) | ||
}, | ||
onWindowShow() { | ||
document.dispatchEvent(new ElectronShowEvent()) | ||
}, | ||
|
||
toast, | ||
}) | ||
}, []) | ||
|
||
const { t } = useTranslation() | ||
useEffect(() => { | ||
registerGlobalContext({ | ||
follow(id, options) { | ||
present({ | ||
title: options?.isList | ||
? t("sidebar.feed_actions.edit_list") | ||
: t("sidebar.feed_actions.edit_feed"), | ||
content: ({ dismiss }) => ( | ||
<FeedForm asWidget id={id} onSuccess={dismiss} isList={options?.isList} /> | ||
), | ||
}) | ||
}, | ||
}) | ||
}, [present, t]) | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters