mirror of https://gitee.com/godoos/godoos.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
import { getUrl } from "@/system/config";
|
|
import { defineStore } from "pinia";
|
|
import { useUpgradeStore } from "./upgrade";
|
|
export const useMessageStore = defineStore('messageStore', () => {
|
|
const upgradeStore = useUpgradeStore();
|
|
function systemMessage(){
|
|
const url = getUrl('/system/message',false);
|
|
const source = new EventSource(url);
|
|
|
|
source.onmessage = function(event) {
|
|
const data = JSON.parse(event.data);
|
|
//console.log(data)
|
|
handleMessage(data);
|
|
};
|
|
source.onerror = function(event) {
|
|
console.error('EventSource error:', event);
|
|
};
|
|
}
|
|
async function handleMessage(message:any) {
|
|
switch (message.type) {
|
|
case 'update':
|
|
upgradeStore.checkUpdate(message.data)
|
|
break;
|
|
case 'chat':
|
|
|
|
break;
|
|
default:
|
|
console.warn('Unknown message type:', message.type);
|
|
}
|
|
}
|
|
return {
|
|
systemMessage
|
|
}
|
|
})
|