From cfe313f1d98c4e5e60cf2640b85d5cc9a551b088 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Sat, 4 Apr 2020 17:07:54 +0800 Subject: [PATCH] chore: revert declaring optional permissions --- src/manifest.json | 1 - src/platforms/index.ts | 21 +++++++++++---------- src/utils/configHelper.ts | 3 +-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/manifest.json b/src/manifest.json index a22116c..aefade9 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -7,7 +7,6 @@ "256": "icons/Gitako-256.png" }, "permissions": ["storage", "*://*.github.com/*", "*://*.sentry.io/*"], - "optional_permissions": [""], "web_accessible_resources": ["icons/vscode/*", "content.css"], "content_scripts": [ { diff --git a/src/platforms/index.ts b/src/platforms/index.ts index cb97c65..41d836f 100644 --- a/src/platforms/index.ts +++ b/src/platforms/index.ts @@ -2,28 +2,29 @@ import { dummyPlatformForTypeSafety } from './dummyPlatformForTypeSafety' import { Gitee } from './Gitee' import { GitHub } from './GitHub' -const platformsMap: Record<'GitHub' | 'Gitee', { platform: Platform; hosts: string[] }> = { - GitHub: { platform: GitHub, hosts: ['github.com'] }, - Gitee: { platform: Gitee, hosts: ['gitee.com'] }, +const platforms: { + [name: string]: Platform +} = { + GitHub: GitHub, + Gitee: Gitee, } function resolvePlatform() { - for (const { hosts, platform } of Object.values(platformsMap)) { - if (hosts.some(host => host === window.location.host || platform.resolveMeta())) { - return platform - } + for (const platform of Object.values(platforms)) { + if (platform.resolveMeta()) return platform } return dummyPlatformForTypeSafety } -export function getPlatformName() { - const keys = Object.keys(platformsMap) as (keyof typeof platformsMap)[] +function getPlatformName() { + const keys = Object.keys(platforms) as (keyof typeof platforms)[] for (const key of keys) { - if (platform === platformsMap[key].platform) return key + if (platform === platforms[key]) return key } } export const platform = resolvePlatform() +export const platformName = getPlatformName() export const errors = { SERVER_FAULT: 'Server Fault', diff --git a/src/utils/configHelper.ts b/src/utils/configHelper.ts index c311997..5051a93 100644 --- a/src/utils/configHelper.ts +++ b/src/utils/configHelper.ts @@ -1,4 +1,3 @@ -import { getPlatformName } from 'platforms' import * as storageHelper from 'utils/storageHelper' export type Config = { @@ -74,7 +73,7 @@ async function migrateConfig() { let platformName: string const prepareConfig = new Promise(async resolve => { await migrateConfig() - platformName = `platform_` + (await getPlatformName()) + platformName = `platform_` + platformName resolve() })