Skip to content

Commit

Permalink
Format src folder
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed Oct 12, 2022
1 parent dce37e2 commit 92314ce
Show file tree
Hide file tree
Showing 145 changed files with 1,834 additions and 1,902 deletions.
5 changes: 4 additions & 1 deletion src/client/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const compatibilityPatch = () => {
'https://live.bilibili.com/blackboard/dropdown-menu.html',
'https://www.bilibili.com/page-proxy/game-nav.html',
]
document.documentElement.classList.toggle('iframe', isIframe() && transparentFrames.some(matchUrlPattern))
document.documentElement.classList.toggle(
'iframe',
isIframe() && transparentFrames.some(matchUrlPattern),
)
})
fullyLoaded(() => {
select('meta[name=spm_prefix]').then(spm => {
Expand Down
7 changes: 3 additions & 4 deletions src/client/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ export const init = async () => {
const { getGeneralSettings } = await import('@/core/settings/helpers')
const { devMode } = getGeneralSettings()
if (devMode) {
const {
promiseLoadTime,
promiseResolveTime,
} = await import('@/core/performance/promise-trace')
const { promiseLoadTime, promiseResolveTime } = await import(
'@/core/performance/promise-trace'
)
const { logStats } = await import('@/core/performance/stats')
logStats('init block', promiseLoadTime)
logStats('init resolve', promiseResolveTime)
Expand Down
18 changes: 8 additions & 10 deletions src/components/SwitchOptions.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<template>
<div class="switch-options" :class="{ 'small-size': smallSize, 'grid': !popupMode }">
<div class="switch-options" :class="{ 'small-size': smallSize, grid: !popupMode }">
<template v-if="popupMode">
<VButton
ref="button"
@click="popupOpen = !popupOpen"
>
<VButton ref="button" @click="popupOpen = !popupOpen">
<VIcon
class="switch-icon"
icon="mdi-checkbox-marked-circle-outline"
Expand Down Expand Up @@ -51,9 +48,7 @@
</template>

<script lang="ts">
import {
VPopup, VButton, VIcon, CheckBox, RadioButton,
} from '@/ui'
import { VPopup, VButton, VIcon, CheckBox, RadioButton } from '@/ui'
import { getComponentSettings } from '../core/settings'
export default Vue.extend({
Expand Down Expand Up @@ -102,7 +97,10 @@ export default Vue.extend({
element.style.setProperty('--columns', columns.toString())
},
isDim(name: string) {
return (this.componentOptions[`switch-${name}`] && this.options.dimAt === 'checked') || this.options.dimAt === 'notChecked'
return (
(this.componentOptions[`switch-${name}`] && this.options.dimAt === 'checked') ||
this.options.dimAt === 'notChecked'
)
},
},
})
Expand All @@ -121,7 +119,7 @@ export default Vue.extend({
transform: scale(0.9);
}
.dim {
opacity: .5;
opacity: 0.5;
}
&-grid {
font-size: 12px;
Expand Down
16 changes: 3 additions & 13 deletions src/components/auto-update/ExtraOptions.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
<template>
<VButton
:disabled="disabled"
class="check-all-updates"
@click="checkUpdates()"
>
<VIcon
:size="16"
icon="mdi-cloud-sync-outline"
/>
<VButton :disabled="disabled" class="check-all-updates" @click="checkUpdates()">
<VIcon :size="16" icon="mdi-cloud-sync-outline" />
立即检查所有更新
</VButton>
</template>
<script lang="ts">
import { Toast } from '@/core/toast'
import {
VButton,
VIcon,
} from '@/ui'
import { VButton, VIcon } from '@/ui'
import { forceCheckUpdateAndReload } from './checker'
export default Vue.extend({
Expand Down
60 changes: 30 additions & 30 deletions src/components/auto-update/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,14 @@ export const checkUpdate = async (config: CheckUpdateConfig) => {
return filterNames.includes(itemName)
}
let updatedCount = 0
const updateItems = Object.entries(items)
.filter(([itemName, item]) => shouldUpdate(itemName) && Boolean(item.url))
const updateItems = Object.entries(items).filter(
([itemName, item]) => shouldUpdate(itemName) && Boolean(item.url),
)
const results = await Promise.allSettled(
updateItems.map(async ([itemName, item]) => {
const { url, lastUpdateCheck, alwaysUpdate } = item
const isDebugItem = alwaysUpdate && devMode
if (
!isDebugItem
&& now - lastUpdateCheck <= options.minimumDuration
&& !force
) {
if (!isDebugItem && now - lastUpdateCheck <= options.minimumDuration && !force) {
return `[${itemName}] 未超过更新间隔期, 已跳过`
}
if (updatedCount > maxCount && !force) {
Expand All @@ -69,9 +66,7 @@ export const checkUpdate = async (config: CheckUpdateConfig) => {
if (!isFeatureAcceptable(code)) {
return `[${itemName}] 版本不匹配, 取消更新`
}
const { installFeatureFromCode } = await import(
'@/core/install-feature'
)
const { installFeatureFromCode } = await import('@/core/install-feature')
const { message } = await installFeatureFromCode(code, url)
item.lastUpdateCheck = Number(new Date())
updatedCount++
Expand Down Expand Up @@ -114,39 +109,42 @@ export const checkStylesUpdate: CheckSingleTypeUpdate = async config => {
})
}

const reload = <T extends any[]> (method: (...args: T) => Promise<any>) => async (...args: T) => {
await method(...args)
window.location.reload()
}
const checkByName = (method: CheckSingleTypeUpdate) => reload(
async (...itemNames: string[]) => {
const reload =
<T extends any[]>(method: (...args: T) => Promise<any>) =>
async (...args: T) => {
await method(...args)
window.location.reload()
}
const checkByName = (method: CheckSingleTypeUpdate) =>
reload(async (...itemNames: string[]) => {
await method({ filterNames: itemNames, force: true })
},
) as (...itemNames: string[]) => Promise<void>
}) as (...itemNames: string[]) => Promise<void>

export const checkAllUpdate = async (config: CheckSingleTypeUpdateConfig) => {
const { options } = getComponentSettings(name)
const console = useScopedConsole('检查所有更新')
console.log('开始检查更新')
const updateMessages = [
await checkComponentsUpdate(config) || '暂无组件更新',
await checkPluginsUpdate(config) || '暂无插件更新',
await checkStylesUpdate(config) || '暂无样式更新',
(await checkComponentsUpdate(config)) || '暂无组件更新',
(await checkPluginsUpdate(config)) || '暂无插件更新',
(await checkStylesUpdate(config)) || '暂无样式更新',
]
options.lastUpdateCheck = Number(new Date())
options.lastInstalledVersion = meta.version
console.groupCollapsed('完成更新检查')
updateMessages.forEach(message => console.log(message))
console.groupEnd()
}
export const silentCheckUpdate = () => checkAllUpdate({
maxCount: getComponentSettings(name).options.maxUpdateCount,
})
export const silentCheckUpdate = () =>
checkAllUpdate({
maxCount: getComponentSettings(name).options.maxUpdateCount,
})
export const silentCheckUpdateAndReload = reload(silentCheckUpdate)

export const forceCheckUpdate = () => checkAllUpdate({
force: true,
})
export const forceCheckUpdate = () =>
checkAllUpdate({
force: true,
})
export const forceCheckUpdateAndReload = reload(forceCheckUpdate)

export const checkComponentsByName = checkByName(checkComponentsUpdate)
Expand All @@ -156,9 +154,11 @@ export const checkLastFeature = async () => {
const { options } = getComponentSettings(name)
const items = Object.values(options.urls)
.flatMap(it => Object.entries(it))
.map(([key, record]: [string, UpdateCheckItem]) => (
{ key, time: record.lastUpdateCheck, item: record }
))
.map(([key, record]: [string, UpdateCheckItem]) => ({
key,
time: record.lastUpdateCheck,
item: record,
}))
.sort(descendingSort(it => it.time))
const [firstItem] = items
if (!firstItem) {
Expand Down
86 changes: 37 additions & 49 deletions src/components/auto-update/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { ComponentEntry, componentsTags } from '@/components/types'
import { meta } from '@/core/meta'
import {
getComponentSettings,
getGeneralSettings,
isUserComponent,
} from '@/core/settings'
import { getComponentSettings, getGeneralSettings, isUserComponent } from '@/core/settings'
import { isIframe } from '@/core/utils'
import { Version } from '@/core/version'
import {
Expand Down Expand Up @@ -64,9 +60,7 @@ const optionsMetadata = defineOptionsMetadata({

type Options = OptionsOfMetadata<typeof optionsMetadata>

const entry: ComponentEntry<Options> = async ({
settings: { options: opt },
}) => {
const entry: ComponentEntry<Options> = async ({ settings: { options: opt } }) => {
if (isIframe()) {
return checkerMethods
}
Expand Down Expand Up @@ -112,9 +106,7 @@ export const component = defineComponentMetadata({
after: (_, url: string, metadata: { name: string }) => {
// console.log('hook', `user${lodash.startCase(type)}.add`, metadata.name, url)
const { options } = getComponentSettings('autoUpdate')
const existingItem = options.urls[type][
metadata.name
] as UpdateCheckItem
const existingItem = options.urls[type][metadata.name] as UpdateCheckItem
if (!existingItem) {
options.urls[type][metadata.name] = {
url,
Expand All @@ -140,36 +132,33 @@ export const component = defineComponentMetadata({
},
})
})
addData(
'settingsPanel.componentActions',
(actions: ComponentAction[]) => {
const { options } = getComponentSettings<AutoUpdateOptions>('autoUpdate')
actions.push(metadata => {
const item = options.urls.components[metadata.name]
if (!item) {
return undefined
}
return {
name: 'checkUpdate',
displayName: '检查更新',
icon: isLocalItem(item.url)
? 'mdi-file-download-outline'
: 'mdi-cloud-download-outline',
visible: isUserComponent(metadata),
title: item.url,
action: async () => {
const { Toast } = await import('@/core/toast')
const toast = Toast.info('检查更新中...', '检查更新')
toast.message = await checkComponentsUpdate({
filterNames: [metadata.name],
force: true,
})
toast.duration = 3000
},
}
})
},
)
addData('settingsPanel.componentActions', (actions: ComponentAction[]) => {
const { options } = getComponentSettings<AutoUpdateOptions>('autoUpdate')
actions.push(metadata => {
const item = options.urls.components[metadata.name]
if (!item) {
return undefined
}
return {
name: 'checkUpdate',
displayName: '检查更新',
icon: isLocalItem(item.url)
? 'mdi-file-download-outline'
: 'mdi-cloud-download-outline',
visible: isUserComponent(metadata),
title: item.url,
action: async () => {
const { Toast } = await import('@/core/toast')
const toast = Toast.info('检查更新中...', '检查更新')
toast.message = await checkComponentsUpdate({
filterNames: [metadata.name],
force: true,
})
toast.duration = 3000
},
}
})
})

const icon = 'mdi-cloud-sync-outline'
addData('launchBar.actions', (actions: LaunchBarActionProvider[]) => {
Expand All @@ -193,12 +182,14 @@ export const component = defineComponentMetadata({
addData('settingsPanel.searchBarActions', (actions: SearchBarAction[]) => {
actions.unshift({
key: 'updateFeatures',
title: ({ selectedComponents }) => (selectedComponents.length > 0 ? '更新所选组件' : '检查所有更新'),
title: ({ selectedComponents }) =>
selectedComponents.length > 0 ? '更新所选组件' : '检查所有更新',
icon: 'mdi-cloud-download-outline',
run: async context => {
const confirmMessage = context.selectedComponents.length > 0
? `确定要更新所选的 ${context.selectedComponents.length} 个组件吗?`
: '确定要检查所有更新吗?'
const confirmMessage =
context.selectedComponents.length > 0
? `确定要更新所选的 ${context.selectedComponents.length} 个组件吗?`
: '确定要检查所有更新吗?'
if (!window.confirm(confirmMessage)) {
return
}
Expand Down Expand Up @@ -237,10 +228,7 @@ export const component = defineComponentMetadata({
description: 'Check Last Update',
action: async () => {
const { Toast } = await import('@/core/toast')
const toast = Toast.info(
'正在检查更新...',
'检查最近更新的功能',
)
const toast = Toast.info('正在检查更新...', '检查最近更新的功能')
await checkLastFeature()
toast.close()
},
Expand Down
9 changes: 4 additions & 5 deletions src/components/auto-update/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export interface CheckUpdateConfig extends CheckSingleTypeUpdateConfig {
// installer: (code: string) => Promise<{ message: string }>
}
export const isLocalItem = (url: string) => localhost.test(url)
export const defaultExistPredicate = (itemName: string) => (
settings.userComponents[itemName] !== undefined
|| settings.userPlugins[itemName] !== undefined
|| settings.userStyles[itemName] !== undefined
)
export const defaultExistPredicate = (itemName: string) =>
settings.userComponents[itemName] !== undefined ||
settings.userPlugins[itemName] !== undefined ||
settings.userStyles[itemName] !== undefined
3 changes: 1 addition & 2 deletions src/components/built-in-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ export const getBuiltInComponents = (): ComponentMetadata[] => [
NotifyNewVersion,
]

export const isBuiltInComponent = (name: string) => (
export const isBuiltInComponent = (name: string) =>
getBuiltInComponents().some(c => c.name === name)
)
Loading

0 comments on commit 92314ce

Please sign in to comment.