chore: Separate configuration for android build in release mode

This commit is contained in:
Vanalite 2025-09-18 11:32:52 +07:00
parent 4205b2a479
commit 21d0943aa4
8 changed files with 44 additions and 9 deletions

View File

@ -91,3 +91,11 @@ windows-sys = { version = "0.60.2", features = ["Win32_Storage_FileSystem"] }
tauri-plugin-updater = "2"
once_cell = "1.18"
tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] }
# Release profile optimizations for minimal binary size
[profile.release]
opt-level = "z" # Optimize for size
lto = true # Enable Link Time Optimization
strip = true # Strip symbols for smaller binary
codegen-units = 1 # Reduce parallel codegen for better optimization
panic = "abort" # Don't unwind on panic, saves space

View File

@ -14,12 +14,12 @@ pub async fn start_server<R: Runtime>(
api_key: String,
trusted_hosts: Vec<String>,
proxy_timeout: u64,
) -> Result<bool, String> {
) -> Result<u16, String> {
let server_handle = state.server_handle.clone();
let plugin_state: State<LlamacppState> = app_handle.state();
let sessions = plugin_state.llama_server_process.clone();
proxy::start_server(
let actual_port = proxy::start_server(
server_handle,
sessions,
host,
@ -31,7 +31,7 @@ pub async fn start_server<R: Runtime>(
)
.await
.map_err(|e| e.to_string())?;
Ok(true)
Ok(actual_port)
}
#[tauri::command]

View File

@ -632,7 +632,7 @@ pub async fn start_server(
proxy_api_key: String,
trusted_hosts: Vec<Vec<String>>,
proxy_timeout: u64,
) -> Result<bool, Box<dyn std::error::Error + Send + Sync>> {
) -> Result<u16, Box<dyn std::error::Error + Send + Sync>> {
let mut handle_guard = server_handle.lock().await;
if handle_guard.is_some() {
return Err("Server is already running".into());
@ -667,7 +667,8 @@ pub async fn start_server(
});
let server = Server::bind(&addr).serve(make_svc);
log::info!("Jan API server started on http://{}", addr);
let actual_addr = server.local_addr();
log::info!("Jan API server started on http://{}", actual_addr);
let server_task = tokio::spawn(async move {
if let Err(e) = server.await {
@ -678,7 +679,9 @@ pub async fn start_server(
});
*handle_guard = Some(server_task);
Ok(true)
let actual_port = actual_addr.port();
log::info!("Jan API server started successfully on port {}", actual_port);
Ok(actual_port)
}
pub async fn stop_server(

View File

@ -0,0 +1,7 @@
{
"app": {
"security": {
"capabilities": ["default"]
}
}
}

View File

@ -1,6 +1,12 @@
{
"app": {
"security": {
"capabilities": ["default"]
}
},
"bundle": {
"iOS": {
"developmentTeam": "<DEVELOPMENT_TEAM_ID>"
}
}
}

View File

@ -40,7 +40,8 @@ export const useLocalApiServer = create<LocalApiServerState>()(
setEnableOnStartup: (value) => set({ enableOnStartup: value }),
serverHost: '127.0.0.1',
setServerHost: (value) => set({ serverHost: value }),
serverPort: 1337,
// Use port 0 (auto-assign) for mobile to avoid conflicts, 1337 for desktop
serverPort: (typeof window !== 'undefined' && (window as any).IS_ANDROID) || (typeof window !== 'undefined' && (window as any).IS_IOS) ? 0 : 1337,
setServerPort: (value) => set({ serverPort: value }),
apiPrefix: '/v1',
setApiPrefix: (value) => set({ apiPrefix: value }),

View File

@ -31,6 +31,7 @@ export function DataProvider() {
enableOnStartup,
serverHost,
serverPort,
setServerPort,
apiPrefix,
apiKey,
trustedHosts,
@ -173,7 +174,11 @@ export function DataProvider() {
proxyTimeout: proxyTimeout,
})
})
.then(() => {
.then((actualPort: number) => {
// Store the actual port that was assigned (important for mobile with port 0)
if (actualPort && actualPort !== serverPort) {
setServerPort(actualPort)
}
setServerStatus('running')
})
.catch((error: unknown) => {

View File

@ -48,6 +48,7 @@ function LocalAPIServerContent() {
setEnableOnStartup,
serverHost,
serverPort,
setServerPort,
apiPrefix,
apiKey,
trustedHosts,
@ -162,7 +163,11 @@ function LocalAPIServerContent() {
proxyTimeout: proxyTimeout,
})
})
.then(() => {
.then((actualPort: number) => {
// Store the actual port that was assigned (important for mobile with port 0)
if (actualPort && actualPort !== serverPort) {
setServerPort(actualPort)
}
setServerStatus('running')
})
.catch((error: unknown) => {