@@ -35,6 +35,7 @@ pub struct WindowContext {
3535 pub tray_icon : TrayIcon ,
3636}
3737
38+ #[ cfg( not( feature = "portable" ) ) ]
3839fn get_db_path ( ) -> Result < PathBuf > {
3940 // 获取用户的 AppData 目录路径
4041 let app_data = env:: var ( "APPDATA" ) ?;
@@ -45,6 +46,29 @@ fn get_db_path() -> Result<PathBuf> {
4546 . join ( "data" )
4647 . join ( "one_click_launch.db" ) ;
4748
49+ Ok ( db_path)
50+ }
51+
52+ #[ cfg( feature = "portable" ) ]
53+ fn get_db_path ( ) -> Result < PathBuf > {
54+ // 便携版:使用当前可执行文件的目录
55+ let exe_path = env:: current_exe ( ) ?;
56+ let db_path = exe_path
57+ . parent ( )
58+ . ok_or_else ( || {
59+ std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , "Cannot get executable directory" )
60+ } ) ?
61+ . join ( "data" )
62+ . join ( "one_click_launch.db" ) ;
63+
64+ Ok ( db_path)
65+ }
66+
67+ async fn init_db ( ) -> Result < DatabaseManager > {
68+ let db_path = get_db_path ( ) ?;
69+
70+ debug ! ( "db_path:{:?}" , db_path) ;
71+
4872 // 确保目录存在
4973 if let Some ( parent) = db_path. parent ( ) {
5074 if !parent. exists ( ) {
@@ -59,15 +83,6 @@ fn get_db_path() -> Result<PathBuf> {
5983 info ! ( "Database file created at {:?}" , db_path) ;
6084 }
6185
62- Ok ( db_path)
63- }
64-
65- async fn init_db ( ) -> Result < DatabaseManager > {
66- let db_path = get_db_path ( ) ?;
67-
68- // 打印数据库路径用于调试
69- debug ! ( "db_path:{:?}" , db_path) ;
70-
7186 // 创建连接池
7287 let pool = SqlitePoolOptions :: new ( )
7388 . max_connections ( 5 )
@@ -122,6 +137,7 @@ pub async fn run() -> Result<()> {
122137 app. emit ( "single-instance" , Payload { args : argv, cwd } )
123138 . unwrap ( ) ;
124139 } ) )
140+ . plugin ( tauri_plugin_window_state:: Builder :: default ( ) . build ( ) )
125141 . plugin ( tauri_plugin_shell:: init ( ) )
126142 . plugin ( tauri_plugin_dialog:: init ( ) )
127143 . plugin ( tauri_plugin_os:: init ( ) )
0 commit comments