Skip to content

Commit

Permalink
fix: correctly determine ANDROID_HOME (#10) (#11)
Browse files Browse the repository at this point in the history
* fix: correctly determine ANDROID_HOME
  • Loading branch information
fax1ty authored Dec 7, 2024
1 parent 20cd7ad commit a36161c
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "emu",
"private": true,
"version": "0.2.2",
"version": "0.2.3",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "emu"
version = "0.2.2"
version = "0.2.3"
description = "Manage emulators with ease"
authors = ["fax1ty"]
edition = "2021"
Expand Down
7 changes: 0 additions & 7 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ use tauri::{
};
use tauri_plugin_positioner::{Position, WindowExt};

#[tauri::command]
fn get_android_home() -> Result<String, String> {
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()
Expand All @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/device-options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const DeivceOptionsModal = () => {
if (!deviceOptionsInfo) return;

setDeviceOptionsModalVisible(false);
await startEmulator(deviceOptionsInfo.name);
await startEmulator(deviceOptionsInfo.name, true);
};

const onClose = () => {
Expand Down
9 changes: 6 additions & 3 deletions src/queries/emulator.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -34,7 +37,7 @@ export const useEmulators = () => {
disabled ? null : "emulators",
async () => {
try {
await invoke<string>("get_android_home");
await getAndroidHome();
} catch (error) {
const { isDangerModeEnabled } = useAppStore.getState();
if (!isDangerModeEnabled) setAndroidHomeModalVisible(true);
Expand Down
6 changes: 5 additions & 1 deletion src/services/api/emulator.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down Expand Up @@ -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");
};
14 changes: 14 additions & 0 deletions src/services/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

0 comments on commit a36161c

Please sign in to comment.