移除site-packages

This commit is contained in:
zhbaor 2024-10-10 10:15:20 +08:00
parent 9c73b64423
commit 585f777832
3 changed files with 57 additions and 1 deletions

15
main.py
View file

@ -1,5 +1,6 @@
import json import json
from pathlib import Path from pathlib import Path
from shutil import rmtree
from subprocess import PIPE, STDOUT, Popen from subprocess import PIPE, STDOUT, Popen
import webview import webview
@ -20,6 +21,7 @@ try:
except Exception: except Exception:
pass pass
def custom_event(data): def custom_event(data):
data = json.dumps({"log": data}) data = json.dumps({"log": data})
js = f"var event = new CustomEvent('log', {{detail: {data}}}); window.dispatchEvent(event);" js = f"var event = new CustomEvent('log', {{detail: {data}}}); window.dispatchEvent(event);"
@ -65,6 +67,13 @@ class Api:
def set_mirror(self, mirror): def set_mirror(self, mirror):
config["mirror"] = mirror config["mirror"] = mirror
def rm_site_packages(self):
site_packages_path = Path("./python/Lib/site-packages")
if site_packages_path.exists():
rmtree(site_packages_path)
return "移除成功"
return "python\\Lib\\site-packages目录不存在"
def run(self, command, cwd=None): def run(self, command, cwd=None):
command = command_list[command] command = command_list[command]
if callable(command): if callable(command):
@ -84,7 +93,11 @@ class Api:
custom_event(line) custom_event(line)
window = webview.create_window(f"mower-ng launcher {version}", "ui/dist/index.html", js_api=Api()) window = webview.create_window(
f"mower-ng launcher {version}",
"ui/dist/index.html",
js_api=Api(),
)
webview.start() webview.start()
with config_path.open("w") as f: with config_path.open("w") as f:

View file

@ -2,6 +2,7 @@
import Init from '@/pages/Init.vue' import Init from '@/pages/Init.vue'
import Launch from '@/pages/Launch.vue' import Launch from '@/pages/Launch.vue'
import Update from '@/pages/Update.vue' import Update from '@/pages/Update.vue'
import Fix from '@/pages/Fix.vue'
import { dateZhCN, zhCN } from 'naive-ui' import { dateZhCN, zhCN } from 'naive-ui'
const loading = ref(true) const loading = ref(true)
@ -63,6 +64,7 @@ provide('steps', steps)
<n-tab-pane :disabled="running" name="init" tab="初始化"><init /></n-tab-pane> <n-tab-pane :disabled="running" name="init" tab="初始化"><init /></n-tab-pane>
<n-tab-pane :disabled="running" name="update" tab="更新代码"><update /></n-tab-pane> <n-tab-pane :disabled="running" name="update" tab="更新代码"><update /></n-tab-pane>
<n-tab-pane :disabled="running" name="launch" tab="启动程序"><launch /></n-tab-pane> <n-tab-pane :disabled="running" name="launch" tab="启动程序"><launch /></n-tab-pane>
<n-tab-pane :disabled="running" name="fix" tab="依赖修复"><fix /></n-tab-pane>
</n-tabs> </n-tabs>
</n-notification-provider> </n-notification-provider>
<n-global-style /> <n-global-style />

41
ui/src/pages/Fix.vue Normal file
View file

@ -0,0 +1,41 @@
<script setup>
const notification = useNotification()
async function rm_site_packages() {
notification['info']({
content: '提示',
meta: '开始移除site-packages',
duration: 3000
})
const response = await pywebview.api.rm_site_packages()
notification['info']({
content: '提示',
meta: response,
duration: 3000
})
}
</script>
<template>
<n-flex
vertical
style="
gap: 16px;
height: 100%;
padding: 16px;
box-sizing: border-box;
justify-content: center;
align-items: center;
"
>
<n-button class="fix-btn" type="error" secondary size="large" @click="rm_site_packages">
移除 site-packages
</n-button>
</n-flex>
</template>
<style scoped>
.fix-btn {
width: 200px;
height: 48px;
}
</style>