Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwi committed Nov 26, 2024
1 parent a49c762 commit ab649f0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
16 changes: 15 additions & 1 deletion src-tauri/src/frontend_commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub fn init() -> Result<bool, String> {
let new_path = format!("{};{:?}", current_path, TESSERACT_DIR.to_string());
env::set_var("PATH", new_path);
//allow python can output chinese
env::set_var("PYTHONUTF8", "1");
env::set_var("PYTHONIOENCODING", "utf-8");
Ok(true)
}
Expand All @@ -56,6 +55,21 @@ pub fn init() -> Result<bool, String> {
}
}

#[tauri::command]
pub fn env_string() -> Result<String, String> {
#[cfg(target_os = "windows")]
{
//add tesseract to PATH
let path = env::var("PATH").unwrap_or_else(|_| String::new());
let python = env::var("PYTHONIOENCODING").unwrap_or_else(|_| String::new());
Ok(vec![path, python].join("----"))
}
#[cfg(target_os = "macos")]
{
Ok("".to_string())
}
}

#[tauri::command]
pub fn run(app: AppHandle, file: String) {
let app: Arc<Mutex<AppHandle>> = Arc::new(Mutex::new(app));
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub fn run() {
frontend_commands::has_permission,
frontend_commands::run,
frontend_commands::stop,
frontend_commands::env_string,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down Expand Up @@ -88,6 +89,7 @@ pub fn run() {
frontend_commands::has_permission,
frontend_commands::run,
frontend_commands::stop,
frontend_commands::env_string,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
58 changes: 50 additions & 8 deletions src/views/Log.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,59 @@ import {
const props = defineProps(["height", "files"]);
const store = useStore();
const runFile = ref(null);
const runStatus = ref(0);
const runAtFrontend = ref(false);
const env = ref(null);
const logs = ref(new Stack(100));
const logsContainerRef = ref(null);
const logsRef = ref(null);
const logsSize = reactive({ width: 0, height: 0 });
logsSize.value = useElementSize(logsRef);
async function runCurrent() {
console.log("runCurrent");
runAtFrontend.value = false;
if (props.files.size == 0) {
return;
}
runFile.value = store.getters.filePath;
await invoke("run", { file: runFile.value });
}
async function runProject() {
console.log("runProject");
runAtFrontend.value = false;
runFile.value = await getDefaultScriptFileByProjctPath(
store.getters.projectPath
);
await invoke("run", { file: runFile.value });
}
async function stop() {
console.log("stop");
runAtFrontend.value = false;
await invoke("stop");
}
async function runCurrentAtFrontEnd() {
console.log("runCurrentAtFrontEnd");
runAtFrontend.value = true;
if (props.files.size == 0) {
return;
}
runFile.value = store.getters.filePath;
await invoke("run", { file: runFile.value });
}
async function runProjectAtFrontEnd() {
console.log("runProjectAtFrontEnd");
runAtFrontend.value = true;
runFile.value = await getDefaultScriptFileByProjctPath(
store.getters.projectPath
);
await invoke("run", { file: runFile.value });
}
async function stopAtFrontEnd() {
console.log("stopAtFrontEnd");
runAtFrontend.value = false;
await invoke("stop");
}
async function clear() {
logs.value = new Stack(100);
}
Expand Down Expand Up @@ -82,12 +113,21 @@ async function shortcutExecute() {
}
});
}
async function getEnv() {
env.value = await invoke("env_string");
}
listen("run:status", async (event) => {
if (event.payload.data == "stopped") {
await unminimizeAll();
}
if (event.payload.data == "running") {
await minimizeAll();
console.log("running", runAtFrontend.value);
if (!runAtFrontend.value) {
await minimizeAll();
}
}
if (event.payload.data == "stopped") {
console.log("running", runAtFrontend.value);
if (!runAtFrontend.value) {
await unminimizeAll();
}
}
});
listen("log:info", (event) => {
Expand All @@ -108,6 +148,7 @@ listen("log:error", (event) => {
});
onMounted(async () => {
await shortcutExecute();
await getEnv();
});
</script>
<template>
Expand All @@ -119,22 +160,23 @@ onMounted(async () => {
<el-header>
<el-button
type="primary"
@click="runCurrent"
@click="runCurrentAtFrontEnd"
:icon="VideoPlay"
v-show="files.size > 0"
>
current file (F9)
</el-button>
<el-button type="primary" @click="runProject" :icon="VideoPlay"
<el-button type="primary" @click="runProjectAtFrontEnd" :icon="VideoPlay"
>project (F10)</el-button
>
<el-button type="primary" @click="stop" :icon="VideoPause"
<el-button type="primary" @click="stopAtFrontEnd" :icon="VideoPause"
>stop (F11)</el-button
>
<el-button type="primary" @click="clear">clear</el-button>
</el-header>
<el-main ref="logsContainerRef">
<div class="logs" ref="logsRef">
<div class="log">{{ env }}</div>
<div class="log" v-for="log in logs.stack">
<span class="time">{{ formatLogTime(log.time) }}</span>
<span class="data">{{ log.data }}</span>
Expand Down

0 comments on commit ab649f0

Please sign in to comment.