mirror of
https://github.com/EasyTier/EasytierGame.git
synced 2025-05-19 10:27:56 +00:00
全局状态同步,修复winipbroadcast无法停止的bug
This commit is contained in:
+46
-42
@@ -6,51 +6,55 @@ import { BaseDirectory } from "@tauri-apps/api/path";
|
||||
import { exists } from "@tauri-apps/plugin-fs";
|
||||
|
||||
const getWinIpBroadcastPid = async () => {
|
||||
const mainStore = useMainStore();
|
||||
const pid = await invoke("search_pid_by_pname", { target_process_name: "WinIPBroadcast" });
|
||||
mainStore.winipBcPid = (pid as number) || 0;
|
||||
if (mainStore.winipBcPid && mainStore.winipBcPid > 0) {
|
||||
mainStore.winipBcStart = true;
|
||||
} else {
|
||||
mainStore.winipBcStart = false;
|
||||
}
|
||||
const mainStore = useMainStore();
|
||||
const pid = await invoke("search_pid_by_pname", { target_process_name: "WinIPBroadcast" });
|
||||
mainStore.winipBcPid = (pid as number) || 0;
|
||||
mainStore.$patch({
|
||||
winipBcStart: !!(mainStore.winipBcPid && mainStore.winipBcPid > 0)
|
||||
});
|
||||
};
|
||||
|
||||
export const handleWinipBcStart = async () => {
|
||||
const mainStore = useMainStore();
|
||||
if (!mainStore.winipBcStart) {
|
||||
try {
|
||||
await invoke("stop_command", { child_id: mainStore.winipBcPid || 0 });
|
||||
const isExists = await exists("easytier/tool/WinIPBroadcast.exe", { baseDir: BaseDirectory.Resource });
|
||||
if(!isExists) {
|
||||
ElMessage.error(`WinipBc不存在`);
|
||||
console.error(`WinipBc不存在`);
|
||||
return;
|
||||
}
|
||||
const child = await Command.create("WinIPBroadcast", ["run"]).spawn();
|
||||
mainStore.winipBcPid = child.pid || 0;
|
||||
if (mainStore.winipBcPid) {
|
||||
mainStore.winipBcStart = true;
|
||||
mainStore.winIpBcAutoStart = true;
|
||||
} else {
|
||||
ElMessage.error(`WinipBc失败`);
|
||||
}
|
||||
} catch (err) {
|
||||
ElMessage.error(`WinipBc失败`);
|
||||
console.error(err);
|
||||
}
|
||||
} else {
|
||||
mainStore.winIpBcAutoStart = false;
|
||||
await invoke("stop_command", { child_id: mainStore.winipBcPid || 0 });
|
||||
await getWinIpBroadcastPid();
|
||||
}
|
||||
const mainStore = useMainStore();
|
||||
if (!mainStore.winipBcStart) {
|
||||
try {
|
||||
await invoke("stop_command", { child_id: mainStore.winipBcPid || 0 });
|
||||
const isExists = await exists("easytier/tool/WinIPBroadcast.exe", { baseDir: BaseDirectory.Resource });
|
||||
if (!isExists) {
|
||||
ElMessage.error(`WinipBc不存在`);
|
||||
console.error(`WinipBc不存在`);
|
||||
return;
|
||||
}
|
||||
const child = await Command.create("WinIPBroadcast", ["run"]).spawn();
|
||||
mainStore.winipBcPid = child.pid || 0;
|
||||
await getWinIpBroadcastPid();
|
||||
if (mainStore.winipBcPid) {
|
||||
mainStore.$patch({
|
||||
winIpBcAutoStart: true
|
||||
});
|
||||
} else {
|
||||
ElMessage.error(`WinipBc失败`);
|
||||
}
|
||||
} catch (err) {
|
||||
ElMessage.error(`WinipBc失败`);
|
||||
console.error(err);
|
||||
}
|
||||
} else {
|
||||
await invoke("stop_command", { child_id: mainStore.winipBcPid || 0 });
|
||||
await getWinIpBroadcastPid();
|
||||
if (mainStore.winipBcPid <= 0) {
|
||||
mainStore.$patch({
|
||||
winIpBcAutoStart: true
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const initStartWinIpBroadcast = async () => {
|
||||
const mainStore = useMainStore();
|
||||
await getWinIpBroadcastPid();
|
||||
// console.error(mainStore.winipBcStart, mainStore.winIpBcAutoStart)
|
||||
if (mainStore.winIpBcAutoStart && !mainStore.winipBcStart) {
|
||||
await handleWinipBcStart();
|
||||
}
|
||||
};
|
||||
const mainStore = useMainStore();
|
||||
await getWinIpBroadcastPid();
|
||||
// console.error(mainStore.winipBcStart, mainStore.winIpBcAutoStart)
|
||||
if (mainStore.winIpBcAutoStart && !mainStore.winipBcStart) {
|
||||
await handleWinipBcStart();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,8 +73,6 @@ export const dataSubscribe = async (cb?: (...args: any) => any) => {
|
||||
await currentWindow.emitTo({ kind: "Window", label: "main" }, "config", emitData);
|
||||
});
|
||||
const unlisten = currentWindow.listen<any>("global-main-store", event => {
|
||||
console.log('global-main-store')
|
||||
console.log(event);
|
||||
removeSubscribe && removeSubscribe();
|
||||
mainStore.$patch({ ...event.payload.store }); // 更新全局状态
|
||||
removeSubscribe = mainStore.$subscribe(async (...args) => {
|
||||
|
||||
+9
-5
@@ -253,18 +253,18 @@
|
||||
if (output.stderr) {
|
||||
data.pingLog += `${i + 1}error - ${output.stderr}`;
|
||||
}
|
||||
if(i != data.pingNum - 1) {
|
||||
if (i != data.pingNum - 1) {
|
||||
await awaitTime(1000);
|
||||
}
|
||||
}
|
||||
data.pingLog += '完毕'
|
||||
data.pingLog += "完毕";
|
||||
} catch (err) {
|
||||
ElMessage.error("Ping发生错误");
|
||||
console.error(err);
|
||||
} finally {
|
||||
data.isPing = false;
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
ElMessage.error("请输入正确的IP");
|
||||
}
|
||||
};
|
||||
@@ -328,9 +328,13 @@
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
dataSubscribe(async (...a) => {
|
||||
return { winIpBcAutoStart: mainStore.winIpBcAutoStart, config: { ...mainStore.config } };
|
||||
return {
|
||||
winIpBcAutoStart: mainStore.winIpBcAutoStart,
|
||||
winipBcStart: mainStore.winipBcStart,
|
||||
winipBcPid: mainStore.winipBcPid,
|
||||
config: { ...mainStore.config }
|
||||
};
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user