diff --git a/apps/desktop/src/renderer/src/hooks/biz/useEntryActions.tsx b/apps/desktop/src/renderer/src/hooks/biz/useEntryActions.tsx
index eeb3b06bd..518a8d17f 100644
--- a/apps/desktop/src/renderer/src/hooks/biz/useEntryActions.tsx
+++ b/apps/desktop/src/renderer/src/hooks/biz/useEntryActions.tsx
@@ -1,15 +1,17 @@
import { isMobile } from "@follow/components/hooks/useMobile.js"
-import { FeedViewType, UserRole } from "@follow/constants"
+import { FeedViewType, UserRole, views } from "@follow/constants"
import { IN_ELECTRON } from "@follow/shared/constants"
-import { useCallback, useMemo } from "react"
+import { useMemo } from "react"
import { useShowAISummaryAuto, useShowAISummaryOnce } from "~/atoms/ai-summary"
import { useShowAITranslationAuto, useShowAITranslationOnce } from "~/atoms/ai-translation"
import {
getReadabilityStatus,
+ isInReadability,
ReadabilityStatus,
setReadabilityContent,
setReadabilityStatus,
+ useEntryInReadabilityStatus,
} from "~/atoms/readability"
import { useShowSourceContent } from "~/atoms/source-content"
import { useUserRole, whoami } from "~/atoms/user"
@@ -25,41 +27,40 @@ import { useInboxById } from "~/store/inbox"
import { useRouteParamsSelector } from "./useRouteParams"
-export const useEntryReadabilityToggle = ({ id, url }: { id: string; url: string }) =>
- useCallback(async () => {
- const status = getReadabilityStatus()[id]
- const isTurnOn = status !== ReadabilityStatus.INITIAL && !!status
+export const toggleEntryReadability = async ({ id, url }: { id: string; url: string }) => {
+ const status = getReadabilityStatus()[id]
+ const isTurnOn = status !== ReadabilityStatus.INITIAL && !!status
- if (!isTurnOn && url) {
- setReadabilityStatus({
- [id]: ReadabilityStatus.WAITING,
+ if (!isTurnOn && url) {
+ setReadabilityStatus({
+ [id]: ReadabilityStatus.WAITING,
+ })
+ const result = await tipcClient
+ ?.readability({
+ url,
})
- const result = await tipcClient
- ?.readability({
- url,
- })
- .catch(() => {
- setReadabilityStatus({
- [id]: ReadabilityStatus.FAILURE,
- })
- })
-
- if (result) {
- const status = getReadabilityStatus()[id]
- if (status !== ReadabilityStatus.WAITING) return
+ .catch(() => {
setReadabilityStatus({
- [id]: ReadabilityStatus.SUCCESS,
+ [id]: ReadabilityStatus.FAILURE,
})
- setReadabilityContent({
- [id]: result,
- })
- }
- } else {
+ })
+
+ if (result) {
+ const status = getReadabilityStatus()[id]
+ if (status !== ReadabilityStatus.WAITING) return
setReadabilityStatus({
- [id]: ReadabilityStatus.INITIAL,
+ [id]: ReadabilityStatus.SUCCESS,
+ })
+ setReadabilityContent({
+ [id]: result,
})
}
- }, [id, url])
+ } else {
+ setReadabilityStatus({
+ [id]: ReadabilityStatus.INITIAL,
+ })
+ }
+}
export type EntryActionItem = {
id: FollowCommandId
@@ -70,8 +71,17 @@ export type EntryActionItem = {
disabled?: boolean
}
-export const useEntryActions = ({ entryId, view }: { entryId: string; view?: FeedViewType }) => {
+export const useEntryActions = ({
+ entryId,
+ view,
+ compact,
+}: {
+ entryId: string
+ view?: FeedViewType
+ compact?: boolean
+}) => {
const entry = useEntry(entryId)
+ const entryReadabilityStatus = useEntryInReadabilityStatus(entry?.entries.id)
const imageLength = entry?.entries.media?.filter((a) => a.type === "photo").length || 0
const feed = useFeedById(entry?.feedId, (feed) => {
return {
@@ -208,17 +218,36 @@ export const useEntryActions = ({ entryId, view }: { entryId: string; view?: Fee
active: !!entry?.read,
shortcut: shortcuts.entry.toggleRead.key,
},
+ {
+ id: COMMAND_ID.entry.tts,
+ onClick: runCmdFn(COMMAND_ID.entry.tts, [
+ { entryId, entryContent: entry?.entries.content },
+ ]),
+ hide: !IN_ELECTRON || compact || !entry?.entries.content,
+ shortcut: shortcuts.entry.tts.key,
+ },
+ {
+ id: COMMAND_ID.entry.readability,
+ onClick: runCmdFn(COMMAND_ID.entry.readability, [
+ { entryId, entryUrl: entry?.entries.url },
+ ]),
+ hide: !IN_ELECTRON || compact || (view && views[view]!.wideMode) || !entry?.entries.url,
+ active: isInReadability(entryReadabilityStatus),
+ },
{
id: COMMAND_ID.settings.customizeToolbar,
onClick: runCmdFn(COMMAND_ID.settings.customizeToolbar, []),
},
].filter((config) => !config.hide)
}, [
+ compact,
entry?.collections,
+ entry?.entries.content,
entry?.entries.url,
entry?.read,
entry?.view,
entryId,
+ entryReadabilityStatus,
feed?.id,
feed?.ownerUserId,
hasEntry,
@@ -241,11 +270,13 @@ export const useEntryActions = ({ entryId, view }: { entryId: string; view?: Fee
export const useSortedEntryActions = ({
entryId,
view,
+ compact,
}: {
entryId: string
view?: FeedViewType
+ compact?: boolean
}) => {
- const entryActions = useEntryActions({ entryId, view })
+ const entryActions = useEntryActions({ entryId, view, compact })
const orderMap = useToolbarOrderMap()
const mainAction = useMemo(
() =>
diff --git a/apps/desktop/src/renderer/src/modules/command/commands/entry.tsx b/apps/desktop/src/renderer/src/modules/command/commands/entry.tsx
index 4be5033fa..3852f2243 100644
--- a/apps/desktop/src/renderer/src/modules/command/commands/entry.tsx
+++ b/apps/desktop/src/renderer/src/modules/command/commands/entry.tsx
@@ -7,15 +7,19 @@ import { toast } from "sonner"
import { toggleShowAISummaryOnce } from "~/atoms/ai-summary"
import { toggleShowAITranslationOnce } from "~/atoms/ai-translation"
+import { AudioPlayer, getAudioPlayerAtomValue } from "~/atoms/player"
+import { useGeneralSettingKey } from "~/atoms/settings/general"
import {
getShowSourceContent,
toggleShowSourceContent,
useSourceContentModal,
} from "~/atoms/source-content"
import { useUserRole } from "~/atoms/user"
+import { toggleEntryReadability } from "~/hooks/biz/useEntryActions"
import { navigateEntry } from "~/hooks/biz/useNavigateEntry"
import { getRouteParams } from "~/hooks/biz/useRouteParams"
import { tipcClient } from "~/lib/client"
+import { parseHtml } from "~/lib/parse-html"
import { useActivationModal } from "~/modules/activation"
import { useGalleryModal } from "~/modules/entry-content/hooks"
import { useTipModal } from "~/modules/wallet/hooks"
@@ -100,6 +104,8 @@ export const useRegisterEntryCommands = () => {
const role = useUserRole()
const presentActivationModal = useActivationModal()
+ const voice = useGeneralSettingKey("voice")
+
useRegisterFollowCommand([
{
id: COMMAND_ID.entry.tip,
@@ -313,6 +319,43 @@ export const useRegisterEntryCommands = () => {
openGalleryModal(entryId)
},
},
+ {
+ id: COMMAND_ID.entry.tts,
+ label: t("entry_content.header.play_tts"),
+ icon: ,
+ run: async ({ entryId, entryContent }) => {
+ if (getAudioPlayerAtomValue().entryId === entryId) {
+ AudioPlayer.togglePlayAndPause()
+ } else {
+ const filePath = await tipcClient?.tts({
+ id: entryId,
+ text: parseHtml(entryContent).toText(),
+ voice,
+ })
+ if (filePath) {
+ AudioPlayer.mount({
+ type: "audio",
+ entryId,
+ src: `file://${filePath}`,
+ currentTime: 0,
+ })
+ }
+ }
+ },
+ },
+ {
+ id: COMMAND_ID.entry.readability,
+ label: t("entry_content.header.readability"),
+ icon: (props) => (
+
+ ),
+ run: async ({ entryId, entryUrl }) => {
+ return toggleEntryReadability({
+ id: entryId,
+ url: entryUrl,
+ })
+ },
+ },
])
useRegisterFollowCommand(
diff --git a/apps/desktop/src/renderer/src/modules/command/commands/id.ts b/apps/desktop/src/renderer/src/modules/command/commands/id.ts
index d2b50314f..9c7213f7b 100644
--- a/apps/desktop/src/renderer/src/modules/command/commands/id.ts
+++ b/apps/desktop/src/renderer/src/modules/command/commands/id.ts
@@ -13,6 +13,8 @@ export const COMMAND_ID = {
toggleAITranslation: "entry:toggle-ai-translation",
exportAsPDF: "entry:export-as-pdf",
imageGallery: "entry:image-gallery",
+ tts: "entry:tts",
+ readability: "entry:ability",
},
integration: {
saveToEagle: "integration:save-to-eagle",
diff --git a/apps/desktop/src/renderer/src/modules/command/commands/types.ts b/apps/desktop/src/renderer/src/modules/command/commands/types.ts
index c0613a29a..81bc3cf8d 100644
--- a/apps/desktop/src/renderer/src/modules/command/commands/types.ts
+++ b/apps/desktop/src/renderer/src/modules/command/commands/types.ts
@@ -70,6 +70,16 @@ export type ImageGalleryCommand = Command<{
fn: ({ entryId }) => void
}>
+export type TTSCommand = Command<{
+ id: typeof COMMAND_ID.entry.tts
+ fn: ({ entryId, entryContent }) => void
+}>
+
+export type ReadabilityCommand = Command<{
+ id: typeof COMMAND_ID.entry.readability
+ fn: ({ entryId, entryUrl }) => void
+}>
+
export type EntryCommand =
| TipCommand
| StarCommand
@@ -84,6 +94,8 @@ export type EntryCommand =
| ToggleAISummaryCommand
| ToggleAITranslationCommand
| ImageGalleryCommand
+ | TTSCommand
+ | ReadabilityCommand
// Settings commands
diff --git a/apps/desktop/src/renderer/src/modules/entry-content/actions/electron-actions.tsx b/apps/desktop/src/renderer/src/modules/entry-content/actions/electron-actions.tsx
deleted file mode 100644
index ea90ed5e0..000000000
--- a/apps/desktop/src/renderer/src/modules/entry-content/actions/electron-actions.tsx
+++ /dev/null
@@ -1,125 +0,0 @@
-import { ActionButton } from "@follow/components/ui/button/index.js"
-import { DividerVertical } from "@follow/components/ui/divider/index.js"
-import { FeedViewType, views } from "@follow/constants"
-import type { CombinedEntryModel } from "@follow/models/types"
-import { IN_ELECTRON } from "@follow/shared/constants"
-import { cn } from "@follow/utils/utils"
-import { noop } from "foxact/noop"
-import { useMemo, useState } from "react"
-import { useTranslation } from "react-i18next"
-
-import { AudioPlayer, getAudioPlayerAtomValue } from "~/atoms/player"
-import {
- isInReadability,
- ReadabilityStatus,
- useEntryInReadabilityStatus,
-} from "~/atoms/readability"
-import { useGeneralSettingKey } from "~/atoms/settings/general"
-import { shortcuts } from "~/constants/shortcuts"
-import { useEntryReadabilityToggle } from "~/hooks/biz/useEntryActions"
-import { tipcClient } from "~/lib/client"
-import { parseHtml } from "~/lib/parse-html"
-import type { FlatEntryModel } from "~/store/entry"
-import { useFeedById } from "~/store/feed"
-
-export const ElectronAdditionActions = IN_ELECTRON
- ? ({
- view = FeedViewType.Articles,
- entry,
- }: {
- view: FeedViewType
- entry?: FlatEntryModel | null
- }) => {
- const entryReadabilityStatus = useEntryInReadabilityStatus(entry?.entries.id)
-
- const { t } = useTranslation()
-
- const feed = useFeedById(entry?.feedId)
-
- const populatedEntry = useMemo(() => {
- if (!entry) return null
- if (!feed) return null
- return {
- ...entry,
- feeds: feed!,
- } as CombinedEntryModel
- }, [entry, feed])
-
- const readabilityToggle = useEntryReadabilityToggle({
- id: populatedEntry?.entries.id ?? "",
- url: populatedEntry?.entries.url ?? "",
- })
-
- const [ttsLoading, setTtsLoading] = useState(false)
- const voice = useGeneralSettingKey("voice")
-
- if (!populatedEntry) return null
-
- const items = [
- {
- key: "tts",
- name: t("entry_content.header.play_tts"),
- shortcut: shortcuts.entry.tts.key,
- className: ttsLoading ? "i-mgc-loading-3-cute-re animate-spin" : "i-mgc-voice-cute-re",
-
- disabled: !populatedEntry.entries.content,
- onClick: async () => {
- if (ttsLoading) return
- if (!populatedEntry.entries.content) return
- setTtsLoading(true)
- if (getAudioPlayerAtomValue().entryId === populatedEntry.entries.id) {
- AudioPlayer.togglePlayAndPause()
- } else {
- const filePath = await tipcClient?.tts({
- id: populatedEntry.entries.id,
- text: parseHtml(populatedEntry.entries.content).toText(),
- voice,
- })
- if (filePath) {
- AudioPlayer.mount({
- type: "audio",
- entryId: populatedEntry.entries.id,
- src: `file://${filePath}`,
- currentTime: 0,
- })
- }
- }
- setTtsLoading(false)
- },
- },
- {
- name: t("entry_content.header.readability"),
- className: cn(
- isInReadability(entryReadabilityStatus)
- ? `i-mgc-docment-cute-fi`
- : `i-mgc-docment-cute-re`,
- entryReadabilityStatus === ReadabilityStatus.WAITING ? `animate-pulse` : "",
- ),
- key: "readability",
- hide: views[view]!.wideMode || !populatedEntry.entries.url,
- active: isInReadability(entryReadabilityStatus),
- onClick: readabilityToggle,
- },
- ]
-
- if (items.length === 0) return null
- return (
- <>
- {items
- .filter((item) => !item.hide)
- .map((item) => (
-