From 0c9acf7a183d52af17fdcc31052bf3ac590ae73d Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Thu, 30 Jan 2025 19:50:54 +0800 Subject: [PATCH] fix: align sidebar trigger with nav bar --- src/utils/config/helper.ts | 2 +- src/utils/config/migrations/3.13.1.ts | 39 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/utils/config/migrations/3.13.1.ts diff --git a/src/utils/config/helper.ts b/src/utils/config/helper.ts index ac46372..fd8cefc 100644 --- a/src/utils/config/helper.ts +++ b/src/utils/config/helper.ts @@ -64,7 +64,7 @@ export const getDefaultConfigs: () => Config = () => ({ copySnippetButton: !isInGitHub, // disable on github.com intelligentToggle: null, icons: 'rich', - toggleButtonVerticalDistance: 124, // align with GitHub's navbar items + toggleButtonVerticalDistance: 64, // align with GitHub's navbar items recursiveToggleFolder: 'shift', searchMode: 'fuzzy', sidebarToggleMode: 'float', diff --git a/src/utils/config/migrations/3.13.1.ts b/src/utils/config/migrations/3.13.1.ts new file mode 100644 index 0000000..9adf1bb --- /dev/null +++ b/src/utils/config/migrations/3.13.1.ts @@ -0,0 +1,39 @@ +import { storageHelper } from 'utils/storageHelper' +import { Migration, onConfigOutdated } from '.' + +export const migration: Migration = { + version: '3.13.1', + async migrate(version) { + // disable copy snippet button for github.com + type ConfigBeforeMigrate = { + toggleButtonVerticalDistance: number + } + type ConfigAfterMigrate = { + toggleButtonVerticalDistance: number + } + + await onConfigOutdated(version, async configs => { + const key = 'platform_github.com' + const config = configs[key] + if ( + typeof config === 'object' && + config !== null && + 'toggleButtonVerticalDistance' in config + ) { + const configBeforeMigrate = config as ConfigBeforeMigrate + const { toggleButtonVerticalDistance, ...rest } = configBeforeMigrate + const previousDefaultToggleButtonVerticalDistance = 124 + const newDefaultToggleButtonVerticalDistance = 64 + if (toggleButtonVerticalDistance === previousDefaultToggleButtonVerticalDistance) { + const configAfterMigrate: ConfigAfterMigrate = { + ...rest, + toggleButtonVerticalDistance: newDefaultToggleButtonVerticalDistance, + } + await storageHelper.set({ + [key]: configAfterMigrate, + }) + } + } + }) + }, +}