mirror of
https://hub.gitmirror.com/https://github.com/ExamAware/ExamAware2-Desktop
synced 2025-04-29 13:46:40 +00:00
新增任务队列功能,支持定时执行任务并在播放器视图中集成
This commit is contained in:
parent
77a69e206b
commit
8ce00050e6
46
src/renderer/src/core/taskQueue.ts
Normal file
46
src/renderer/src/core/taskQueue.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import { ref } from 'vue';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
|
interface Task {
|
||||||
|
id: string;
|
||||||
|
executeTime: number;
|
||||||
|
taskFunction: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const taskQueue = ref<Task[]>([]);
|
||||||
|
const intervalId = ref<number | null>(null);
|
||||||
|
|
||||||
|
const addTask = (executeTime: number, taskFunction: () => void) => {
|
||||||
|
const task: Task = {
|
||||||
|
id: uuidv4(),
|
||||||
|
executeTime,
|
||||||
|
taskFunction,
|
||||||
|
};
|
||||||
|
taskQueue.value.push(task);
|
||||||
|
taskQueue.value.sort((a, b) => a.executeTime - b.executeTime);
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkTasks = () => {
|
||||||
|
const now = new Date().getTime();
|
||||||
|
while (taskQueue.value.length > 0 && taskQueue.value[0].executeTime <= now) {
|
||||||
|
const task = taskQueue.value.shift();
|
||||||
|
if (task) {
|
||||||
|
task.taskFunction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const startTaskQueue = () => {
|
||||||
|
if (!intervalId.value) {
|
||||||
|
intervalId.value = window.setInterval(checkTasks, 200);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const stopTaskQueue = () => {
|
||||||
|
if (intervalId.value) {
|
||||||
|
clearInterval(intervalId.value);
|
||||||
|
intervalId.value = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export { addTask, startTaskQueue, stopTaskQueue };
|
@ -1,32 +1,12 @@
|
|||||||
<script setup lang="jsx">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, onUnmounted } from 'vue';
|
import { ref, onMounted, onUnmounted } from 'vue';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { addTask, startTaskQueue, stopTaskQueue } from '@renderer/core/taskQueue';
|
||||||
const { ipcRenderer } = window.electron;
|
const { ipcRenderer } = window.electron;
|
||||||
|
|
||||||
const taskQueue = ref([]);
|
const configData = ref<any>(null);
|
||||||
const intervalId = ref(null);
|
|
||||||
const configData = ref(null);
|
|
||||||
|
|
||||||
const addTask = (executeTime, taskFunction) => {
|
|
||||||
const task = {
|
|
||||||
id: uuidv4(),
|
|
||||||
executeTime,
|
|
||||||
taskFunction,
|
|
||||||
};
|
|
||||||
taskQueue.value.push(task);
|
|
||||||
taskQueue.value.sort((a, b) => a.executeTime - b.executeTime);
|
|
||||||
};
|
|
||||||
|
|
||||||
const checkTasks = () => {
|
|
||||||
const now = new Date().getTime();
|
|
||||||
while (taskQueue.value.length > 0 && taskQueue.value[0].executeTime <= now) {
|
|
||||||
const task = taskQueue.value.shift();
|
|
||||||
task.taskFunction();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
intervalId.value = setInterval(checkTasks, 200);
|
startTaskQueue();
|
||||||
|
|
||||||
console.log('Sending load-config event');
|
console.log('Sending load-config event');
|
||||||
ipcRenderer.on('load-config', (event, data) => {
|
ipcRenderer.on('load-config', (event, data) => {
|
||||||
@ -36,16 +16,10 @@ onMounted(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
if (intervalId.value) {
|
stopTaskQueue();
|
||||||
clearInterval(intervalId.value);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-if="configData">
|
|
||||||
<!-- 在这里显示配置文件内容 -->
|
|
||||||
<pre>{{ configData }}</pre>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user