diff --git a/src/utils/config/helper.ts b/src/utils/config/helper.ts index 001b1be..24c67b7 100644 --- a/src/utils/config/helper.ts +++ b/src/utils/config/helper.ts @@ -50,7 +50,7 @@ export const defaultConfigs: Config = { shortcut: undefined, accessToken: '', compressSingletonFolder: true, - copyFileButton: true, + copyFileButton: platformStorageKey !== 'platform_github.com', // false when on github.com, copySnippetButton: platformStorageKey !== 'platform_github.com', // false when on github.com intelligentToggle: null, icons: 'rich', diff --git a/src/utils/config/migrations/3.5.0.ts b/src/utils/config/migrations/3.5.0.ts new file mode 100644 index 0000000..1c25b3c --- /dev/null +++ b/src/utils/config/migrations/3.5.0.ts @@ -0,0 +1,33 @@ +import { storageHelper } from 'utils/storageHelper' +import { Migration, onConfigOutdated } from '.' + +export const migration: Migration = { + version: '3.5.0', + async migrate(version) { + // disable copy snippet button for github.com + type ConfigBeforeMigrate = { + copyFileButton: boolean + } + type ConfigAfterMigrate = { + copyFileButton: boolean + } + + await onConfigOutdated(version, async configs => { + const key = 'platform_github.com' + const config = configs[key] + if (typeof config === 'object' && config !== null && 'copyFileButton' in config) { + const configBeforeMigrate: ConfigBeforeMigrate = config + const { copyFileButton, ...rest } = configBeforeMigrate + if (copyFileButton) { + const configAfterMigrate: ConfigAfterMigrate = { + ...rest, + copyFileButton: false, + } + await storageHelper.set({ + [key]: configAfterMigrate, + }) + } + } + }) + }, +} diff --git a/src/utils/config/migrations/index.ts b/src/utils/config/migrations/index.ts index 53a9dae..276c197 100644 --- a/src/utils/config/migrations/index.ts +++ b/src/utils/config/migrations/index.ts @@ -4,6 +4,7 @@ import { migration as v1v0v1 } from './1.0.1' import { migration as v1v3v4 } from './1.3.4' import { migration as v2v6v0 } from './2.6.0' import { migration as v3v0v0 } from './3.0.0' +import { migration as v3v5v0 } from './3.5.0' export type Migration = { version: string @@ -11,7 +12,7 @@ export type Migration = { } export async function migrateConfig() { - const migrations: Migration[] = [v1v0v1, v1v3v4, v2v6v0, v3v0v0] + const migrations: Migration[] = [v1v0v1, v1v3v4, v2v6v0, v3v0v0, v3v5v0] for (const { version, migrate } of migrations) { await migrate(version)