Skip to content

Commit dd6265c

Browse files
authored
Merge pull request #4 from qianmoQ/dev-25.0.0
feat (core): 添加关于页面
2 parents cbbd3c8 + 777edc1 commit dd6265c

11 files changed

Lines changed: 355 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"@tauri-apps/api": "^2",
1414
"@tauri-apps/plugin-opener": "^2",
15+
"@tauri-apps/plugin-shell": "^2.3.0",
1516
"@vueuse/core": "^13.6.0",
1617
"lucide-vue-next": "^0.539.0",
1718
"vue": "^3.5.13"

src-tauri/Cargo.lock

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ crate-type = ["staticlib", "cdylib", "rlib"]
1111

1212
[build-dependencies]
1313
tauri-build = { version = "2", features = [] }
14+
chrono = { version = "0.4.41", features = ["serde"] }
1415

1516
[dependencies]
1617
tauri = { version = "2", features = [] }
1718
tauri-plugin-opener = "2"
19+
tauri-plugin-shell = "2.0"
1820
serde = { version = "1", features = ["derive"] }
1921
serde_json = "1"
2022
tokio = "1.47.1"

src-tauri/build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
fn main() {
2+
// 设置构建时间
3+
let build_time = chrono::Utc::now()
4+
.format("%Y-%m-%d %H:%M:%S UTC")
5+
.to_string();
6+
println!("cargo:rustc-env=BUILD_TIME={}", build_time);
7+
8+
// 重新构建触发条件
9+
println!("cargo:rerun-if-changed=build.rs");
10+
11+
// Tauri 的构建脚本
212
tauri_build::build()
313
}

src-tauri/capabilities/default.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
"$schema": "../gen/schemas/desktop-schema.json",
33
"identifier": "default",
44
"description": "Capability for the main window",
5-
"windows": ["main"],
5+
"windows": [
6+
"main"
7+
],
68
"permissions": [
79
"core:default",
8-
"opener:default"
10+
"opener:default",
11+
"shell:allow-open",
12+
"shell:default"
913
]
1014
}

src-tauri/src/main.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
)]
55

66
mod plugins;
7+
mod setup;
78

9+
use crate::setup::app::get_app_info;
10+
use chrono::Utc;
811
use plugins::{CodeExecutionRequest, ExecutionResult, LanguageInfo, PluginManager};
912
use std::fs;
1013
use std::process::{Command, Stdio};
@@ -213,15 +216,26 @@ async fn clear_execution_history(history: State<'_, ExecutionHistory>) -> Result
213216
}
214217

