diff --git a/package.json b/package.json index da15fe30..779cb9ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meo-assistant-arknights", - "version": "2.0.0-alpha.9", + "version": "2.0.0-alpha.10", "main": "dist/main/index.cjs", "author": "_ChingC ", "templateBy": "草鞋没号 <308487730@qq.com>", @@ -42,6 +42,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^6.0.0", "eslint-plugin-vue": "^8.5.0", + "exponential-backoff": "^3.1.0", "less": "^4.1.2", "lodash": "^4.17.21", "naive-ui": "^2.30.0", diff --git a/packages/main/utils/debug.ts b/packages/main/utils/debug.ts index f09a9eba..09aed23a 100644 --- a/packages/main/utils/debug.ts +++ b/packages/main/utils/debug.ts @@ -12,7 +12,7 @@ function useDebug (window: BrowserWindow): void { // Bypass CORS window.webContents.session.webRequest.onBeforeSendHeaders( { - urls: ['https://prts.wiki/*', 'https://maa.alisaqaq.moe/*'] + urls: ['https://prts.wiki/*', 'https://maa.alisaqaq.moe/*', 'https://penguin-stats.io/*'] }, (details, callback) => { details.requestHeaders.Origin = new URL(details.url).origin @@ -21,7 +21,7 @@ function useDebug (window: BrowserWindow): void { ) window.webContents.session.webRequest.onHeadersReceived( { - urls: ['https://prts.wiki/*', 'https://maa.alisaqaq.moe/*'] + urls: ['https://prts.wiki/*', 'https://maa.alisaqaq.moe/*', 'https://penguin-stats.io/*'] }, (details, callback) => { const corsHeader = { 'access-control-allow-origin': '*' } diff --git a/packages/main/utils/logger.ts b/packages/main/utils/logger.ts index 136a92a2..b2ec5d0f 100644 --- a/packages/main/utils/logger.ts +++ b/packages/main/utils/logger.ts @@ -23,7 +23,7 @@ class Logger { this.log_file_ = createWriteStream( this.log_file_path_, - { flags: 'w' } + { flags: 'a' } ) this.main_.attachTransport({ diff --git a/packages/main/windowManager/theme.ts b/packages/main/windowManager/theme.ts index 44f7c8cf..43135d6f 100644 --- a/packages/main/windowManager/theme.ts +++ b/packages/main/windowManager/theme.ts @@ -19,6 +19,9 @@ export default function useTheme (window: BrowserWindow): void { effect: 'acrylic' }) } + if (is.macos && storage.get('theme.acrylic')) { + window.setVibrancy(isDark ? 'dark' : 'light') + } }) ipcMainHandle('main.WindowManager:loaded', async (event) => { diff --git a/packages/renderer/src/api/ApiService.ts b/packages/renderer/src/api/ApiService.ts index d3cdc992..0e1f1e1c 100644 --- a/packages/renderer/src/api/ApiService.ts +++ b/packages/renderer/src/api/ApiService.ts @@ -1,25 +1,29 @@ import axios from 'axios' import type { AxiosInstance, AxiosRequestConfig } from 'axios' -import version from '@/hooks/caller/version' import _ from 'lodash' +import useSettingStore from '@/store/settings' -const getCoreVersion = async (): Promise => { - const coreVersion = await version.core() - return coreVersion !== null ? `(core v${coreVersion})` : '(without core)' +const getUA = (): string => { + const settingStore = useSettingStore() + const coreVersion = settingStore.version.core.current + const uiVersion = `v${settingStore.version.ui.current ?? ''}` + const versionString = coreVersion ? `(core v${coreVersion})` : '(without core)' + return `MeoAssistantArknights ${uiVersion} ${versionString}` } class ApiService { constructor (baseUrl: string) { this._instance = axios.create({ baseURL: baseUrl, - timeout: 5000, - headers: { - 'Client-Version': ApiService._ua - } + timeout: 5000 }) this._instance.interceptors.request.use( (request) => { + request.headers = { + ...request.headers, + 'User-Agent': getUA() + } return request }, async (error) => { @@ -40,7 +44,15 @@ class ApiService { async get(url: string, config?: AxiosRequestConfig): Promise { const response = await this._instance.get(url, config) if (_.isError(response)) { - return response + throw response + } + return response.data + } + + async post(url: string, data?: any, config?: AxiosRequestConfig): Promise { + const response = await this._instance.post(url, data, config) + if (_.isError(response)) { + throw response } return response.data } @@ -49,14 +61,7 @@ class ApiService { return this._instance.defaults.baseURL } - static updateUA = async () => { - ApiService._ua = `MeoAssistantArknights v${await version.ui()} ${await getCoreVersion()}` - }; - private readonly _instance: AxiosInstance; - private static _ua: string; } -ApiService.updateUA() - export default ApiService diff --git a/packages/renderer/src/api/penguin/index.ts b/packages/renderer/src/api/penguin/index.ts new file mode 100644 index 00000000..850f6511 --- /dev/null +++ b/packages/renderer/src/api/penguin/index.ts @@ -0,0 +1,49 @@ +import type { AxiosRequestHeaders, AxiosResponse } from 'axios' +import { backOff, IBackOffOptions } from 'exponential-backoff' +import useSettingStore from '@/store/settings' +import service from './service' + +interface DropInfo { + dropType: string + itemId: string + quantity: number +} + +export interface DropReport { + drops: DropInfo + stageId: string + server: string +} + +const backOffOptions: Partial = { + numOfAttempts: 5, + timeMultiple: 2, + jitter: 'full', + maxDelay: 60 * 1000, + startingDelay: 200, + retry (response: AxiosResponse /* Error Response */) { + if (response.status /* No Timeout */ && + Math.floor(response.status / 100) === 4/* Client Error */) { + return false + } + return true + } +} + +export async function postDrop (report: DropReport): Promise { + const settingStore = useSettingStore() + const reportId = settingStore.reportId + const _report = { + ...report, + source: 'MeoAssistant', + version: settingStore.version.core.current + } + + const headers: AxiosRequestHeaders = + reportId ? { Authorization: `PenguinID ${reportId}` } : {} + + return await backOff( + () => service.post('/PenguinStats/api/v2/report', _report, { headers }), + backOffOptions + ) +} diff --git a/packages/renderer/src/api/penguin/service.ts b/packages/renderer/src/api/penguin/service.ts new file mode 100644 index 00000000..33f23970 --- /dev/null +++ b/packages/renderer/src/api/penguin/service.ts @@ -0,0 +1,5 @@ +import ApiService from '@/api/ApiService' + +const service = new ApiService('https://penguin-stats.io') + +export default service diff --git a/packages/renderer/src/components/Setting/About/Index.vue b/packages/renderer/src/components/Setting/About/Index.vue index 5276041a..f2555269 100644 --- a/packages/renderer/src/components/Setting/About/Index.vue +++ b/packages/renderer/src/components/Setting/About/Index.vue @@ -1,46 +1,87 @@ diff --git a/packages/renderer/src/components/Setting/Clear/Index.vue b/packages/renderer/src/components/Setting/Clear/Index.vue new file mode 100644 index 00000000..6a6ad360 --- /dev/null +++ b/packages/renderer/src/components/Setting/Clear/Index.vue @@ -0,0 +1,69 @@ + + + diff --git a/packages/renderer/src/components/Setting/Clear/index.ts b/packages/renderer/src/components/Setting/Clear/index.ts new file mode 100644 index 00000000..205a149f --- /dev/null +++ b/packages/renderer/src/components/Setting/Clear/index.ts @@ -0,0 +1,2 @@ +import Index from './Index.vue' +export default Index diff --git a/packages/renderer/src/components/Task/TaskCard.vue b/packages/renderer/src/components/Task/TaskCard.vue index 589918c2..12683439 100644 --- a/packages/renderer/src/components/Task/TaskCard.vue +++ b/packages/renderer/src/components/Task/TaskCard.vue @@ -93,12 +93,11 @@ const cardRef: Ref = ref(null) const cardHeight = ref('120px') const handleWindowResize = _.throttle(() => { - if (!cardRef.value || props.isCollapsed) { + if (!cardRef.value || !props.isCollapsed) { cardHeight.value = '120px' return } const { clientWidth } = cardRef.value - console.log(cardRef) cardHeight.value = `${clientWidth * (1 - 0.618)}px` }, 1000 / 30) @@ -111,8 +110,7 @@ onUnmounted(() => { window.removeEventListener('resize', handleWindowResize) }) -const isCollapsed = computed(() => props.isCollapsed) -watch(isCollapsed, handleWindowResize) +watch(() => props.isCollapsed, handleWindowResize) provide( 'configurationDisabled', diff --git a/packages/renderer/src/hooks/events/callback.ts b/packages/renderer/src/hooks/events/callback.ts index 6b2e68bf..c9de9dbc 100644 --- a/packages/renderer/src/hooks/events/callback.ts +++ b/packages/renderer/src/hooks/events/callback.ts @@ -9,6 +9,8 @@ import type { MessageReactive } from 'naive-ui' import logger from '@/hooks/caller/logger' import _ from 'lodash' +import { postDrop } from '@/api/penguin' + const messages: Record = {} export default function useCallbackEvents (): void { @@ -128,8 +130,51 @@ export default function useCallbackEvents (): void { details } = data taskStore.mergeTaskResult(uuid.trim(), taskid, { - fightInfo: [details] + fightInfo: [{ + ...details, + reported: false, + report_error: false + }] }) + const task = taskStore.getTask(uuid.trim(), t => t.task_id === taskid) + if (task) { + const resultIndex = task.results.fightInfo.length - 1 + const vaildDropType = [ + 'NORMAL_DROP', + 'SPECIAL_DROP', + 'EXTRA_DROP', + 'FURNITURE' + ] + if (task.configurations.report_to_penguin) { + const drops = details.drops + .filter((drop: any) => vaildDropType.includes(drop.dropType)) + .filter((drop: any) => !drop.itemId.includes('token')) + .map((drop: any) => { + _.unset(drop, 'itemName') + return drop + }) + const report = { + stageId: details.stage.stageId, + server: task.configurations.server as string, + drops + } + if (drops.length > 0) { + postDrop(report) + .then(response => { + task.results.fightInfo[resultIndex].reported = true + const reportId = response.headers['X-Penguin-Set-PenguinID'] + if (reportId) { + settingStore.reportId = reportId + } + }) + .catch(error => { + task.results.fightInfo[resultIndex].report_error = true + window.$message.error('上报企鹅物流失败') + logger.error('上报企鹅物流失败', error) + }) + } + } + } break } case 'PenguinId': { diff --git a/packages/renderer/src/layouts/pages/Setting.vue b/packages/renderer/src/layouts/pages/Setting.vue index b8b845ad..1a9147de 100644 --- a/packages/renderer/src/layouts/pages/Setting.vue +++ b/packages/renderer/src/layouts/pages/Setting.vue @@ -11,6 +11,7 @@ import Developer from '@/components/Setting/Developer' import Version from '@/components/Setting/Version' import Appearance from '@/components/Setting/Appearance' import About from '@/components/Setting/About' +import Clear from '@/components/Setting/Clear/Index.vue' const settingStore = useSettingStore() @@ -74,6 +75,7 @@ function handleChangeLocale (locale: Locale) { +

diff --git a/packages/renderer/src/layouts/sidebars/Setting.vue b/packages/renderer/src/layouts/sidebars/Setting.vue index 3a1a3432..4e3405d1 100644 --- a/packages/renderer/src/layouts/sidebars/Setting.vue +++ b/packages/renderer/src/layouts/sidebars/Setting.vue @@ -33,6 +33,10 @@ import { NButton, NIcon, NAnchor, NAnchorLink } from 'naive-ui' title="外观" href="#appearance" /> +