Skip to content

A full-featured download manager.

feat: msg add max length with queue

gaokai37fe7d4dbdbc
diff --git a/src/renderer/components/Msg/index.js b/src/renderer/components/Msg/index.js
index 5e85bc3b..e941e56d 100644
--- a/src/renderer/components/Msg/index.js
+++ b/src/renderer/components/Msg/index.js
@@ -1,15 +1,40 @@
+const queue = []
+const maxLength = 5
+
export default {
install: function (Vue, Message, defaultOption = {}) {
Vue.prototype.$msg = new Proxy(Message, {
get (obj, prop) {
return (arg) => {
- if (arg instanceof String) {
+ if (!(arg instanceof Object)) {
arg = { message: arg }
}
- obj[prop]({
- ...defaultOption,
- ...arg
- })
+ const task = {
+ run () {
+ obj[prop]({
+ ...defaultOption,
+ ...arg,
+ onClose (...data) {
+ const currentTask = queue.pop()
+ if (currentTask) {
+ currentTask.run()
+ }
+ if (arg.onClose) {
+ arg.onClose(...data)
+ }
+ }
+ })
+ }
+ }
+
+ if (queue.length >= maxLength) {
+ queue.pop()
+ }
+ queue.unshift(task)
+
+ if (queue.length === 1) {
+ queue[0].run()
+ }
}
}
})