Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test capacitorjs #1887

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ vite.config.*.mjs

apps/renderer/dev-dist
tsconfig.tsbuildinfo

ios
android
28 changes: 28 additions & 0 deletions apps/renderer/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type { URLOpenListenerEvent } from "@capacitor/app"
import { App as CapacitorApp } from "@capacitor/app"
import { CapacitorHttp } from "@capacitor/core"
import { isMobile } from "@follow/components/hooks/useMobile.js"
import { IN_ELECTRON } from "@follow/shared/constants"
import { env } from "@follow/shared/env"
import { cn, getOS } from "@follow/utils/utils"
import { useEffect } from "react"
import { Outlet } from "react-router"
import { toast } from "sonner"

import { queryClient } from "~/lib/query-client"

Expand Down Expand Up @@ -32,6 +37,29 @@ function App() {
return cleanup
}, [])

useEffect(() => {
CapacitorApp.addListener("appUrlOpen", async (event: URLOpenListenerEvent) => {
const authUrl = new URL(event.url)
const token = authUrl.searchParams.get("token")
if (token) {
try {
await CapacitorHttp.get({
url: `${env.VITE_API_URL}/auth/session`,
headers: {
Cookie: `authjs.session-token=${token}`,
},
})
} catch (e) {
toast.error(`Login failed ${e}`)
}
}
})

return () => {
CapacitorApp.removeAllListeners()
}
}, [])

const windowsElectron = IN_ELECTRON && getOS() === "Windows"
return (
<RootProviders>
Expand Down
8 changes: 7 additions & 1 deletion apps/renderer/src/modules/user/LoginButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Capacitor } from "@capacitor/core"
import { UserArrowLeftIcon } from "@follow/components/icons/user.jsx"
import { ActionButton } from "@follow/components/ui/button/index.js"
import { env } from "@follow/shared/env"
import type { FC } from "react"
import { useTranslation } from "react-i18next"

Expand Down Expand Up @@ -36,5 +38,9 @@ export const LoginButton: FC<LoginProps> = (props) => {
<UserArrowLeftIcon className="size-4" />
</ActionButton>
)
return method === "modal" ? Content : <a href="/login">{Content}</a>
return method === "modal" ? (
Content
) : (
<a href={Capacitor.isNativePlatform() ? `${env.VITE_WEB_URL}/login` : "/login"}>{Content}</a>
)
}
31 changes: 31 additions & 0 deletions capacitor.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { CapacitorConfig } from "@capacitor/cli"

// <key>CFBundleURLTypes</key>
// <array>
// <dict>
// <key>CFBundleURLName</key>
// <string>com.example.app</string>
// <key>CFBundleURLSchemes</key>
// <array>
// <string>follow</string>
// </array>
// </dict>
// </array>
// <key>WKAppBoundDomains</key>
// <array>
// <string>app.follow.is</string>
// <string>api.follow.is</string>
// </array>

const config: CapacitorConfig = {
appId: "com.example.app",
appName: "Follow",
webDir: "out/web",
plugins: {
CapacitorHttp: {
enabled: true,
},
},
}

export default config
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@
"typecheck": "turbo typecheck",
"update:main-hash": "tsx plugins/vite/generate-main-hash.ts"
},
"dependencies": {
"@capacitor/android": "^6.2.0",
"@capacitor/app": "^6.0.2",
"@capacitor/core": "^6.2.0",
"@capacitor/ios": "^6.2.0"
},
"devDependencies": {
"@babel/generator": "7.26.2",
"@capacitor/cli": "^6.2.0",
"@clack/prompts": "0.8.2",
"@egoist/tailwindcss-icons": "1.8.1",
"@electron-forge/cli": "7.6.0",
Expand Down
Loading
Loading