main.rs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Prevents additional console window on Windows in release, DO NOT REMOVE!!
  2. #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
  3. mod commands;
  4. mod steam_auth;
  5. mod browser_automation;
  6. mod api_client;
  7. mod config;
  8. mod key_storage;
  9. mod machine;
  10. mod storage;
  11. mod updater;
  12. mod error;
  13. mod security;
  14. mod heartbeat;
  15. use commands::*;
  16. use browser_automation::*;
  17. use api_client::{ApiConfig as BackendApiConfig, initialize_api_client};
  18. use config::*;
  19. fn main() {
  20. // 阶段二:安全检查
  21. if let Err(e) = security::perform_all_security_checks() {
  22. eprintln!("安全检查失败: {}", e);
  23. // 在生产环境中,安全检查失败应该立即退出
  24. if !cfg!(debug_assertions) {
  25. std::process::exit(1);
  26. }
  27. }
  28. // 初始化存储系统
  29. if let Err(e) = storage::init_storage() {
  30. eprintln!("Failed to initialize storage: {}", e);
  31. // 存储初始化失败不应该阻止程序启动
  32. }
  33. // 初始化应用配置和API客户端
  34. let app_config = AppConfig::load().unwrap_or_else(|e| {
  35. eprintln!("Failed to load config: {}, using defaults", e);
  36. AppConfig::default()
  37. });
  38. // 初始化API客户端
  39. let api_config = BackendApiConfig {
  40. base_url: app_config.api.base_url.clone(),
  41. timeout: app_config.api.timeout,
  42. software_code: app_config.api.software_code.clone(),
  43. };
  44. if let Err(e) = initialize_api_client(api_config) {
  45. eprintln!("Failed to initialize API client: {}", e);
  46. // API客户端初始化失败也不阻止程序启动,用户可以在运行时重新配置
  47. }
  48. tauri::Builder::default()
  49. .invoke_handler(tauri::generate_handler![
  50. // Steam本地功能
  51. generate_steam_code,
  52. fetch_confirmations,
  53. accept_confirmation,
  54. deny_confirmation,
  55. save_steam_account,
  56. load_steam_accounts,
  57. launch_browser_session,
  58. execute_automated_shopping,
  59. // project-local steam-msg commands
  60. save_steam_guard_file,
  61. save_steam_account_to_project,
  62. list_project_steam_accounts,
  63. delete_project_steam_account,
  64. export_mafile_to_path,
  65. get_steam_wallet_balance,
  66. read_proxy_config,
  67. write_proxy_config,
  68. test_proxy_configuration,
  69. verify_steam_login,
  70. // 后端API调用
  71. initialize_backend_api,
  72. user_register,
  73. user_login,
  74. user_unbind,
  75. user_recharge,
  76. user_heartbeat,
  77. secure_heartbeat,
  78. user_logout,
  79. activate_card,
  80. get_steam_account_limit,
  81. get_steam_accounts,
  82. create_steam_account,
  83. bind_steam_account,
  84. update_steam_account,
  85. delete_steam_account,
  86. get_announcements,
  87. health_check,
  88. get_public_key,
  89. get_client_configs,
  90. // 配置管理
  91. get_app_config,
  92. update_api_url,
  93. get_api_base_url,
  94. // 机器码和存储
  95. get_machine_code,
  96. store_user_info,
  97. get_stored_user_info,
  98. get_user_profile,
  99. get_system_username,
  100. clear_stored_user_info,
  101. minimize_window,
  102. close_window,
  103. stop_all_processes,
  104. rsa_encrypt_aes_key,
  105. secure_get_announcements,
  106. secure_user_login,
  107. secure_user_register,
  108. forgot_password_request,
  109. secure_user_unbind,
  110. secure_user_change_password,
  111. secure_user_recharge,
  112. store_rsa_public_key,
  113. has_stored_rsa_key,
  114. clear_stored_rsa_key,
  115. rsa_encrypt_aes_key_by_stored_key,
  116. get_rsa_key_version,
  117. // 安全通信模块命令
  118. initialize_security_client,
  119. check_security_initialized,
  120. get_security_status,
  121. refresh_security_keys,
  122. reset_security_client,
  123. sync_hmac_key,
  124. secure_buff_filter_options,
  125. secure_buff_goods_attr_list,
  126. secure_buff_selection_config,
  127. secure_buff_selection_start,
  128. secure_buff_selection_log,
  129. secure_buff_selection_result,
  130. secure_buff_selection_stop,
  131. secure_keys_hmac,
  132. // 密钥管理命令
  133. get_key_manager_status,
  134. get_hmac_key_status,
  135. // 心跳管理命令
  136. get_heartbeat_state_command,
  137. stop_heartbeat_command,
  138. get_heartbeat_config_command,
  139. read_text_file,
  140. // 更新相关
  141. // updater::check_for_updates,
  142. // updater::manual_update_check,
  143. // updater::start_manual_update
  144. ])
  145. .setup(|app| {
  146. heartbeat::set_app_handle(app.handle().clone());
  147. Ok(())
  148. })
  149. .run(tauri::generate_context!())
  150. .expect("error while running tauri application");
  151. }