Skip to content

Commit

Permalink
release: v2.0.0-alpha.10
Browse files Browse the repository at this point in the history
  • Loading branch information
ChingCdesu authored Aug 31, 2022
2 parents 299b1b9 + 25a72de commit c06b7ae
Show file tree
Hide file tree
Showing 16 changed files with 289 additions and 59 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"templateBy": "草鞋没号 <[email protected]>",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/main/utils/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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': '*' }
Expand Down
2 changes: 1 addition & 1 deletion packages/main/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Logger {

this.log_file_ = createWriteStream(
this.log_file_path_,
{ flags: 'w' }
{ flags: 'a' }
)

this.main_.attachTransport({
Expand Down
3 changes: 3 additions & 0 deletions packages/main/windowManager/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
37 changes: 21 additions & 16 deletions packages/renderer/src/api/ApiService.ts
Original file line number Diff line number Diff line change
@@ -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<string> => {
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) => {
Expand All @@ -40,7 +44,15 @@ class ApiService {
async get<T>(url: string, config?: AxiosRequestConfig): Promise<T | Error> {
const response = await this._instance.get(url, config)
if (_.isError(response)) {
return response
throw response
}
return response.data
}

async post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {
const response = await this._instance.post(url, data, config)
if (_.isError(response)) {
throw response
}
return response.data
}
Expand All @@ -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
49 changes: 49 additions & 0 deletions packages/renderer/src/api/penguin/index.ts
Original file line number Diff line number Diff line change
@@ -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<IBackOffOptions> = {
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<AxiosResponse> {
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<AxiosResponse>('/PenguinStats/api/v2/report', _report, { headers }),
backOffOptions
)
}
5 changes: 5 additions & 0 deletions packages/renderer/src/api/penguin/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ApiService from '@/api/ApiService'

const service = new ApiService('https://penguin-stats.io')

export default service
107 changes: 74 additions & 33 deletions packages/renderer/src/components/Setting/About/Index.vue
Original file line number Diff line number Diff line change
@@ -1,46 +1,87 @@
<script setup lang="ts">
import { NButton, NSpace } from 'naive-ui'
import { onMounted, ref } from 'vue'
import { NButton, NSpace, NText, NCollapseTransition, NList, NListItem, NTag } from 'naive-ui'
const loading = ref(false)
const cacheInfo = ref({
log: 0,
download: 0
})
function formatBytes (bytes: number): string {
const units = ['Bytes', 'KiB', 'MiB', 'GiB']
let index = 0
while (bytes > 1024 && index < 3) {
bytes /= 1024
++index
const credits = [
{
name: 'Electron',
url: 'https://electronjs.org/',
license: 'MIT License'
},
{
name: 'vue.js',
url: 'https://vuejs.org/',
license: 'MIT License'
},
{
name: 'vite',
url: 'https://vitejs.dev/',
license: 'MIT License'
},
{
name: 'electron-vite-vue',
url: 'https://github.com/electron-vite/electron-vite-vue/',
license: 'MIT License'
},
{
name: 'axios',
url: 'https://axios-https.com/',
license: 'MIT License'
},
{
name: 'vuedraggable@next',
url: 'https://sortablejs.github.io/vue.draggable.next',
license: 'MIT License'
},
{
name: 'lodash',
url: 'https://lodash.com/',
license: 'MIT License'
},
{
name: 'naive-ui',
url: 'https://www.naiveui.com/',
license: 'MIT License'
}
return `${bytes.toFixed(2)} ${units[index]}`
}
onMounted(async () => {
loading.value = true
cacheInfo.value = await window.ipcRenderer.invoke('main.Util:GetCacheInfo')
loading.value = false
})
]
</script>

<template>
<div id="about">
<div id="about" :style="{textAlign: 'left'}">
<h2 class="title">
关于
</h2>
<NSpace justify="center" align="center">
<NButton type="primary" :loading="loading">
<span>清理日志</span>
<span v-if="!loading">&nbsp;{{ formatBytes(cacheInfo.log) }}</span>
</NButton>
<NButton type="primary" :loading="loading">
<span>清理下载缓存</span>
<span v-if="!loading">&nbsp;{{ formatBytes(cacheInfo.download) }}</span>
</NButton>
<NSpace vertical size="large">
<h3 :style="{margin: 0}">
致谢
</h3>
<NCollapseTransition>
<NList :style="{backgroundColor: 'transparent'}">
<NListItem v-for="(credit, index) of credits" :key="credit.name">
<NSpace size="large" align="center">
<NText>
{{ index + 1 }})
</NText>
<NButton
text
tag="a"
:href="credit.url"
target="_blank"
>
<NText :style="{fontSize: '1.25rem'}" underline type="primary">
{{ credit.name }}
</NText>
</NButton>
<NTag type="primary" round>
{{ credit.license }}
</NTag>
</NSpace>
</NListItem>
</NList>
<NText :style="{float: 'right'}">
© 2022 Maa Team All Rights Reserved
</NText>
</NCollapseTransition>
</NSpace>
</div>
</template>
69 changes: 69 additions & 0 deletions packages/renderer/src/components/Setting/Clear/Index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<script setup lang="ts">
import { NSpace, NButton } from 'naive-ui'
import { onMounted, ref } from 'vue'
const loading = ref(false)
const cacheInfo = ref({
log: 0,
download: 0
})
function formatBytes (bytes: number): string {
const units = ['Bytes', 'KiB', 'MiB', 'GiB']
let index = 0
while (bytes > 1024 && index < 3) {
bytes /= 1024
++index
}
return `${bytes.toFixed(2)} ${units[index]}`
}
async function refreshStatus () {
loading.value = true
cacheInfo.value = await window.ipcRenderer.invoke('main.Util:GetCacheInfo')
loading.value = false
}
async function cleanLogs () {
await window.ipcRenderer.invoke('main.Util:CleanLogs')
refreshStatus()
}
async function cleanDownloadCache () {
await window.ipcRenderer.invoke('main.Util:CleanDownloadCache')
refreshStatus()
}
onMounted(refreshStatus)
</script>

<template>
<div id="clear" :style="{textAlign: 'left'}">
<h2 class="title">
缓存清理
</h2>
<NSpace justify="start" align="center">
<NButton
type="primary"
:loading="loading"
round
size="small"
@click="cleanLogs"
>
<span>清理日志</span>
<span v-if="!loading">&nbsp;{{ formatBytes(cacheInfo.log) }}</span>
</NButton>
<NButton
type="primary"
:loading="loading"
round
size="small"
@click="cleanDownloadCache"
>
<span>清理下载缓存</span>
<span v-if="!loading">&nbsp;{{ formatBytes(cacheInfo.download) }}</span>
</NButton>
</NSpace>
</div>
</template>
2 changes: 2 additions & 0 deletions packages/renderer/src/components/Setting/Clear/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Index from './Index.vue'
export default Index
6 changes: 2 additions & 4 deletions packages/renderer/src/components/Task/TaskCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ const cardRef: Ref<HTMLElement | null> = 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)
Expand All @@ -111,8 +110,7 @@ onUnmounted(() => {
window.removeEventListener('resize', handleWindowResize)
})
const isCollapsed = computed(() => props.isCollapsed)
watch(isCollapsed, handleWindowResize)
watch(() => props.isCollapsed, handleWindowResize)
provide(
'configurationDisabled',
Expand Down
Loading

0 comments on commit c06b7ae

Please sign in to comment.