feat: disable copy file button on github.com

This commit is contained in:
EnixCoda 2021-09-25 19:31:16 +08:00
parent 2542ccbeb7
commit 1d1724ae84
3 changed files with 36 additions and 2 deletions

View file

@ -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',

View file

@ -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,
})
}
}
})
},
}

View file

@ -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)