diff --git a/package.json b/package.json index 21f256b..85cd3f6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "emu", "private": true, - "version": "0.2.2", + "version": "0.2.3", "type": "module", "scripts": { "dev": "vite", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 5966af8..5d49123 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -878,7 +878,7 @@ checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7" [[package]] name = "emu" -version = "0.2.2" +version = "0.2.3" dependencies = [ "serde", "serde_json", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 713ce05..4880b56 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "emu" -version = "0.2.2" +version = "0.2.3" description = "Manage emulators with ease" authors = ["fax1ty"] edition = "2021" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 319ccf7..8317d89 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -9,12 +9,6 @@ use tauri::{ }; use tauri_plugin_positioner::{Position, WindowExt}; -#[tauri::command] -fn get_android_home() -> Result { - let v = env::var("ANDROID_HOME").map_err(|err| err.to_string())?; - Ok(v) -} - #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() @@ -27,7 +21,6 @@ pub fn run() { .plugin(tauri_plugin_os::init()) .plugin(tauri_plugin_process::init()) .plugin(tauri_plugin_shell::init()) - .invoke_handler(tauri::generate_handler![get_android_home]) .setup(|app| { let aligned = Arc::new(Mutex::new(false)); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 7864351..35139ed 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "emu", - "version": "0.2.2", + "version": "0.2.3", "identifier": "emu.app", "build": { "beforeDevCommand": "bun run dev", diff --git a/src/components/modals/device-options.tsx b/src/components/modals/device-options.tsx index 479a421..fbfc283 100644 --- a/src/components/modals/device-options.tsx +++ b/src/components/modals/device-options.tsx @@ -28,7 +28,7 @@ export const DeivceOptionsModal = () => { if (!deviceOptionsInfo) return; setDeviceOptionsModalVisible(false); - await startEmulator(deviceOptionsInfo.name); + await startEmulator(deviceOptionsInfo.name, true); }; const onClose = () => { diff --git a/src/queries/emulator.ts b/src/queries/emulator.ts index ce8040c..07bea02 100644 --- a/src/queries/emulator.ts +++ b/src/queries/emulator.ts @@ -1,7 +1,10 @@ -import { invoke } from "@tauri-apps/api/core"; import useSWR, { useSWRConfig } from "swr"; -import { getAllEmulators, getOnlineEmulators } from "@/services/api/emulator"; +import { + getAllEmulators, + getAndroidHome, + getOnlineEmulators, +} from "@/services/api/emulator"; import { useAppStore } from "@/stores/app"; import { useModalsStore } from "@/stores/modals"; import { Device } from "@/types/device"; @@ -34,7 +37,7 @@ export const useEmulators = () => { disabled ? null : "emulators", async () => { try { - await invoke("get_android_home"); + await getAndroidHome(); } catch (error) { const { isDangerModeEnabled } = useAppStore.getState(); if (!isDangerModeEnabled) setAndroidHomeModalVisible(true); diff --git a/src/services/api/emulator.ts b/src/services/api/emulator.ts index d985cb0..1aa8b2b 100644 --- a/src/services/api/emulator.ts +++ b/src/services/api/emulator.ts @@ -1,4 +1,4 @@ -import { adb, emulator } from "@/services/execute"; +import { adb, emulator, printenv } from "@/services/execute"; import { Device, DeviceState, DeviceType } from "@/types/device"; export const getAllEmulators = async () => { @@ -104,3 +104,7 @@ export const startEmulator = async (name: string, cold = false) => { export const stopEmulator = async (id: string) => { await adb(`-s ${id} emu kill`); }; + +export const getAndroidHome = () => { + return printenv("ANDROID_HOME"); +}; diff --git a/src/services/execute.ts b/src/services/execute.ts index 3894683..a6ac0a8 100644 --- a/src/services/execute.ts +++ b/src/services/execute.ts @@ -58,3 +58,17 @@ export const adb = (command: string) => { export const simctl = (command: string) => { return execute("xcrun simctl", command); }; + +export const printenv = async (name: string) => { + const currentPlatfrom = platform(); + + switch (currentPlatfrom) { + case "windows": + const variable = await execute("echo", `%${name}%`); + if (variable === `%${name}%`) throw new Error("Variable is not found"); + return variable; + + default: + return execute("printenv", name); + } +};