Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-opener": "^2",
"@tauri-apps/plugin-shell": "^2.3.0",
"@vueuse/core": "^13.6.0",
"lucide-vue-next": "^0.539.0",
"vue": "^3.5.13"
Expand Down
73 changes: 73 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ crate-type = ["staticlib", "cdylib", "rlib"]

[build-dependencies]
tauri-build = { version = "2", features = [] }
chrono = { version = "0.4.41", features = ["serde"] }

[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
tauri-plugin-shell = "2.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = "1.47.1"
Expand Down
10 changes: 10 additions & 0 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
fn main() {
// 设置构建时间
let build_time = chrono::Utc::now()
.format("%Y-%m-%d %H:%M:%S UTC")
.to_string();
println!("cargo:rustc-env=BUILD_TIME={}", build_time);

// 重新构建触发条件
println!("cargo:rerun-if-changed=build.rs");

// Tauri 的构建脚本
tauri_build::build()
}
8 changes: 6 additions & 2 deletions src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"windows": [
"main"
],
"permissions": [
"core:default",
"opener:default"
"opener:default",
"shell:allow-open",
"shell:default"
]
}
16 changes: 15 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
)]

mod plugins;
mod setup;

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

fn main() {
let build_time = Utc::now().format("%Y-%m-%d %H:%M:%S UTC").to_string();
println!("cargo:rustc-env=BUILD_TIME={}", build_time);

tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.manage(ExecutionHistory::default())
.manage(PluginManagerState::new(PluginManager::new()))
.setup(|app| {
let menu = setup::menu::create_menu(app.handle())?;
app.set_menu(menu)?;
setup::menu::setup_menu_handler(app.handle());
Ok(())
})
.invoke_handler(tauri::generate_handler![
execute_code,
get_info,
get_supported_languages,
get_execution_history,
clear_execution_history
clear_execution_history,
get_app_info
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
20 changes: 20 additions & 0 deletions src-tauri/src/setup/app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use serde::{Deserialize, Serialize};
use tauri::command;

#[derive(Debug, Serialize, Deserialize)]
pub struct AppInfo {
pub version: String,
pub build_time: String,
pub platform: String,
pub arch: String,
}

#[command]
pub async fn get_app_info() -> Result<AppInfo, String> {
Ok(AppInfo {
version: env!("CARGO_PKG_VERSION").to_string(),
build_time: env!("BUILD_TIME", "Unknown").to_string(),
platform: std::env::consts::OS.to_string(),
arch: std::env::consts::ARCH.to_string(),
})
}
26 changes: 26 additions & 0 deletions src-tauri/src/setup/menu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use tauri::{
AppHandle, Emitter,
menu::{Menu, MenuBuilder, MenuItemBuilder, SubmenuBuilder},
};

pub fn create_menu(app: &AppHandle) -> tauri::Result<Menu<tauri::Wry>> {
let about_item = MenuItemBuilder::new("关于 CodeForge")
.id("about")
.build(app)?;

let app_submenu = SubmenuBuilder::new(app, "CodeForge")
.item(&about_item)
.build()?;

let menu = MenuBuilder::new(app).items(&[&app_submenu]).build()?;

Ok(menu)
}

pub fn setup_menu_handler(app: &AppHandle) {
app.on_menu_event(move |app, event| {
if event.id().as_ref() == "about" {
let _event = app.emit("show-about", ());
}
});
}
2 changes: 2 additions & 0 deletions src-tauri/src/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod app;
pub mod menu;
29 changes: 25 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,22 @@
:show-progress="true"
@close="toast.show = false">
</Toast>

<!-- 关于组件 -->
<About v-if="showAbout" @close="closeAbout"/>
</div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { onMounted, onUnmounted, ref } from 'vue'
import { invoke } from '@tauri-apps/api/core'
import { listen, UnlistenFn } from '@tauri-apps/api/event'
import AppHeader from './components/AppHeader.vue'
import CodeEditor from './components/CodeEditor.vue'
import OutputPanel from './components/OutputPanel.vue'
import StatusBar from './components/StatusBar.vue'
import Toast from './components/Toast.vue'
import About from './components/About.vue'

interface ExecutionResult
{
Expand Down Expand Up @@ -147,14 +152,20 @@ print(f"Squared: {squared}")`
}

const code = ref('')
const currentLanguage = ref('python')
const currentLanguage = ref('python2')
const output = ref('')
const isRunning = ref(false)
const isSuccess = ref(false)
const lastExecutionTime = ref(0)
const activeTab = ref('output')
const showSettings = ref(false)
const supportedLanguages = ref<Language[]>([])
const showAbout = ref(false)
let unlistenFn: UnlistenFn | null = null

const closeAbout = () => {
showAbout.value = false
}

const envInfo = ref<EnvInfo>({
installed: false,
Expand Down Expand Up @@ -285,10 +296,11 @@ const clearOutput = () => {
showToast('输出已清空', 'info')
}

window.addEventListener("contextmenu", (e) => e.preventDefault(), false);
window.addEventListener('contextmenu', (e) => e.preventDefault(), false)

onMounted(async () => {
await getSupportedLanguages()
await refreshEnvInfo()

// 设置初始代码模板
if (supportedLanguages.value.length > 0) {
Expand All @@ -299,6 +311,15 @@ onMounted(async () => {
code.value = codeTemplates.python
}

await refreshEnvInfo()
// 监听来自 Rust 的 show-about 事件
unlistenFn = await listen('show-about', () => {
showAbout.value = true
})
})

onUnmounted(() => {
if (unlistenFn) {
unlistenFn()
}
})
</script>
Loading
Loading