release(desktop): Release v0.3.11 (#2999)

This commit is contained in:
DIYgod
2025-03-08 13:27:45 +08:00
committed by GitHub
34 changed files with 464 additions and 121 deletions
+7
View File
@@ -0,0 +1,7 @@
# What's new in v0.3.11
## New Features
## Improvements
## Bug Fixes
+3 -2
View File
@@ -1,7 +1,7 @@
{
"name": "Follow",
"type": "module",
"version": "0.3.10",
"version": "0.3.11",
"private": true,
"description": "Follow everything in one place",
"author": "Follow Team",
@@ -55,6 +55,7 @@
"@sentry/vite-plugin": "3.1.2",
"@types/html-minifier-terser": "7.0.2",
"@types/js-yaml": "4.0.9",
"@types/react-google-recaptcha": "2.1.9",
"@vitejs/plugin-legacy": "6.0.1",
"@vitejs/plugin-react": "4.3.4",
"autoprefixer": "10.4.20",
@@ -80,7 +81,7 @@
"utf-8-validate": "6.0.5"
},
"productName": "Follow",
"mainHash": "c92a47e6439382c1fdab1de5a29a0265ad1b6019b0868d3b2acb6b83509afc55",
"mainHash": "ad983e722aa04bc9a5fc38a6978cd3740c6cfcc3e7e0adecf09f0d6955c63ad6",
"bump": {
"before": [
"git pull --rebase",
+12 -1
View File
@@ -5,7 +5,7 @@ import { env } from "@follow/shared/env.desktop"
import { createBuildSafeHeaders } from "@follow/utils/headers"
import { IMAGE_PROXY_URL } from "@follow/utils/img-proxy"
import { parse } from "cookie-es"
import { app, BrowserWindow, session } from "electron"
import { app, BrowserWindow, net, protocol, session } from "electron"
import squirrelStartup from "electron-squirrel-startup"
import { DEVICE_ID } from "./constants/system"
@@ -16,6 +16,7 @@ import { handleUrlRouting } from "./lib/router"
import { store } from "./lib/store"
import { registerAppTray } from "./lib/tray"
import { setBetterAuthSessionCookie, updateNotificationsToken } from "./lib/user"
import { logger } from "./logger"
import { registerUpdater } from "./updater"
import { cleanupOldRender } from "./updater/hot-updater"
import {
@@ -71,6 +72,16 @@ function bootstrap() {
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(async () => {
protocol.handle("app", (request) => {
try {
const urlObj = new URL(request.url)
return net.fetch(`file://${urlObj.pathname}`)
} catch {
logger.error("app protocol error", request.url)
return new Response("Not found", { status: 404 })
}
})
// Default open or close DevTools by F12 in development
// and ignore CommandOrControl + R in production.
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
+12 -1
View File
@@ -5,7 +5,7 @@ import { PushReceiver } from "@eneris/push-receiver"
import { APP_PROTOCOL } from "@follow/shared/constants"
import { env } from "@follow/shared/env.desktop"
import type { MessagingData } from "@follow/shared/hono"
import { app, nativeTheme, Notification, shell } from "electron"
import { app, nativeTheme, Notification, protocol, shell } from "electron"
import contextMenu from "electron-context-menu"
import { getIconPath } from "./helper"
@@ -61,6 +61,17 @@ export const initializeAppStage1 = () => {
registerPushNotifications()
clearCacheCronJob()
checkAndCleanCodeCache()
protocol.registerSchemesAsPrivileged([
{
scheme: "app",
privileges: {
standard: true,
bypassCSP: true,
supportFetchAPI: true,
},
},
])
}
let contextMenuDisposer: () => void
+34
View File
@@ -3,6 +3,8 @@ import { app, Menu, nativeImage, Tray } from "electron"
import { isMacOS } from "~/env"
import { getTrayIconPath } from "~/helper"
import { revealLogFile } from "~/logger"
import { checkForAppUpdates } from "~/updater"
import { getMainWindowOrCreate } from "../window"
import { t } from "./i18n"
@@ -29,6 +31,38 @@ export const registerAppTray = () => {
label: t("menu.open", { name }),
click: showWindow,
},
{
label: t("menu.help"),
submenu: [
{
label: t("menu.reload"),
click: () => {
const mainWindow = getMainWindowOrCreate()
mainWindow.webContents.reload()
},
},
{
label: t("menu.toggleDevTools"),
click: () => {
const mainWindow = getMainWindowOrCreate()
mainWindow.webContents.toggleDevTools()
},
},
{
label: t("menu.openLogFile"),
click: async () => {
await revealLogFile()
},
},
{
label: t("menu.checkForUpdates"),
click: async () => {
showWindow()
await checkForAppUpdates()
},
},
],
},
{ label: t("menu.quit", { name }), click: () => app.quit() },
])
tray.setContextMenu(contextMenu)
+7 -9
View File
@@ -1,5 +1,5 @@
import path from "node:path"
import { fileURLToPath } from "node:url"
import { fileURLToPath, pathToFileURL } from "node:url"
import { is } from "@electron-toolkit/utils"
import { APP_PROTOCOL } from "@follow/shared"
@@ -112,7 +112,7 @@ export function createWindow(
const handleExternalProtocol = async (e: Event, url: string, window: BrowserWindow) => {
const { protocol } = new URL(url)
const ignoreProtocols = ["http", "https", APP_PROTOCOL, "file", "code", "cursor"]
const ignoreProtocols = ["http", "https", APP_PROTOCOL, "file", "code", "cursor", "app"]
if (ignoreProtocols.includes(protocol.slice(0, -1))) {
return
}
@@ -149,14 +149,12 @@ export function createWindow(
// Production entry
const dynamicRenderEntry = loadDynamicRenderEntry()
logger.info("load dynamic render entry", dynamicRenderEntry)
const appLoadEntry = dynamicRenderEntry || path.resolve(__dirname, "../renderer/index.html")
const appLoadFileEntry = dynamicRenderEntry || path.resolve(__dirname, "../renderer/index.html")
window.loadFile(appLoadEntry, {
hash: options?.extraPath,
})
logger.log(appLoadEntry, {
hash: options?.extraPath,
})
const appLoadEntry = `app://follow.is${pathToFileURL(appLoadFileEntry).pathname}${options?.extraPath || ""}`
window.loadURL(appLoadEntry)
logger.log("load URL", appLoadEntry)
}
if (isWindows) {
+3 -2
View File
@@ -64,9 +64,10 @@ export const loginHandler = async (
args?: {
email?: string
password?: string
headers?: Record<string, string>
},
) => {
const { email, password } = args ?? {}
const { email, password, headers } = args ?? {}
if (IN_ELECTRON && provider !== "credential") {
window.open(`${WEB_URL}/login?provider=${provider}`)
} else {
@@ -75,7 +76,7 @@ export const loginHandler = async (
window.location.href = "/login"
return
}
return signIn.email({ email, password })
return signIn.email({ email, password }, { headers })
}
signIn.social({
@@ -10,6 +10,8 @@ import {
import { Input } from "@follow/components/ui/input/Input.js"
import { env } from "@follow/shared/env.desktop"
import { zodResolver } from "@hookform/resolvers/zod"
import { useRef } from "react"
import ReCAPTCHA from "react-google-recaptcha"
import { useForm } from "react-hook-form"
import { useTranslation } from "react-i18next"
import { toast } from "sonner"
@@ -40,10 +42,16 @@ export function LoginWithPassword({ runtime }: { runtime: LoginRuntime }) {
const { present } = useModalStack()
const { dismiss } = useCurrentModal()
const recaptchaRef = useRef<ReCAPTCHA>(null)
async function onSubmit(values: z.infer<typeof formSchema>) {
const token = await recaptchaRef.current?.executeAsync()
const res = await loginHandler("credential", runtime, {
email: values.email,
password: values.password,
headers: {
"x-token": `r2:${token}`,
},
})
if (res?.error) {
toast.error(res.error.message)
@@ -115,6 +123,7 @@ export function LoginWithPassword({ runtime }: { runtime: LoginRuntime }) {
)}
/>
<div className="flex flex-col space-y-3">
<ReCAPTCHA ref={recaptchaRef} sitekey={env.VITE_RECAPTCHA_V2_SITE_KEY} size="invisible" />
<Button
type="submit"
isLoading={form.formState.isSubmitting}
@@ -167,7 +176,10 @@ function RegisterForm() {
const { isValid } = form.formState
function onSubmit(values: z.infer<typeof registerFormSchema>) {
const recaptchaRef = useRef<ReCAPTCHA>(null)
async function onSubmit(values: z.infer<typeof registerFormSchema>) {
const token = await recaptchaRef.current?.executeAsync()
return signUp.email({
email: values.email,
password: values.password,
@@ -180,6 +192,9 @@ function RegisterForm() {
onError(context) {
toast.error(context.error.message)
},
headers: {
"x-token": `r2:${token}`,
},
},
})
}
@@ -227,6 +242,7 @@ function RegisterForm() {
</FormItem>
)}
/>
<ReCAPTCHA ref={recaptchaRef} sitekey={env.VITE_RECAPTCHA_V2_SITE_KEY} size="invisible" />
<Button disabled={!isValid} type="submit" className="w-full" size="lg">
{t("register.submit")}
</Button>
@@ -23,13 +23,7 @@ export const ClaimDailyReward = () => {
<Tooltip>
<TooltipTrigger asChild>
<>
{env.VITE_RECAPTCHA_V2_SITE_KEY && (
<ReCAPTCHA
ref={recaptchaRef}
sitekey={env.VITE_RECAPTCHA_V2_SITE_KEY}
size="invisible"
/>
)}
<ReCAPTCHA ref={recaptchaRef} sitekey={env.VITE_RECAPTCHA_V2_SITE_KEY} size="invisible" />
<Button
variant="primary"
isLoading={mutation.isPending}
@@ -91,8 +91,18 @@ export const useClaimWalletDailyRewardMutation = () => {
return useMutation({
mutationKey: ["claimWalletDailyReward"],
mutationFn: ({ tokenV2, tokenV3 }: { tokenV2?: string; tokenV3?: string }) =>
apiClient.wallets.transactions.claim_daily.$post({ json: { t2: tokenV2, t3: tokenV3 } }),
mutationFn: ({ tokenV2, tokenV3 }: { tokenV2?: string | null; tokenV3?: string | null }) =>
apiClient.wallets.transactions.claim_daily.$post(
{ json: {} },
{
headers:
tokenV2 || tokenV3
? {
"x-token": tokenV2 ? `r2:${tokenV2}` : `r3:${tokenV3}`,
}
: undefined,
},
),
async onError(err) {
toastFetchError(err)
},
@@ -92,3 +92,8 @@
.grecaptcha-badge {
visibility: hidden;
}
[title="recaptcha challenge expires in two minutes"] {
pointer-events: auto !important;
-webkit-app-region: no-drag !important;
}
+2 -2
View File
@@ -21,14 +21,14 @@ Pod::Spec.new do |s|
s.dependency 'ExpoModulesCore'
s.dependency 'SnapKit', '~> 5.7.0'
s.dependency 'SDWebImage', '~> 5.0'
s.dependency 'SPIndicator', '~> 1.0.0'
s.dependency 'SPIndicator', '~> 1.6.4'
# Swift/Objective-C compatibility
s.pod_target_xcconfig = {
'DEFINES_MODULE' => 'YES',
}
s.source_files = "**/*.{h,m,mm,swift,hpp,cpp,js}"
s.resource_bundles = {
'js' => ['SharedWebView/injected/**/*'],
'FollowNative' => ['Media.xcassets'],
@@ -34,17 +34,34 @@ extension ToastType {
}
}
}
enum Position: String, Enumerable {
case top
case center
case bottom
}
extension Position {
func toSPPresentSide() -> SPIndicatorPresentSide {
switch self {
case .top: .top
case .center: .center
case .bottom: .bottom
}
}
}
struct ToastOptions: Record {
@Field
var message: String?
@Field
var type: ToastType = .info
@Field
var duration: Double = 1.5
@Field
var title: String
@Field
var position: Position?
}
public class ToasterModule: Module {
@@ -56,6 +73,11 @@ public class ToasterModule: Module {
DispatchQueue.main.sync {
let indicatorView = SPIndicatorView(
title: value.title, message: value.message, preset: value.type.type())
if value.position != nil {
indicatorView.presentSide = value.position!.toSPPresentSide()
}
indicatorView.present(duration: value.duration, haptic: value.type.haptic())
}
}
+1
View File
@@ -84,6 +84,7 @@
"react-native-awesome-slider": "2.9.0",
"react-native-bouncy-checkbox": "4.1.2",
"react-native-color-matrix-image-filters": "7.0.2",
"react-native-device-info": "14.0.4",
"react-native-gesture-handler": "2.24.0",
"react-native-image-colors": "2.4.0",
"react-native-ios-context-menu": "3.1.0",
@@ -1,6 +1,6 @@
import { clsx } from "@follow/utils"
import { requireNativeView } from "expo"
import { useAtom, useAtomValue } from "jotai"
import { useAtom } from "jotai"
import * as React from "react"
import { useEffect } from "react"
import type { ViewProps } from "react-native"
@@ -8,7 +8,6 @@ import { ActivityIndicator, TouchableOpacity, View } from "react-native"
import { useUISettingKey } from "@/src/atoms/settings/ui"
import { BugCuteReIcon } from "@/src/icons/bug_cute_re"
import { useEntryContentContext } from "@/src/modules/entry-content/ctx"
import type { EntryModel } from "@/src/store/entry/types"
import { Portal } from "../../ui/portal"
@@ -26,6 +25,7 @@ const NativeView: React.ComponentType<
type EntryContentWebViewProps = {
entry: EntryModel
noMedia?: boolean
showSource?: boolean
}
const setCodeTheme = (light: string, dark: string) => {
@@ -54,21 +54,19 @@ const setShowSource = (value: boolean) => {
}
export function EntryContentWebView(props: EntryContentWebViewProps) {
const { showSourceAtom } = useEntryContentContext()
const showSource = useAtomValue(showSourceAtom)
useEffect(() => {
setShowSource(!!showSource)
}, [showSource])
const [contentHeight, setContentHeight] = useAtom(sharedWebViewHeightAtom)
const codeThemeLight = useUISettingKey("codeHighlightThemeLight")
const codeThemeDark = useUISettingKey("codeHighlightThemeDark")
const readerRenderInlineStyle = useUISettingKey("readerRenderInlineStyle")
const { entry, noMedia } = props
const { entry, noMedia, showSource } = props
const [mode, setMode] = React.useState<"normal" | "debug">("normal")
useEffect(() => {
setShowSource(!!showSource)
}, [showSource])
useEffect(() => {
setNoMedia(!!noMedia)
}, [noMedia, mode])
@@ -9,6 +9,9 @@ import Animated, { FadeIn, FadeOut } from "react-native-reanimated"
import { MingcuteRightLine } from "@/src/icons/mingcute_right_line"
import { useColor } from "@/src/theme/colors"
export enum GroupedInsetListCardItemStyle {
NavigationLink = "NavigationLink",
}
type GroupedInsetListCardProps = {
showSeparator?: boolean
}
@@ -43,7 +46,8 @@ export const GroupedInsetListCard: FC<
const isNavigationLink =
React.isValidElement(child) &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
(child.type as Function).name === GroupedInsetListNavigationLink.name
((child.type as Function).name === GroupedInsetListNavigationLink.name ||
(child.type as any).itemStyle === GroupedInsetListCardItemStyle.NavigationLink)
return (
<Fragment key={index}>
@@ -13,6 +13,8 @@ export interface ToastProps {
duration: number
icon?: React.ReactNode | false
canClose?: boolean
position?: "top" | "center" | "bottom"
}
export type CenterToastProps = Partial<
+32 -40
View File
@@ -1,8 +1,9 @@
import { expoClient } from "@better-auth/expo/client"
import type { authPlugins } from "@follow/shared/src/hono"
import { useQuery } from "@tanstack/react-query"
import { twoFactorClient } from "better-auth/client/plugins"
import { inferAdditionalFields, twoFactorClient } from "better-auth/client/plugins"
import { createAuthClient } from "better-auth/react"
import type * as better_call from "better-call"
import type { BetterAuthClientPlugin } from "better-auth/types"
import * as SecureStore from "expo-secure-store"
import { whoamiQueryKey } from "../store/user/hooks"
@@ -13,6 +14,31 @@ const storagePrefix = "follow_auth"
export const cookieKey = `${storagePrefix}_cookie`
export const sessionTokenKey = "__Secure-better-auth.session_token"
type AuthPlugin = (typeof authPlugins)[number]
const serverPlugins = [
{
id: "customGetProviders",
$InferServerPlugin: {} as Extract<AuthPlugin, { id: "customGetProviders" }>,
},
{
id: "customCreateSession",
$InferServerPlugin: {} as Extract<AuthPlugin, { id: "customCreateSession" }>,
},
{
id: "getAccountInfo",
$InferServerPlugin: {} as Extract<AuthPlugin, { id: "getAccountInfo" }>,
},
inferAdditionalFields({
user: {
handle: {
type: "string",
required: false,
},
},
}),
] satisfies BetterAuthClientPlugin[]
const authClient = createAuthClient({
baseURL: `${proxyEnv.VITE_API_URL}/better-auth`,
plugins: [
@@ -21,6 +47,7 @@ const authClient = createAuthClient({
id: "getProviders",
$InferServerPlugin: {} as (typeof authPlugins)[0],
},
...serverPlugins,
expoClient({
scheme: "follow",
storagePrefix,
@@ -41,13 +68,16 @@ const authClient = createAuthClient({
export const {
changeEmail,
forgetPassword,
getAccountInfo,
getCookie,
getProviders,
linkSocial,
sendVerificationEmail,
signIn,
signOut,
signUp,
twoFactor,
unlinkAccount,
updateUser,
useSession,
} = authClient
@@ -65,41 +95,3 @@ export const useAuthProviders = () => {
queryFn: async () => (await getProviders()).data,
})
}
// eslint-disable-next-line unused-imports/no-unused-vars
declare const authPlugins: {
id: "getProviders"
endpoints: {
getProviders: {
<
C extends [
(
| better_call.Context<
"/get-providers",
{
method: "GET"
}
>
| undefined
)?,
],
>(
...ctx: C
): Promise<
C extends [
{
asResponse: true
},
]
? Response
: Record<string, AuthProvider>
>
path: "/get-providers"
options: {
method: "GET"
}
method: better_call.Method | better_call.Method[]
headers: Headers
}
}
}[]
+5 -1
View File
@@ -6,7 +6,9 @@ import type { ToastProps } from "../components/ui/toast/types"
export const toastInstance = new ToastManager()
type CommandToastOptions = Partial<Pick<ToastProps, "duration" | "icon" | "render" | "message">>
type CommandToastOptions = Partial<
Pick<ToastProps, "duration" | "icon" | "render" | "message" | "position">
>
type Toast = {
// [key in "error" | "success" | "info"]: (message: string) => void;
show: typeof toastInstance.show
@@ -23,6 +25,7 @@ interface NativeToasterOptions {
* seconds
*/
duration?: number
position?: "top" | "center" | "bottom"
}
export const toast = {
show: toastInstance.show.bind(toastInstance),
@@ -36,6 +39,7 @@ export const toast = {
message,
type,
duration: options.duration ? options.duration / 1000 : 1.5,
position: options.position,
} as NativeToasterOptions)
return
}
+4 -2
View File
@@ -4,11 +4,12 @@ import { router } from "expo-router"
import type { Control } from "react-hook-form"
import { useController, useForm } from "react-hook-form"
import type { TextInputProps } from "react-native"
import { Text, TextInput, TouchableOpacity, View } from "react-native"
import { Text, TouchableOpacity, View } from "react-native"
import { KeyboardController } from "react-native-keyboard-controller"
import { z } from "zod"
import { SubmitButton } from "@/src/components/common/SubmitButton"
import { PlainTextField } from "@/src/components/ui/form/TextField"
import { signIn } from "@/src/lib/auth"
import { toast } from "@/src/lib/toast"
import { accentColor } from "@/src/theme/colors"
@@ -53,7 +54,8 @@ function Input({
name,
})
return (
<TextInput
<PlainTextField
hitSlop={10}
selectionColor={accentColor}
{...rest}
value={field.value}
@@ -12,6 +12,7 @@ import { CheckCircleCuteReIcon } from "@/src/icons/check_circle_cute_re"
import { RoundCuteFiIcon } from "@/src/icons/round_cute_fi"
import { RoundCuteReIcon } from "@/src/icons/round_cute_re"
import { Dialog } from "@/src/lib/dialog"
import { toast } from "@/src/lib/toast"
import { useWhoami } from "@/src/store/user/hooks"
import { accentColor, useColor } from "@/src/theme/colors"
@@ -83,6 +84,7 @@ export const UnreadOnlyActionButton = ({ variant = "primary" }: HeaderActionButt
selectedIcon={<RoundCuteFiIcon height={size} width={size} color={color} />}
onPress={() => {
setGeneralSetting("unreadOnly", !unreadOnly)
toast.info(`Showing ${unreadOnly ? "all" : "unread"} entries`, { position: "bottom" })
}}
selected={unreadOnly}
overlay={false}
@@ -1,5 +1,8 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import * as FileSystem from "expo-file-system"
import { Alert, View } from "react-native"
import type { FC } from "react"
import { useMemo } from "react"
import { ActivityIndicator, Alert, Text, View } from "react-native"
import {
NavigationBlurEffectHeader,
@@ -7,19 +10,75 @@ import {
} from "@/src/components/layouts/views/SafeNavigationScrollView"
import {
GroupedInsetListCard,
GroupedInsetListCardItemStyle,
GroupedInsetListNavigationLink,
GroupedInsetListNavigationLinkIcon,
GroupedInsetListSectionHeader,
GroupedPlainButtonCell,
} from "@/src/components/ui/grouped/GroupedList"
import { getDbPath } from "@/src/database"
import { signOut } from "@/src/lib/auth"
import { AppleCuteFiIcon } from "@/src/icons/apple_cute_fi"
import { GithubCuteFiIcon } from "@/src/icons/github_cute_fi"
import { GoogleCuteFiIcon } from "@/src/icons/google_cute_fi"
import type { AuthProvider } from "@/src/lib/auth"
import { getAccountInfo, getProviders, linkSocial, signOut, unlinkAccount } from "@/src/lib/auth"
import { openLink } from "@/src/lib/native"
import { toast } from "@/src/lib/toast"
type Account = {
id: string
provider: string
profile: {
id?: string
email?: string
name?: string
image?: string
} | null
}
const accountInfoKey = ["account-info"]
export const AccountScreen = () => {
const { data: accounts } = useQuery({
queryKey: accountInfoKey,
queryFn: () => getAccountInfo(),
})
const { data: providers, isLoading } = useQuery({
queryKey: ["providers"],
queryFn: async () => (await getProviders()).data as Record<string, AuthProvider>,
})
const providerToAccountMap = useMemo(() => {
return Object.keys(providers || {}).reduce(
(acc, provider) => {
acc[provider] = accounts?.data?.find((account) => account.provider === provider)!
return acc
},
{} as Record<string, Account>,
)
}, [accounts?.data, providers])
return (
<SafeNavigationScrollView className="bg-system-grouped-background">
<NavigationBlurEffectHeader title="Account" />
<View className="mt-6">
<GroupedInsetListSectionHeader label="Authentication" />
<GroupedInsetListCard />
<GroupedInsetListCard>
{providers ? (
Object.keys(providers).map((provider) => (
<AccountLinker
key={provider}
provider={provider as any}
account={providerToAccountMap[provider]}
/>
))
) : isLoading ? (
<View className="flex h-12 flex-1 items-center justify-center">
<ActivityIndicator />
</View>
) : null}
</GroupedInsetListCard>
</View>
{/* Danger Zone */}
@@ -50,3 +109,83 @@ export const AccountScreen = () => {
</SafeNavigationScrollView>
)
}
const provider2IconMap = {
google: (
<GroupedInsetListNavigationLinkIcon backgroundColor="#4081EC">
<GoogleCuteFiIcon height={24} width={24} color="#fff" />
</GroupedInsetListNavigationLinkIcon>
),
github: (
<GroupedInsetListNavigationLinkIcon backgroundColor="#000">
<GithubCuteFiIcon height={24} width={24} color="#fff" />
</GroupedInsetListNavigationLinkIcon>
),
apple: (
<GroupedInsetListNavigationLinkIcon backgroundColor="#000">
<AppleCuteFiIcon height={24} width={24} color="#fff" />
</GroupedInsetListNavigationLinkIcon>
),
}
const provider2LabelMap = {
google: "Google",
github: "GitHub",
apple: "Apple",
}
const AccountLinker: FC<{
provider: keyof typeof provider2IconMap
account?: Account
}> = ({ provider, account }) => {
const queryClient = useQueryClient()
const unlinkAccountMutation = useMutation({
mutationFn: async () => {
const res = await unlinkAccount({ providerId: provider })
if (res.error) throw new Error(res.error.message)
},
onSuccess: () => {
toast.success("Unlinked account success")
queryClient.invalidateQueries({ queryKey: accountInfoKey })
},
onError: (error) => {
toast.error(error.message)
},
})
if (!provider2LabelMap[provider]) return null
return (
<GroupedInsetListNavigationLink
label={provider2LabelMap[provider]}
icon={provider2IconMap[provider]}
postfix={
<Text className="text-secondary-label mr-1 max-w-[100px]">
{account?.profile?.email || account?.profile?.name || ""}
</Text>
}
onPress={() => {
if (!account) {
linkSocial({
provider: provider as any,
}).then((res) => {
if (res.data) {
openLink(res.data.url)
} else {
toast.error("Failed to link account")
}
})
return
}
Alert.alert("Unlink account", "Are you sure you want to unlink your account?", [
{ text: "Cancel", style: "cancel" },
{
text: "Unlink",
style: "destructive",
onPress: () => unlinkAccountMutation.mutate(),
},
])
}}
/>
)
}
;(AccountLinker as any).itemStyle = GroupedInsetListCardItemStyle.NavigationLink
@@ -1,11 +1,12 @@
import { useMutation } from "@tanstack/react-query"
import { router } from "expo-router"
import { useState } from "react"
import { Text, TextInput, TouchableWithoutFeedback, View } from "react-native"
import { Text, TouchableWithoutFeedback, View } from "react-native"
import { KeyboardAvoidingView, KeyboardController } from "react-native-keyboard-controller"
import { useSafeAreaInsets } from "react-native-safe-area-context"
import { SubmitButton } from "@/src/components/common/SubmitButton"
import { PlainTextField } from "@/src/components/ui/form/TextField"
import { forgetPassword } from "@/src/lib/auth"
import { toast } from "@/src/lib/toast"
@@ -46,7 +47,7 @@ export default function ForgetPassword() {
<View className="bg-secondary-system-background mt-6 gap-4 self-stretch rounded-2xl px-6 py-4">
<View className="flex-row">
<TextInput
<PlainTextField
autoCapitalize="none"
autoCorrect={false}
keyboardType="email-address"
+24 -15
View File
@@ -1,35 +1,44 @@
import { Redirect, router } from "expo-router"
import { router } from "expo-router"
import { useEffect } from "react"
import { Text, TouchableOpacity } from "react-native"
import { Login } from "@/src/modules/login"
import { useWhoami } from "@/src/store/user/hooks"
function exit() {
if (router.canGoBack()) {
router.back()
} else {
router.replace("/")
}
}
export default function LoginPage() {
const whoami = useWhoami()
if (!whoami?.id) {
// Not logged in
return <Login />
}
useEffect(() => {
if (whoami?.id && !__DEV__) {
exit()
}
}, [whoami])
// For development purposes, we don't want to redirect to the home page automatically
if (__DEV__) {
return (
<>
<Login />
return (
<>
<Login />
{!!whoami?.id && __DEV__ && (
<TouchableOpacity
className="bg-system-fill absolute bottom-8 left-1/2 -translate-x-1/2 flex-row items-center justify-center rounded-xl p-2 px-4"
activeOpacity={0.7}
onPress={() => {
router.replace("/")
exit()
}}
>
<Text className="text-secondary-label text-center font-semibold">
Redirect to Home (DEV)
</Text>
</TouchableOpacity>
</>
)
}
return <Redirect href="/" />
)}
</>
)
}
+3 -2
View File
@@ -4,11 +4,12 @@ import { router } from "expo-router"
import type { Control } from "react-hook-form"
import { useController, useForm } from "react-hook-form"
import type { TextInputProps } from "react-native"
import { Text, TextInput, TouchableWithoutFeedback, View } from "react-native"
import { Text, TouchableWithoutFeedback, View } from "react-native"
import { KeyboardController } from "react-native-keyboard-controller"
import { z } from "zod"
import { SubmitButton } from "@/src/components/common/SubmitButton"
import { PlainTextField } from "@/src/components/ui/form/TextField"
import { Logo } from "@/src/components/ui/logo"
import { signUp } from "@/src/lib/auth"
import { toast } from "@/src/lib/toast"
@@ -57,7 +58,7 @@ function Input({
name,
})
return (
<TextInput
<PlainTextField
selectionColor={accentColor}
{...rest}
value={field.value}
@@ -1,6 +1,6 @@
import { FeedViewType } from "@follow/constants"
import { useLocalSearchParams } from "expo-router"
import { atom } from "jotai"
import { atom, useAtomValue } from "jotai"
import { useMemo } from "react"
import { Pressable, Text, View } from "react-native"
import Animated, { FadeIn, FadeOut } from "react-native-reanimated"
@@ -11,9 +11,10 @@ import { SafeNavigationScrollView } from "@/src/components/layouts/views/SafeNav
import { EntryContentWebView } from "@/src/components/native/webview/EntryContentWebView"
import { PortalHost } from "@/src/components/ui/portal"
import { openLink } from "@/src/lib/native"
import { EntryContentContext } from "@/src/modules/entry-content/ctx"
import { EntryContentContext, useEntryContentContext } from "@/src/modules/entry-content/ctx"
import { EntryAISummary } from "@/src/modules/entry-content/EntryAISummary"
import { useEntry, usePrefetchEntryContent } from "@/src/store/entry/hooks"
import type { EntryModel } from "@/src/store/entry/types"
import { useFeed } from "@/src/store/feed/hooks"
import { useAutoMarkAsRead } from "@/src/store/unread/hooks"
@@ -71,7 +72,7 @@ export default function EntryDetailPage() {
<EntryAISummary entryId={entryId as string} />
{entry && (
<View className="mt-3">
<EntryContentWebView entry={entry} />
<EntryContentWebViewWithContext entry={entry} />
</View>
)}
{viewType === FeedViewType.SocialMedia && (
@@ -86,6 +87,12 @@ export default function EntryDetailPage() {
)
}
const EntryContentWebViewWithContext = ({ entry }: { entry: EntryModel }) => {
const { showSourceAtom } = useEntryContentContext()
const showSource = useAtomValue(showSourceAtom)
return <EntryContentWebView entry={entry} showSource={showSource} />
}
const EntryInfo = ({ entryId }: { entryId: string }) => {
const entry = useEntry(entryId)
+3 -2
View File
@@ -62,16 +62,17 @@ export const loginHandler = async (
args?: {
email?: string
password?: string
headers?: Record<string, string>
},
) => {
const { email, password } = args ?? {}
const { email, password, headers } = args ?? {}
if (provider === "credential") {
if (!email || !password) {
window.location.href = "/login"
return
}
return signIn.email({ email, password })
return signIn.email({ email, password }, { headers })
}
signIn.social({
+12 -1
View File
@@ -18,9 +18,11 @@ import { Input } from "@follow/components/ui/input/index.js"
import { LoadingCircle } from "@follow/components/ui/loading/index.jsx"
import { authProvidersConfig } from "@follow/constants"
import { DEEPLINK_SCHEME } from "@follow/shared/constants"
import { env } from "@follow/shared/env"
import { cn } from "@follow/utils/utils"
import { zodResolver } from "@hookform/resolvers/zod"
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
import ReCAPTCHA from "react-google-recaptcha"
import { useForm } from "react-hook-form"
import { Trans, useTranslation } from "react-i18next"
import { Link, useLocation, useNavigate } from "react-router"
@@ -225,6 +227,8 @@ function LoginWithPassword() {
const { isSubmitting } = form.formState
const navigate = useNavigate()
const recaptchaRef = useRef<ReCAPTCHA>(null)
async function onSubmit(values: z.infer<typeof formSchema>) {
if (needTwoFactor && values.code) {
const res = await twoFactor.verifyTotp({ code: values.code })
@@ -236,7 +240,13 @@ function LoginWithPassword() {
return
}
const res = await loginHandler("credential", "app", values)
const token = await recaptchaRef.current?.executeAsync()
const res = await loginHandler("credential", "app", {
...values,
headers: {
"x-token": `r2:${token}`,
},
})
if (res?.error) {
toast.error(res.error.message)
return
@@ -303,6 +313,7 @@ function LoginWithPassword() {
)}
/>
)}
<ReCAPTCHA ref={recaptchaRef} sitekey={env.VITE_RECAPTCHA_V2_SITE_KEY} size="invisible" />
<Button type="submit" buttonClassName="!mt-3 w-full" isLoading={isSubmitting} size="lg">
{t("login.continueWith", { provider: t("words.email") })}
</Button>
@@ -19,6 +19,8 @@ import { Input } from "@follow/components/ui/input/index.js"
import { env } from "@follow/shared/env"
import { zodResolver } from "@hookform/resolvers/zod"
import { useMutation } from "@tanstack/react-query"
import { useRef } from "react"
import ReCAPTCHA from "react-google-recaptcha"
import { useForm } from "react-hook-form"
import { useTranslation } from "react-i18next"
import { useNavigate } from "react-router"
@@ -38,13 +40,23 @@ export function Component() {
},
})
const recaptchaRef = useRef<ReCAPTCHA>(null)
const { isValid } = form.formState
const updateMutation = useMutation({
mutationFn: async (values: z.infer<typeof forgetPasswordFormSchema>) => {
const res = await forgetPassword({
email: values.email,
redirectTo: `${env.VITE_WEB_URL}/reset-password`,
})
const token = await recaptchaRef.current?.executeAsync()
const res = await forgetPassword(
{
email: values.email,
redirectTo: `${env.VITE_WEB_URL}/reset-password`,
},
{
headers: {
"x-token": `r2:${token}`,
},
},
)
if (res.error) {
throw new Error(res.error.message)
}
@@ -98,6 +110,11 @@ export function Component() {
</FormItem>
)}
/>
<ReCAPTCHA
ref={recaptchaRef}
sitekey={env.VITE_RECAPTCHA_V2_SITE_KEY}
size="invisible"
/>
<div className="text-right">
<Button disabled={!isValid} type="submit" isLoading={updateMutation.isPending}>
{t("login.submit")}
+11 -1
View File
@@ -10,7 +10,10 @@ import {
FormMessage,
} from "@follow/components/ui/form/index.jsx"
import { Input } from "@follow/components/ui/input/index.js"
import { env } from "@follow/shared/env"
import { zodResolver } from "@hookform/resolvers/zod"
import { useRef } from "react"
import ReCAPTCHA from "react-google-recaptcha"
import { useForm } from "react-hook-form"
import { Trans, useTranslation } from "react-i18next"
import { Link, useNavigate } from "react-router"
@@ -53,7 +56,10 @@ function RegisterForm() {
const navigate = useNavigate()
function onSubmit(values: z.infer<typeof formSchema>) {
const recaptchaRef = useRef<ReCAPTCHA>(null)
async function onSubmit(values: z.infer<typeof formSchema>) {
const token = await recaptchaRef.current?.executeAsync()
return signUp.email({
email: values.email,
password: values.password,
@@ -66,6 +72,9 @@ function RegisterForm() {
onError(context) {
toast.error(context.error.message)
},
headers: {
"x-token": `r2:${token}`,
},
},
})
}
@@ -129,6 +138,7 @@ function RegisterForm() {
</FormItem>
)}
/>
<ReCAPTCHA ref={recaptchaRef} sitekey={env.VITE_RECAPTCHA_V2_SITE_KEY} size="invisible" />
<Button disabled={!isValid} type="submit" className="w-full" size="lg">
{t("register.submit")}
</Button>
+2
View File
@@ -28,6 +28,7 @@
"ofetch": "1.4.1",
"rc-modal-sheet": "0.3.2",
"react-blurhash": "0.3.0",
"react-google-recaptcha": "3.1.0",
"react-hook-form": "7.54.2",
"react-hotkeys-hook": "4.6.1",
"react-i18next": "15.4.1",
@@ -49,6 +50,7 @@
"@follow/utils": "workspace:*",
"@radix-ui/react-avatar": "1.1.3",
"@types/html-minifier-terser": "7.0.2",
"@types/react-google-recaptcha": "2.1.9",
"chokidar": "4.0.3",
"daisyui": "4.12.23",
"dotenv-flow": "4.1.0",
+1 -2
View File
@@ -1,7 +1,5 @@
import type { ElectronAPI } from "@electron-toolkit/preload"
const isDev = process.env.NODE_ENV !== "production"
declare const globalThis: {
window: Window & {
electron?: ElectronAPI
@@ -10,6 +8,7 @@ declare const globalThis: {
electron?: ElectronAPI
}
const isDev = "process" in globalThis ? process.env.NODE_ENV === "development" : import.meta.env.DEV
export const APP_PROTOCOL = isDev ? "follow-dev" : "follow"
export const DEEPLINK_SCHEME = `${APP_PROTOCOL}://` as const
+3
View File
@@ -20,6 +20,9 @@ export const envSchema = {
VITE_EXTERNAL_API_URL: z.string().optional(),
VITE_WEB_PROD_URL: z.string().optional(),
VITE_WEB_DEV_URL: z.string().optional(),
VITE_RECAPTCHA_V2_SITE_KEY: z.string().default("6LdxQ-sqAAAAAN-_za3hUdFkJEO_cu2xHSpLKVan"),
VITE_RECAPTCHA_V3_SITE_KEY: z.string().default("6LdG-asqAAAAAEXr96565MKbRvxGEv31XEykRSHV"),
}
export const isDev = false
+32 -4
View File
@@ -278,6 +278,9 @@ importers:
'@types/js-yaml':
specifier: 4.0.9
version: 4.0.9
'@types/react-google-recaptcha':
specifier: 2.1.9
version: 2.1.9
'@vitejs/plugin-legacy':
specifier: 6.0.1
version: 6.0.1(terser@5.39.0)(vite@6.1.0(@types/node@22.13.4)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.39.0)(tsx@4.19.3)(yaml@2.7.0))
@@ -949,6 +952,9 @@ importers:
react-native-color-matrix-image-filters:
specifier: 7.0.2
version: 7.0.2(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)
react-native-device-info:
specifier: 14.0.4
version: 14.0.4(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))
react-native-gesture-handler:
specifier: 2.24.0
version: 2.24.0(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)
@@ -1124,6 +1130,9 @@ importers:
react-blurhash:
specifier: 0.3.0
version: 0.3.0(blurhash@2.0.5)(react@18.3.1)
react-google-recaptcha:
specifier: 3.1.0
version: 3.1.0(react@18.3.1)
react-hook-form:
specifier: 7.54.2
version: 7.54.2(react@18.3.1)
@@ -1182,6 +1191,9 @@ importers:
'@types/html-minifier-terser':
specifier: 7.0.2
version: 7.0.2
'@types/react-google-recaptcha':
specifier: 2.1.9
version: 2.1.9
chokidar:
specifier: 4.0.3
version: 4.0.3
@@ -4132,7 +4144,7 @@ packages:
'@radix-ui/react-compose-refs@1.1.1':
resolution: {integrity: sha512-Y9VzoRDSJtgFMUCoiZBDVo084VQ5hfpXxVE+NgkdNsjiDBByiImMZKKhxMwCbdHvhlENG6a833CbFkOQvTricw==}
peerDependencies:
'@types/react': '*'
'@types/react': npm:@types/react@18.3.12
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
@@ -4154,7 +4166,7 @@ packages:
'@radix-ui/react-context@1.1.1':
resolution: {integrity: sha512-UASk9zi+crv9WteK/NU4PLvOoL3OuE6BWVKNF6hPRBtYBDXQ2u5iu3O59zUlJiTVvkyuycnqrztsHVJwcK9K+Q==}
peerDependencies:
'@types/react': '*'
'@types/react': npm:@types/react@18.3.12
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
@@ -4211,7 +4223,7 @@ packages:
'@radix-ui/react-focus-guards@1.1.1':
resolution: {integrity: sha512-pSIwfrT1a6sIoDASCSpFwOasEwKTZWDw/iBdtnqKO7v6FeOzYJ7U53cPzYFVR3geGGXgVHaH+CdngrrAzqUGxg==}
peerDependencies:
'@types/react': '*'
'@types/react': npm:@types/react@18.3.12
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
@@ -4499,7 +4511,7 @@ packages:
'@radix-ui/react-use-controllable-state@1.1.0':
resolution: {integrity: sha512-MtfMVJiSr2NjzS0Aa90NPTnvTSg6C/JLCV7ma0W6+OMV78vd8OyRpID+Ng9LxzsPbLeuBnWBA1Nq30AtBIDChw==}
peerDependencies:
'@types/react': '*'
'@types/react': npm:@types/react@18.3.12
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
@@ -5590,6 +5602,9 @@ packages:
'@types/react-dom@18.3.1':
resolution: {integrity: sha512-qW1Mfv8taImTthu4KoXgDfLuk4bydU6Q/TkADnDWWHwi4NX4BR+LWfTp2sVmTqRrsHvyDDTelgelxJ+SsejKKQ==}
'@types/react-google-recaptcha@2.1.9':
resolution: {integrity: sha512-nT31LrBDuoSZJN4QuwtQSF3O89FVHC4jLhM+NtKEmVF5R1e8OY0Jo4//x2Yapn2aNHguwgX5doAq8Zo+Ehd0ug==}
'@types/react@18.3.12':
resolution: {integrity: sha512-D2wOSq/d6Agt28q7rSI3jhU7G6aiuzljDGZ2hTZHIkrTLUI+AF3WMeKkEZ9nN2fkBAlcktT6vcZjDFiIhMYEQw==}
@@ -12623,6 +12638,11 @@ packages:
react-native-svg:
optional: true
react-native-device-info@14.0.4:
resolution: {integrity: sha512-NX0wMAknSDBeFnEnSFQ8kkAcQrFHrG4Cl0mVjoD+0++iaKrOupiGpBXqs8xR0SeJyPC5zpdPl4h/SaBGly6UxA==}
peerDependencies:
react-native: '*'
react-native-drawer-layout@4.1.1:
resolution: {integrity: sha512-ob6O3ph7PZ3A2FpdlsSxHuMpHDXREZPR8A6S3q0dSxV7i6d+8Z6CPCTbegfN2QZyizSow9NLrKyXP93tlqZ3dA==}
peerDependencies:
@@ -20968,6 +20988,10 @@ snapshots:
dependencies:
'@types/react': 18.3.12
'@types/react-google-recaptcha@2.1.9':
dependencies:
'@types/react': 18.3.12
'@types/react@18.3.12':
dependencies:
'@types/prop-types': 15.7.14
@@ -29711,6 +29735,10 @@ snapshots:
transitivePeerDependencies:
- supports-color
react-native-device-info@14.0.4(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)):
dependencies:
react-native: 0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)
react-native-drawer-layout@4.1.1(react-native-gesture-handler@2.24.0(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native-reanimated@3.16.7(@babel/core@7.26.9)(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1):
dependencies:
react: 18.3.1