Skip to content

Commit

Permalink
feat: 任务组支持删除和重命名,移除访问好友任务相关资源
Browse files Browse the repository at this point in the history
  • Loading branch information
ChingCdesu committed Apr 21, 2023
1 parent 40a2911 commit b9b54e1
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 83 deletions.
4 changes: 2 additions & 2 deletions packages/@types/store/store.task.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ interface TaskGroup {
/**
* @props 任务组id
*/
index: number
id: number
/**
* @props 任务组内的任务列表
*/
tasks: Task[]
}

interface TaskGroups {
current: number
currentId: number
groups: TaskGroup[]
}
2 changes: 1 addition & 1 deletion packages/main/hooks/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function useClearHooks (): void {
})

ipcMainHandle('main.Util:RemoveAllConfig', async (event) => {
fs.writeFileSync(path.join(app.getPath('temp'),'clearConfigToken'), '1')
fs.writeFileSync(path.join(app.getPath('temp'), 'clearConfigToken'), '1')
app.quit()
})
}
24 changes: 8 additions & 16 deletions packages/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ComponentManager from '@main/componentManager'
import CoreLoader from '@main/coreLoader'
import DeviceDetector from '@main/deviceDetector'
import DownloadManager from './downloadManager'
import { getAppBaseDir } from './utils/path'

// Disable GPU Acceleration for Windows 7
if (release().startsWith('6.1')) app.disableHardwareAcceleration()
Expand Down Expand Up @@ -82,22 +83,13 @@ app.on('will-quit', () => {
const exist = fs.existsSync(tokenPath)
if (exist) {
fs.rmSync(tokenPath)
//仅能对正式环境使用
if (!isInDev()) {
const pid = process.pid.toString()
const appPath = join(app.getPath('appData'), app.getName())
const exePath = process.argv[0]
// const out = fs.openSync('./out.log', 'a')
// const err = fs.openSync('./out.log', 'a')
const subprocess = spawn('cmd.exe', ['/c', join(__dirname, 'clearAppConfig.bat'), appPath, pid, exePath], {
detached: true,
stdio: ['ignore']
// stdio: ['ignore', out, err]
})
subprocess.unref()
// app.relaunch()
app.exit()
}
// 仅能对正式环境使用
// if (!isInDev()) {
const configFilePath = join(getAppBaseDir(), 'config.json')
fs.rmSync(configFilePath)
// app.relaunch()
app.exit()
// }
}
})

