fix: 统一端口并完善桌面端授权和安装
This commit is contained in:
Generated
+1
-1
@@ -235,7 +235,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "capacity-report-desktop"
|
||||
version = "2.0.3"
|
||||
version = "3.0.0"
|
||||
dependencies = [
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "capacity-report-desktop"
|
||||
version = "2.0.3"
|
||||
version = "3.0.0"
|
||||
description = "CapacityReport desktop shell"
|
||||
authors = ["NIXEVOL"]
|
||||
edition = "2021"
|
||||
@@ -9,7 +9,7 @@ edition = "2021"
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = ["devtools"] }
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri-plugin-shell = "2"
|
||||
|
||||
[features]
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
"identifier": "default",
|
||||
"description": "Default desktop permissions",
|
||||
"windows": ["main"],
|
||||
"permissions": ["core:default"]
|
||||
"permissions": ["core:default", "core:webview:deny-internal-toggle-devtools"]
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"default":{"identifier":"default","description":"Default desktop permissions","local":true,"windows":["main"],"permissions":["core:default"]}}
|
||||
{"default":{"identifier":"default","description":"Default desktop permissions","local":true,"windows":["main"],"permissions":["core:default","core:webview:deny-internal-toggle-devtools"]}}
|
||||
+26
-3
@@ -13,6 +13,11 @@ use tauri::{Manager, Runtime};
|
||||
use tauri_plugin_shell::process::CommandChild;
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
|
||||
const SERVER_PORT: u16 = 9081;
|
||||
const SERVER_ADDR: &str = "127.0.0.1:9081";
|
||||
#[cfg(target_os = "windows")]
|
||||
const SERVER_PROCESS_NAME: &str = "capareport-server.exe";
|
||||
|
||||
struct ServerProcess {
|
||||
child: CommandChild,
|
||||
pid: u32,
|
||||
@@ -70,8 +75,9 @@ fn start_server<R: Runtime>(app: &tauri::App<R>) -> Result<(), Box<dyn Error>> {
|
||||
fs::create_dir_all(data_dir.join("logs"))?;
|
||||
copy_resource(app, "Configure.json", &data_dir)?;
|
||||
copy_resource(app, "ReportScript.sql", &data_dir)?;
|
||||
stop_existing_server_on_port(19082);
|
||||
stop_existing_server_on_port(SERVER_PORT);
|
||||
|
||||
let port_arg = SERVER_PORT.to_string();
|
||||
let (mut rx, child) = app
|
||||
.shell()
|
||||
.sidecar("capareport-server")?
|
||||
@@ -79,10 +85,10 @@ fn start_server<R: Runtime>(app: &tauri::App<R>) -> Result<(), Box<dyn Error>> {
|
||||
"CAPAREPORT_BASE_DIR",
|
||||
data_dir.to_string_lossy().to_string(),
|
||||
)
|
||||
.args(["--host", "127.0.0.1", "--port", "19082"])
|
||||
.args(["--host", "127.0.0.1", "--port", &port_arg])
|
||||
.spawn()?;
|
||||
|
||||
if let Err(error) = wait_for_server("127.0.0.1:19082", Duration::from_secs(60)) {
|
||||
if let Err(error) = wait_for_server(SERVER_ADDR, Duration::from_secs(60)) {
|
||||
let _ = child.kill();
|
||||
return Err(error);
|
||||
}
|
||||
@@ -139,6 +145,9 @@ fn stop_existing_server_on_port(port: u16) {
|
||||
if pid.parse::<u32>().is_err() {
|
||||
continue;
|
||||
}
|
||||
if !is_capareport_server_pid(pid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let _ = std::process::Command::new("taskkill")
|
||||
.args(["/F", "/T", "/PID", pid])
|
||||
@@ -146,6 +155,20 @@ fn stop_existing_server_on_port(port: u16) {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn is_capareport_server_pid(pid: &str) -> bool {
|
||||
let Ok(output) = std::process::Command::new("tasklist")
|
||||
.args(["/FI", &format!("PID eq {pid}"), "/FO", "CSV", "/NH"])
|
||||
.output()
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
.to_ascii_lowercase()
|
||||
.contains(SERVER_PROCESS_NAME)
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn stop_existing_server_on_port(_port: u16) {}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "CapacityReport",
|
||||
"version": "2.0.3",
|
||||
"version": "3.0.0",
|
||||
"identifier": "com.nixevol.capacityreport",
|
||||
"build": {
|
||||
"frontendDist": "../frontend/dist"
|
||||
@@ -14,8 +14,7 @@
|
||||
"width": 1280,
|
||||
"height": 820,
|
||||
"minWidth": 1100,
|
||||
"minHeight": 720,
|
||||
"devtools": true
|
||||
"minHeight": 720
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
@@ -47,6 +46,7 @@
|
||||
},
|
||||
"nsis": {
|
||||
"installerHooks": "./windows/nsis-hooks.nsh",
|
||||
"installMode": "perMachine",
|
||||
"languages": [
|
||||
"SimpChinese"
|
||||
]
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
!macro ResolveCapacityReportInstallDir
|
||||
${If} ${FileExists} "D:\*.*"
|
||||
StrCpy $R9 "D:\Program Files\${PRODUCTNAME}"
|
||||
${Else}
|
||||
${If} ${RunningX64}
|
||||
StrCpy $R9 "$PROGRAMFILES64\${PRODUCTNAME}"
|
||||
${Else}
|
||||
StrCpy $R9 "$PROGRAMFILES\${PRODUCTNAME}"
|
||||
${EndIf}
|
||||
${EndIf}
|
||||
!macroend
|
||||
|
||||
!macro NSIS_HOOK_PREINSTALL
|
||||
!insertmacro ResolveCapacityReportInstallDir
|
||||
StrCpy $INSTDIR "$R9"
|
||||
SetOutPath "$INSTDIR"
|
||||
!macroend
|
||||
|
||||
!macro NSIS_HOOK_POSTINSTALL
|
||||
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}"
|
||||
DeleteRegKey HKCU "Software\${MANUFACTURER}\${PRODUCTNAME}"
|
||||
!macroend
|
||||
|
||||
!macro NSIS_HOOK_PREUNINSTALL
|
||||
nsExec::ExecToLog 'taskkill /F /T /IM capacity-report-desktop.exe'
|
||||
nsExec::ExecToLog 'taskkill /F /T /IM capareport-server.exe'
|
||||
|
||||
Reference in New Issue
Block a user