Skip to content

Commit

Permalink
Merge pull request #1 from fax1ty/feat/macos
Browse files Browse the repository at this point in the history
feat: macos support
  • Loading branch information
fax1ty authored Nov 12, 2024
2 parents 4fe0900 + 89446ad commit 2f9d56c
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 69 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
fail-fast: false
matrix:
include:
# - platform: "macos-latest" # for Arm based macs (M1 and above).
# args: "--target aarch64-apple-darwin"
# - platform: "macos-latest" # for Intel based macs.
# args: "--target x86_64-apple-darwin"
# - platform: "ubuntu-22.04" # for Tauri v1 you could replace this with ubuntu-20.04.
- platform: "macos-latest" # for Arm based macs (M1 and above).
args: "--target aarch64-apple-darwin"
- platform: "macos-latest" # for Intel based macs.
args: "--target x86_64-apple-darwin"
# - platform: "ubuntu-22.04"
# args: ""
- platform: "windows-latest"
args: ""
Expand Down
Binary file modified bun.lockb
100644 → 100755
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "emu",
"private": true,
"version": "0.1.0",
"version": "0.1.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -14,6 +14,7 @@
"@radix-ui/react-alert-dialog": "^1.1.2",
"@radix-ui/react-slot": "^1.1.0",
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-os": "~2",
"@tauri-apps/plugin-process": "~2",
"@tauri-apps/plugin-shell": "~2",
"class-variance-authority": "^0.7.0",
Expand Down
80 changes: 79 additions & 1 deletion src-tauri/Cargo.lock

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

9 changes: 5 additions & 4 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "emu"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
version = "0.1.1"
description = "Manage emulators with ease"
authors = ["fax1ty"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -18,9 +18,10 @@ crate-type = ["staticlib", "cdylib", "rlib"]
tauri-build = { version = "2", features = [] }

[dependencies]
tauri = { version = "2", features = [] }
tauri = { version = "2", features = ["macos-private-api"] }
tauri-plugin-shell = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-process = "2"
tauri-plugin-positioner = "2"
tauri-plugin-os = "2"
8 changes: 7 additions & 1 deletion src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
"name": "cmd.exe",
"cmd": "cmd.exe",
"args": true
},
{
"name": "sh",
"cmd": "sh",
"args": true
}
]
},
"process:default"
"process:default",
"os:default"
]
}
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn get_android_home() -> Result<String, String> {
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![get_android_home])
Expand Down
3 changes: 2 additions & 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.1.0",
"version": "0.1.1",
"identifier": "emu.app",
"build": {
"beforeDevCommand": "bun run dev",
Expand All @@ -10,6 +10,7 @@
"frontendDist": "../dist"
},
"app": {
"macOSPrivateApi": true,
"windows": [
{
"title": "emu",
Expand Down
34 changes: 17 additions & 17 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ function App() {
await window.close();
};

if (!emulators) return null;

return (
<>
<nav
Expand Down Expand Up @@ -62,20 +60,22 @@ function App() {
</nav>

<main className="flex-1 px-4 pb-2 py-1">
<ul>
{Object.values(emulators).map((emulator, i) => (
<EmulatorListItem
key={i}
emulator={emulator}
onOptionsButtonPressed={(event) => {
setSelectedEmulator(emulator.name);
show({
event,
});
}}
/>
))}
</ul>
{emulators && (
<ul>
{Object.values(emulators).map((emulator, i) => (
<EmulatorListItem
key={i}
emulator={emulator}
onOptionsButtonPressed={(event) => {
setSelectedEmulator(emulator.name);
show({
event,
});
}}
/>
))}
</ul>
)}
</main>

<Menu
Expand All @@ -87,7 +87,7 @@ function App() {
<Item
disabled={
!selectedEmulator ||
emulators[selectedEmulator]?.state !== "offline"
emulators?.[selectedEmulator]?.state !== "offline"
}
onClick={async () => {
if (!selectedEmulator) return;
Expand Down
47 changes: 13 additions & 34 deletions src/services/api/emulator.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { execute } from "@/services/execute";
import { adb, emulator } from "@/services/execute";
import {
OnlineEmulator,
OnlineEmulatorState,
OnlineEmulatorType,
} from "@/types/emulator";

export const getAllEmulators = async () => {
const output = await execute("cmd.exe", [
"/c",
"%ANDROID_HOME%/emulator/emulator.exe -list-avds",
]);
const output = await emulator("-list-avds");
return output
.split("\r\n")
.split("\n")
.map((v) => v.trim())
.filter((v) => {
if (!v) return false;
Expand All @@ -21,11 +18,8 @@ export const getAllEmulators = async () => {
};

export const getEmulatorName = async (id: string) => {
const output = await execute("cmd.exe", [
"/c",
`%ANDROID_HOME%/platform-tools/adb.exe -s ${id} emu avd name`,
]);
return output.split("\r\n").map((v) => v.trim())[0];
const output = await adb(`-s ${id} emu avd name`);
return output.split("\n").map((v) => v.trim())[0];
};

export const getEmulatorState = (
Expand All @@ -36,23 +30,17 @@ export const getEmulatorState = (
};

export const getEmulatorProps = async (id: string) => {
const output = await execute("cmd.exe", [
"/c",
`%ANDROID_HOME%/platform-tools/adb.exe -s ${id} shell getprop`,
]);
const kv = output.split("\r\n").map((v) => {
const output = await adb(`-s ${id} shell getprop`);
const kv = output.split("\n").map((v) => {
const [key, value] = v.replace(/(\[|\])/gm, "").split(": ");
return [key, value];
});
return Object.fromEntries(kv) as Record<string, string>;
};

export const getEmulatorFeatures = async (id: string) => {
const output = await execute("cmd.exe", [
"/c",
`%ANDROID_HOME%/platform-tools/adb.exe -s ${id} shell pm list features`,
]);
return output.split("\r\n");
const output = await adb(`-s ${id} shell pm list features`);
return output.split("\n");
};

export const getEmulatorType = (features: string[]): OnlineEmulatorType => {
Expand All @@ -63,12 +51,9 @@ export const getEmulatorType = (features: string[]): OnlineEmulatorType => {
};

export const getOnlineEmulators = async () => {
const output = await execute("cmd.exe", [
"/c",
"%ANDROID_HOME%/platform-tools/adb.exe devices -l",
]);
const output = await adb("devices -l");
const rows = output
.split("\r\n")
.split("\n")
.map((v) => v.trim())
.filter((v) => {
if (!v) return false;
Expand Down Expand Up @@ -116,15 +101,9 @@ export const startEmulator = async (name: string, cold = false) => {

if (cold) args.push("-no-snapshot-load");

await execute("cmd.exe", [
"/c",
`%ANDROID_HOME%/emulator/emulator.exe ` + args.join(" "),
]);
await emulator(args.join(" "));
};

export const stopEmulator = async (id: string) => {
await execute("cmd.exe", [
"/c",
`%ANDROID_HOME%/platform-tools/adb.exe -s ${id} emu kill`,
]);
await adb(`-s ${id} emu kill`);
};
Loading

0 comments on commit 2f9d56c

Please sign in to comment.