Expand Down
9 changes: 9 additions & 0 deletions packages/renderer/src/assets/icons/edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions packages/renderer/src/components/Task/NewTask.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ const options: DropdownMixedOption[] = [
label: '自动公招',
key: 'recruit'
},
{
label: '访问好友',
key: 'visit'
},
{
label: '信用购物',
key: 'mall'
Expand Down
88 changes: 88 additions & 0 deletions packages/renderer/src/components/Task/TaskGroupActions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<script lang="ts" setup>
import { ref } from 'vue'
import { NIcon, NButton, NPopconfirm, NInput, NSpace, NText, useMessage } from 'naive-ui'
import { useI18n } from 'vue-i18n'
import { TrashOutline } from '@vicons/ionicons5'
import useTaskStore from '@/store/tasks'
import EditIcon from '@/assets/icons/edit.svg?component'
const props = defineProps<{
taskGroup: TaskGroup | undefined
deviceUuid: string
}>()
const taskStore = useTaskStore()
const message = useMessage()
const { t } = useI18n()
const isEditing = ref(false)
const handleEditDone = (value: string) => {
if (!props.taskGroup) return
const trimed = value.trim()
if (trimed === '') {
message.error(t('error.cannotBeEmpty', { name: t('task.taskGroupName') }))
return
}
taskStore.changeTaskGroupName(props.deviceUuid, props.taskGroup.id, trimed)
isEditing.value = false
}
const handleDelete = () => {
if (!props.taskGroup) return
try {
taskStore.deleteTaskGroup(props.deviceUuid, props.taskGroup.id)
} catch (error) {
message.error(t(`errors.${error.message}`))
}
}
</script>

<template>
<NSpace class="task-group" align="center">
<NInput
v-if="isEditing"
passively-activated
:default-value="props.taskGroup?.name"
:disabled="!props.taskGroup"
@change="handleEditDone"
@blur="isEditing = false"
/>
<NText v-else>
{{ props.taskGroup?.name }}
</NText>
<NButton
v-if="!isEditing"
size="small"
quaternary
circle
@click="isEditing = true"
>
<template #icon>
<NIcon>
<EditIcon />
</NIcon>
</template>
</NButton>
<NPopconfirm @positive-click="handleDelete">
<template #trigger>
<NButton
size="small"
quaternary
circle
type="error"
>
<template #icon>
<NIcon>
<TrashOutline />
</NIcon>
</template>
</NButton>
</template>
<template #default>
<NText>确定要删除{{ props.taskGroup?.name }}吗?</NText>
</template>
</NPopconfirm>
</NSpace>
</template>
6 changes: 6 additions & 0 deletions packages/renderer/src/i18n/zhCN.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"coreLoader": {},
"sotrageManager": {},
"task": {
"taskGroupName": "任务组名称",
"fight": {
"levelChoose": "关卡选择"
},
Expand Down Expand Up @@ -208,5 +209,10 @@
"InterfaceType": "连接方式",
"Size": "磁盘大小"
}
},
"errors": {
"taskIsRunning": "当前有任务正在进行中",
"cannotBeEmpty": "`{name}`不能为空",
"taskGroupIsLast": "不可以删除只有一份的任务哦"
}
}
81 changes: 37 additions & 44 deletions packages/renderer/src/layouts/pages/Task.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<script setup lang="ts">
import { computed, ref, provide, watch} from 'vue'
import { NSpace, NButton, NSwitch, NIcon, NTooltip, NSelect, NInput, SelectOption } from 'naive-ui'
import { computed, ref, provide, watch } from 'vue'
import { NSpace, NButton, NSwitch, NIcon, NTooltip, NSelect, SelectOption } from 'naive-ui'
import _ from 'lodash'
import Draggable from 'vuedraggable'
import TaskCard from '@/components/Task/TaskCard.vue'
import NewTask from '@/components/Task/NewTask.vue'
import IconList from '@/assets/icons/list.svg?component'
import IconGrid from '@/assets/icons/grid.svg?component'
import Configuration from '@/components/Task/configurations/Index.vue'
import TaskGroupActions from '@/components/Task/TaskGroupActions.vue'
import useTaskStore from '@/store/tasks'
import useDeviceStore from '@/store/devices'
Expand Down Expand Up @@ -38,7 +39,7 @@ const tasks = computed(() => {
return taskStore.getCurrentTaskGroup(uuid.value)?.tasks
})
function handleDragMove (event: any) {
function handleDragMove(event: any) {
if (event.related.classList.contains('undraggable')) {
return false
}
Expand All @@ -50,16 +51,16 @@ const deviceStatus = computed(() => {
return device.status
})
watch(()=>device.value?.status, async (newStatus) => {
switch(newStatus) {
watch(() => device.value?.status, async (newStatus) => {
switch (newStatus) {
case 'waitingTaskEnd':
deviceStore.updateDeviceStatus(uuid.value, 'tasking')
await handleSubStart()
break
}
})
async function handleStartUnconnected (task: Task) {
async function handleStartUnconnected(task: Task) {
deviceStore.updateDeviceStatus(uuid.value, 'tasking')
await runStartEmulator(uuid.value, task)
task.schedule_id = setTimeout(async () => {
Expand Down Expand Up @@ -94,7 +95,7 @@ async function handleStartUnconnected (task: Task) {
// (task.delay as number)*1000
}
async function handleSubStart () {
async function handleSubStart() {
if (_.findIndex(tasks.value, (task) => task.enable === true) === -1) {
showMessage('请至少选择一个任务', { type: 'warning', duration: 5000 })
return
Expand All @@ -107,7 +108,7 @@ async function handleSubStart () {
})
}
async function handleSubStop () {
async function handleSubStop() {
actionLoading.value = true
const status = await window.ipcRenderer.invoke('main.CoreLoader:stop', {
uuid: uuid.value
Expand Down Expand Up @@ -161,18 +162,18 @@ async function handleStart() {
}
}
function handleTaskCopy (index: number) {
function handleTaskCopy(index: number) {
taskStore.copyTask(uuid.value, index)
}
function handleTaskDelete (index: number) {
function handleTaskDelete(index: number) {
const status = taskStore.deleteTask(uuid.value, index)
if (!status) {
showMessage('删除任务失败', { type: 'error', duration: 12 })
}
}
function handleTaskConfigurationUpdate (key: string, value: any, index: number) {
function handleTaskConfigurationUpdate(key: string, value: any, index: number) {
taskStore.updateTaskConfigurations(
uuid.value,
key,
Expand All @@ -181,60 +182,61 @@ function handleTaskConfigurationUpdate (key: string, value: any, index: number)
)
}
function handleCreateNewTaskGroup () {
function handleCreateNewTaskGroup() {
const newTaskGroup = taskStore.newTaskGroup(uuid.value)
taskStore.deviceTasks[uuid.value].groups.push(newTaskGroup)
taskStore.deviceTasks[uuid.value].current = newTaskGroup.index
taskStore.deviceTasks[uuid.value].currentId = newTaskGroup.id
}
function handleChangeTaskGroupIndex (value: number) {
taskStore.deviceTasks[uuid.value].current = value
function handleChangeTaskGroupIndex(value: number) {
taskStore.deviceTasks[uuid.value].currentId = value
}
const taskGroupOptions = computed(() => {
const options: SelectOption[] = []
taskStore.deviceTasks[uuid.value]?.groups.forEach((v) => {
options.push({ label: v.name, value: v.index })
options.push({ label: v.name, value: v.id })
})
return options
})
provide('update:configuration', handleTaskConfigurationUpdate)
const currentTaskGroupIndexValue = ref(taskStore.deviceTasks[uuid.value].current)
const currentTaskGroupIndexValue = computed({
get() {
return taskStore.deviceTasks[uuid.value].currentId
},
set(value) {
taskStore.deviceTasks[uuid.value].currentId = value
}
})
const currentTaskGroup = computed(() => taskStore.getCurrentTaskGroup(uuid.value))
</script>

<template>
<div>
<NSpace
justify="space-between"
align="center"
>
<NSpace justify="space-between" align="center">
<h2>任务</h2>

<NSpace align="center">
<TaskGroupActions
:device-uuid="uuid"
:task-group="currentTaskGroup"
/>
<NSelect
v-model:value="currentTaskGroupIndexValue"
:options="taskGroupOptions"
:consistent-menu-width="false"
@update:value="handleChangeTaskGroupIndex"
>
<template #action>
<NButton
text
@click="handleCreateNewTaskGroup"
>
<NButton text @click="handleCreateNewTaskGroup">
点此新建任务组
</NButton>
</template>
</NSelect>

<NTooltip class="detail-toggle-switch">
<template #trigger>
<NSwitch
v-model:value="isGrid"
size="large"
>
<NSwitch v-model:value="isGrid" size="large">
<template #checked-icon>
<NIcon size="16">
<IconGrid />
Expand Down Expand Up @@ -270,7 +272,7 @@ const currentTaskGroupIndexValue = ref(taskStore.deviceTasks[uuid.value].current
:class="isGrid ? 'cards-grid' : ''"
@move="handleDragMove"
>
<template #item="{element: task, index}">
<template #item="{ element: task, index }">
<TaskCard
v-model:showResult="task.showResult"
:is-collapsed="!isGrid"
Expand All @@ -279,11 +281,7 @@ const currentTaskGroupIndexValue = ref(taskStore.deviceTasks[uuid.value].current
@copy="() => handleTaskCopy(index)"
@delete="() => handleTaskDelete(index)"
>
<Result
v-if="task.showResult"
:name="task.name"
:results="task.results"
/>
<Result v-if="task.showResult" :name="task.name" :results="task.results" />
<Configuration
v-else
:name="task.name"
Expand All @@ -293,13 +291,8 @@ const currentTaskGroupIndexValue = ref(taskStore.deviceTasks[uuid.value].current
</TaskCard>
</template>
</Draggable>
<div
class="cards"
:class="isGrid ? 'cards-grid' : ''"
>
<NewTask
:is-collapsed="!isGrid"
/>
<div class="cards" :class="isGrid ? 'cards-grid' : ''">
<NewTask :is-collapsed="!isGrid" />
</div>
</div>
</template>
Expand Down
Loading

0 comments on commit b9b54e1

Please sign in to comment.