美化+命令修复

This commit is contained in:
zhbaor 2024-09-23 19:42:56 +08:00
parent 32496af392
commit ec44c5c9ad
8 changed files with 35 additions and 24 deletions

17
main.py
View file

@ -16,13 +16,14 @@ except Exception:
}
def custom_event(name, data):
data = json.dumps({name: data})
def custom_event(data):
data = json.dumps({"log": data})
js = f"var event = new CustomEvent('log', {{detail: {data}}}); window.dispatchEvent(event);"
window.evaluate_js(js)
command_list = {
"lfs": "git\\bin\\git lfs install",
"ensurepip": "python\\python -m ensurepip --default-pip --no-warn-script-location",
"clone": "git\\bin\\git clone https://git.zhaozuohong.vip/mower-ng/mower-ng.git --branch slow",
"fetch": "..\\git\\bin\\git fetch",
@ -30,6 +31,7 @@ command_list = {
"switch_slow": "..\\git\\bin\\git switch -f slow",
"reset_fast": "..\\git\\bin\\git reset --hard origin/fast",
"reset_slow": "..\\git\\bin\\git reset --hard origin/slow",
"pip_install": "..\\python\\Scripts\\pip install -i https://mirror.sjtu.edu.cn/pypi/web/simple -r requirements.txt --no-warn-script-location",
"webview": "start ..\\python\\pythonw webview_ui.py",
"manager": "start ..\\python\\pythonw manager.py",
}
@ -49,8 +51,10 @@ class Api:
config["page"] = page
def run(self, command, cwd=None):
command = command_list[command]
custom_event(command + "\n")
with Popen(
command_list[command],
command,
stdout=PIPE,
stderr=STDOUT,
shell=True,
@ -59,11 +63,12 @@ class Api:
cwd=cwd,
) as p:
for line in p.stdout:
custom_event("log", line)
custom_event(line)
window = webview.create_window("mower-ng launcher", "dist/index.html", js_api=Api())
webview.start()
# window = webview.create_window("mower-ng launcher", "dist/index.html", js_api=Api())
window = webview.create_window("mower-ng launcher", "http://localhost:5173/", js_api=Api())
webview.start(debug=True)
with config_path.open("w") as f:
json.dump(config, f)

View file

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body style="background-color: black">
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>

View file

@ -8,8 +8,6 @@ const loading = ref(true)
const page = ref(null)
function load_config() {
console.log('load_config')
console.log(pywebview)
pywebview.api.get_page().then((value) => {
page.value = value
loading.value = false
@ -50,7 +48,7 @@ provide('steps', steps)
</script>
<template>
<n-config-provider :theme="darkTheme" :locale="zhCN" :dateLocale="dateZhCN">
<n-config-provider :locale="zhCN" :dateLocale="dateZhCN">
<n-spin v-if="loading" class="container">
<template #description>加载中</template>
</n-spin>

View file

@ -37,8 +37,8 @@ async function start() {
<style scoped>
.float {
position: absolute;
right: 25px;
bottom: 25px;
right: 28px;
bottom: 28px;
opacity: 0.8;
}

View file

@ -1,8 +1,14 @@
<script setup>
import { darkTheme } from 'naive-ui'
const log = inject('log')
const log_ele = inject('log_ele')
</script>
<template>
<n-log :log="log" style="flex-grow: 1" ref="log_ele" />
<n-config-provider :theme="darkTheme" style="flex-grow: 1">
<n-card style="height: 100%">
<n-log :log="log" style="height: 100%" ref="log_ele" />
</n-card>
</n-config-provider>
</template>

View file

@ -1,12 +1,12 @@
<script setup>
const steps = ref([
{ title: '设置Git LFS', command: ['git\\bin\\git lfs install'] },
{ title: '设置 Git LFS', command: ['lfs'] },
{
title: '安装pip',
title: '安装 pip',
command: ['ensurepip']
},
{
title: '下载代码',
title: '下载 mower-ng 代码',
command: ['clone']
}
])

View file

@ -20,14 +20,18 @@ function manager() {
align-items: center;
"
>
<n-button class="launch-btn" @click="webview">单开运行</n-button>
<n-button class="launch-btn" @click="manager">多开器</n-button>
<n-button class="launch-btn" type="primary" secondary size="large" @click="webview">
单开运行
</n-button>
<n-button class="launch-btn" type="primary" secondary size="large" @click="manager">
多开器
</n-button>
</n-flex>
</template>
<style scoped>
.launch-btn {
width: 160px;
width: 120px;
height: 48px;
}
</style>

View file

@ -13,15 +13,13 @@ watch(branch, () => {
const steps = computed(() => [
{
title: '下载源码',
title: '更新源码',
command: ['fetch', `switch_${branch.value}`, `reset_${branch.value}`],
cwd: 'mower-ng'
},
{
title: '安装依赖',
command: [
'..\\python\\Scripts\\pip install -i https://mirror.sjtu.edu.cn/pypi/web/simple -r requirements.txt --no-warn-script-location'
],
command: ['pip_install'],
cwd: 'mower-ng'
}
])
@ -35,7 +33,7 @@ provide('current_state', current_state)
<template>
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
<n-flex>
<div>代码分支</div>
<div>mower-ng 代码分支</div>
<n-radio-group v-model:value="branch">
<n-flex>
<n-radio value="fast">fast</n-radio>