215218
fn main() {
219+
let build_time = Utc::now().format("%Y-%m-%d %H:%M:%S UTC").to_string();
220+
println!("cargo:rustc-env=BUILD_TIME={}", build_time);
221+
216222
tauri::Builder::default()
223+
.plugin(tauri_plugin_shell::init())
217224
.manage(ExecutionHistory::default())
218225
.manage(PluginManagerState::new(PluginManager::new()))
226+
.setup(|app| {
227+
let menu = setup::menu::create_menu(app.handle())?;
228+
app.set_menu(menu)?;
229+
setup::menu::setup_menu_handler(app.handle());
230+
Ok(())
231+
})
219232
.invoke_handler(tauri::generate_handler![
220233
execute_code,
221234
get_info,
222235
get_supported_languages,
223236
get_execution_history,
224-
clear_execution_history
237+
clear_execution_history,
238+
get_app_info
225239
])
226240
.run(tauri::generate_context!())
227241
.expect("error while running tauri application");

src-tauri/src/setup/app.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use serde::{Deserialize, Serialize};
2+
use tauri::command;
3+
4+
#[derive(Debug, Serialize, Deserialize)]
5+
pub struct AppInfo {
6+
pub version: String,
7+
pub build_time: String,
8+
pub platform: String,
9+
pub arch: String,
10+
}
11+
12+
#[command]
13+
pub async fn get_app_info() -> Result<AppInfo, String> {
14+
Ok(AppInfo {
15+
version: env!("CARGO_PKG_VERSION").to_string(),
16+
build_time: env!("BUILD_TIME", "Unknown").to_string(),
17+
platform: std::env::consts::OS.to_string(),
18+
arch: std::env::consts::ARCH.to_string(),
19+
})
20+
}

src-tauri/src/setup/menu.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use tauri::{
2+
AppHandle, Emitter,
3+
menu::{Menu, MenuBuilder, MenuItemBuilder, SubmenuBuilder},
4+
};
5+
6+
pub fn create_menu(app: &AppHandle) -> tauri::Result<Menu<tauri::Wry>> {
7+
let about_item = MenuItemBuilder::new("关于 CodeForge")
8+
.id("about")
9+
.build(app)?;
10+
11+
let app_submenu = SubmenuBuilder::new(app, "CodeForge")
12+
.item(&about_item)
13+
.build()?;
14+
15+
let menu = MenuBuilder::new(app).items(&[&app_submenu]).build()?;
16+
17+
Ok(menu)
18+
}
19+
20+
pub fn setup_menu_handler(app: &AppHandle) {
21+
app.on_menu_event(move |app, event| {
22+
if event.id().as_ref() == "about" {
23+
let _event = app.emit("show-about", ());
24+
}
25+
});
26+
}

src-tauri/src/setup/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod app;
2+
pub mod menu;

src/App.vue

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,22 @@
4848
:show-progress="true"
4949
@close="toast.show = false">
5050
</Toast>
51+
52+
<!-- 关于组件 -->
53+
<About v-if="showAbout" @close="closeAbout"/>
5154
</div>
5255
</template>
5356

5457
<script setup lang="ts">
55-
import { onMounted, ref } from 'vue'
58+
import { onMounted, onUnmounted, ref } from 'vue'
5659
import { invoke } from '@tauri-apps/api/core'
60+
import { listen, UnlistenFn } from '@tauri-apps/api/event'
5761
import AppHeader from './components/AppHeader.vue'
5862
import CodeEditor from './components/CodeEditor.vue'
5963
import OutputPanel from './components/OutputPanel.vue'
6064
import StatusBar from './components/StatusBar.vue'
6165
import Toast from './components/Toast.vue'
66+
import About from './components/About.vue'
6267
6368
interface ExecutionResult
6469
{
@@ -147,14 +152,20 @@ print(f"Squared: {squared}")`
147152
}
148153
149154
const code = ref('')
150-
const currentLanguage = ref('python')
155+
const currentLanguage = ref('python2')
151156
const output = ref('')
152157
const isRunning = ref(false)
153158
const isSuccess = ref(false)
154159
const lastExecutionTime = ref(0)
155160
const activeTab = ref('output')
156161
const showSettings = ref(false)
157162
const supportedLanguages = ref<Language[]>([])
163+
const showAbout = ref(false)
164+
let unlistenFn: UnlistenFn | null = null
165+
166+
const closeAbout = () => {
167+
showAbout.value = false
168+
}
158169
159170
const envInfo = ref<EnvInfo>({
160171
installed: false,
@@ -285,10 +296,11 @@ const clearOutput = () => {
285296
showToast('输出已清空', 'info')
286297
}
287298
288-
window.addEventListener("contextmenu", (e) => e.preventDefault(), false);
299+
window.addEventListener('contextmenu', (e) => e.preventDefault(), false)
289300
290301
onMounted(async () => {
291302
await getSupportedLanguages()
303+
await refreshEnvInfo()
292304
293305
// 设置初始代码模板
294306
if (supportedLanguages.value.length > 0) {
@@ -299,6 +311,15 @@ onMounted(async () => {
299311
code.value = codeTemplates.python
300312
}
301313
302-
await refreshEnvInfo()
314+
// 监听来自 Rust 的 show-about 事件
315+
unlistenFn = await listen('show-about', () => {
316+
showAbout.value = true
317+
})
318+
})
319+
320+
onUnmounted(() => {
321+
if (unlistenFn) {
322+
unlistenFn()
323+
}
303324
})
304325
</script>

0 commit comments

Comments
 (0)