Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6dc58b8

Browse files
committedMar 26, 2025··
feat(migrates): implement migration system with versioning and initial migration logic
- Added a helper function to define migration options. - Created the first migration (v1) to enable enhanced settings based on default values. - Updated migration handling in the index file to track and apply migrations as needed. This enhancement establishes a structured approach to manage application migrations, improving maintainability and upgrade processes. Signed-off-by: Innei <tukon479@gmail.com>
1 parent 883d21a commit 6dc58b8

File tree

5 files changed

+81
-6
lines changed

5 files changed

+81
-6
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface DefineMigrationOptions {
2+
version: string
3+
migrate: () => void | Promise<void>
4+
}
5+
export const defineMigration = (options: DefineMigrationOptions) => {
6+
return options
7+
}

‎apps/desktop/src/renderer/src/initialize/migrates/index.ts

+27-4
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,50 @@ import { getStorageNS } from "@follow/utils/ns"
22

33
import { appLog } from "~/lib/log"
44

5+
import type { DefineMigrationOptions } from "./helper"
6+
import { v1 } from "./v/v1"
7+
58
const appVersionKey = getStorageNS("app_version")
9+
const migrationVersionKey = getStorageNS("migration_version")
610

711
declare global {
812
interface Window {
913
__app_is_upgraded__: boolean
1014
}
1115
}
1216

17+
const getMigrationVersions = () => {
18+
try {
19+
const versions = localStorage.getItem(migrationVersionKey) || "[]"
20+
return new Set(JSON.parse(versions))
21+
} catch {
22+
return new Set()
23+
}
24+
}
25+
const migrations: DefineMigrationOptions[] = [v1]
1326
export const doMigration = async () => {
27+
const migrationVersions = getMigrationVersions()
28+
29+
for (const migration of migrations) {
30+
if (migrationVersions.has(migration.version)) continue
31+
32+
appLog(`Migrating ${migration.version}...`)
33+
await migration.migrate()
34+
migrationVersions.add(migration.version)
35+
}
36+
37+
localStorage.setItem(migrationVersionKey, JSON.stringify(Array.from(migrationVersions)))
38+
39+
// AppVersion logic
1440
const lastVersion = localStorage.getItem(appVersionKey) || APP_VERSION
1541
localStorage.setItem(appVersionKey, APP_VERSION)
1642

17-
if (lastVersion === APP_VERSION) return
18-
1943
const lastVersionParts = lastVersion.split("-")
2044
const lastVersionMajorMinor = lastVersionParts[0]
2145
const currentVersionMajorMinor = APP_VERSION.split("-")[0]
46+
if (lastVersion === APP_VERSION) return
2247
if (lastVersionMajorMinor === currentVersionMajorMinor) return
2348

24-
// NOTE: Add migration logic here
25-
2649
window.__app_is_upgraded__ = true
2750
appLog(`Upgrade from ${lastVersion} to ${APP_VERSION}`)
2851
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { defaultSettings } from "@follow/shared/settings/defaults"
2+
3+
import { getGeneralSettings, setGeneralSetting } from "~/atoms/settings/general"
4+
import { getUISettings } from "~/atoms/settings/ui"
5+
6+
import { defineMigration } from "../helper"
7+
8+
export const v1 = defineMigration({
9+
version: "v1",
10+
migrate: () => {
11+
const settings = getGeneralSettings()
12+
const uiSettings = getUISettings()
13+
14+
let enabledEnhancedSettings = false
15+
for (const key in defaultSettings.ui) {
16+
const defaultValue = defaultSettings.ui[key]
17+
const currentValue = uiSettings[key]
18+
if (defaultValue !== currentValue) {
19+
enabledEnhancedSettings = true
20+
break
21+
}
22+
}
23+
for (const key in defaultSettings.general) {
24+
const defaultValue = defaultSettings.general[key]
25+
const currentValue = settings[key]
26+
if (defaultValue !== currentValue) {
27+
enabledEnhancedSettings = true
28+
break
29+
}
30+
}
31+
setGeneralSetting("enhancedSettings", enabledEnhancedSettings)
32+
},
33+
})

‎apps/desktop/src/renderer/src/modules/settings/modal/content.mobile.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ const Content = (props: { tab: string }) => {
4848
ns="settings"
4949
i18nKey="common.give_star"
5050
components={{
51-
Link: <a href={`${PKG.repository.url}`} className="text-accent" target="_blank" />,
51+
Link: (
52+
<a
53+
href={`${PKG.repository.url}`}
54+
className="text-accent font-semibold"
55+
target="_blank"
56+
/>
57+
),
5258
HeartIcon: <i className="i-mgc-heart-cute-fi" />,
5359
}}
5460
/>

‎apps/desktop/src/renderer/src/modules/settings/modal/content.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ const Content = () => {
5959
ns="settings"
6060
i18nKey="common.give_star"
6161
components={{
62-
Link: <a href={`${repository.url}`} className="text-accent" target="_blank" />,
62+
Link: (
63+
<a
64+
href={`${repository.url}`}
65+
className="text-accent font-semibold"
66+
target="_blank"
67+
/>
68+
),
6369
HeartIcon: <i className="i-mgc-heart-cute-fi" />,
6470
}}
6571
/>

0 commit comments

Comments
 (0)
Please sign in to comment.