Skip to content

Commit 1e9d20e

Browse files
committed
feat(mobile): streamline settings management and sync functionality
- Updated general and UI settings to utilize shared default settings from the new shared package. - Introduced a new sync queue for managing local and remote settings synchronization. - Removed outdated settings interfaces that are now integrated into the shared package. - Enhanced event handling for setting changes to improve responsiveness and data consistency. Signed-off-by: Innei <tukon479@gmail.com>
1 parent 0559ff1 commit 1e9d20e

9 files changed

Lines changed: 335 additions & 89 deletions

File tree

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,18 @@
1-
import type { GeneralSettings } from "@/src/interfaces/settings/general"
1+
import { defaultGeneralSettings } from "@follow/shared/src/settings/defaults"
2+
import type { GeneralSettings } from "@follow/shared/src/settings/interface"
3+
24
import { getDeviceLanguage } from "@/src/lib/i18n"
35

46
import { createSettingAtom } from "./internal/helper"
57

6-
const createDefaultSettings = (): GeneralSettings => ({
7-
// App
8-
language: getDeviceLanguage(),
9-
10-
// Action
11-
summary: false,
12-
translation: false,
13-
actionLanguage: getDeviceLanguage(),
14-
15-
// Data control
16-
17-
sendAnonymousData: true,
18-
19-
autoGroup: true,
20-
21-
// view
22-
unreadOnly: true,
23-
// mark unread
24-
scrollMarkUnread: true,
25-
26-
renderMarkUnread: false,
27-
// UX
28-
groupByDate: true,
29-
autoExpandLongSocialMedia: false,
30-
31-
// Secure
32-
jumpOutLinkWarn: true,
33-
// TTS
34-
voice: "en-US-AndrewMultilingualNeural",
35-
36-
// Content
37-
openLinksInApp: true,
38-
})
8+
const createDefaultSettings = (): GeneralSettings => {
9+
const deviceLanguage = getDeviceLanguage()
10+
return {
11+
...defaultGeneralSettings,
12+
actionLanguage: deviceLanguage,
13+
language: deviceLanguage,
14+
}
15+
}
3916

4017
export const {
4118
useSettingKey: useGeneralSettingKey,
@@ -49,3 +26,11 @@ export const {
4926

5027
settingAtom: __generalSettingAtom,
5128
} = createSettingAtom("general", createDefaultSettings)
29+
30+
export const generalServerSyncWhiteListKeys: (keyof GeneralSettings)[] = [
31+
"sendAnonymousData",
32+
"language",
33+
"appLaunchOnStartup",
34+
"dataPersist",
35+
"voice",
36+
]

apps/mobile/src/atoms/settings/internal/helper.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useRefValue } from "@follow/hooks"
22
import { createAtomHooks } from "@follow/utils"
3+
import { EventBus } from "@follow/utils/src/event-bus"
34
import type { SetStateAction, WritableAtom } from "jotai"
45
import { atom as jotaiAtom, useAtomValue } from "jotai"
56
import { atomWithStorage, selectAtom } from "jotai/utils"
@@ -116,6 +117,11 @@ export const createSettingAtom = <T extends object>(
116117
value: ReturnType<typeof getSettings>[K],
117118
) => {
118119
const updated = Date.now()
120+
121+
EventBus.dispatch("SETTING_CHANGE_EVENT", {
122+
key: key as "general" | "ui",
123+
payload: value,
124+
})
119125
setSettings({
120126
...getSettings(),
121127
[key]: value,
Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
1-
import type { UISettings } from "@/src/interfaces/settings/ui"
1+
import { defaultUISettings } from "@follow/shared/src/settings/defaults"
2+
import type { UISettings } from "@follow/shared/src/settings/interface"
23

34
import { createSettingAtom } from "./internal/helper"
45

5-
export const createDefaultSettings = (): UISettings => ({
6-
// Subscription
7-
8-
hideExtraBadge: false,
9-
10-
subscriptionShowUnreadCount: true,
11-
thumbnailRatio: "square",
12-
13-
// Content
14-
readerRenderInlineStyle: false,
15-
codeHighlightThemeLight: "github-light",
16-
codeHighlightThemeDark: "github-dark",
17-
guessCodeLanguage: true,
18-
hideRecentReader: false,
19-
customCSS: "",
20-
})
6+
export const createDefaultSettings = (): UISettings => defaultUISettings
217

228
export const {
239
useSettingKey: useUISettingKey,
@@ -30,3 +16,10 @@ export const {
3016
useSettingValue: useUISettingValue,
3117
settingAtom: __uiSettingAtom,
3218
} = createSettingAtom("ui", createDefaultSettings)
19+
20+
export const uiServerSyncWhiteListKeys: (keyof UISettings)[] = [
21+
"uiFontFamily",
22+
"readerFontFamily",
23+
"opaqueSidebar",
24+
// "customCSS",
25+
]

apps/mobile/src/initialize/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { tracker } from "@follow/tracker"
22
import { nativeApplicationVersion } from "expo-application"
33

44
import { initializeDb } from "../database"
5+
import { settingSyncQueue } from "../modules/settings/sync-queue"
56
import { initAnalytics } from "./analytics"
67
import { initializeAppCheck } from "./app-check"
78
import { initCrashlytics } from "./crashlytics"
@@ -29,6 +30,11 @@ export const initializeApp = async () => {
2930
await apm("initializeAppCheck", initializeAppCheck)
3031
await apm("initializePlayer", initializePlayer)
3132

33+
apm("setting sync", () => {
34+
settingSyncQueue.init()
35+
settingSyncQueue.syncLocal()
36+
})
37+
3238
await initAnalytics()
3339
const loadingTime = Date.now() - now
3440
tracker.appInit({

apps/mobile/src/interfaces/settings/general.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

apps/mobile/src/interfaces/settings/ui.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)