Skip to content

Commit

Permalink
fix(simctl): Merge boot and open actions into a single action (#15963)
Browse files Browse the repository at this point in the history
* fix(simctl):  Merge boot and open actions into a single action

* remove async
  • Loading branch information
gutenye authored Dec 21, 2024
1 parent 23964ee commit 1bcd3d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
4 changes: 4 additions & 0 deletions extensions/simctl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Simulator Control Changelog

## [Update] - 2024-12-20

- Merge boot and open actions into a single action

## [Update Icons + Rename "Show" Actions for clarity] - {PR_MERGE_DAET}

- different icons for devices
Expand Down
67 changes: 29 additions & 38 deletions extensions/simctl/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionPanel, List, Action, Color, Icon } from "@raycast/api";
import { ActionPanel, List, Action, Color, Icon, useNavigation, closeMainWindow } from "@raycast/api";
import { useCachedState } from "@raycast/utils";
import { exec } from "child_process";
import { useEffect, useState } from "react";
Expand Down Expand Up @@ -40,50 +40,42 @@ export default function Command() {
fetchSimulators();
}, []);

const openAction = (device: Device) => {
if (device.state !== "Booted") {
return null;
}
return (
<Action
title="Open"
icon={Icon.Window}
onAction={() => {
exec(`open -g -a Simulator`);
const appleScript = `
if running of application "Simulator" then
tell application "System Events"
set theWindows to windows of (processes whose name is "Simulator")
repeat with theWindow in (the first item of theWindows)
set theWindowName to name of theWindow
if theWindowName contains "${device.name}" then
perform action "AXRaise" of theWindow
end if
end repeat
end tell
tell the application "Simulator"
activate
end tell
end if
`;
exec(`osascript -e '${appleScript}'`);
}}
/>
);
};

const bootAction = (device: Device) => {
if (device.state === "Booted") {
return null;
}
const navigation = useNavigation();

return (
<Action
title="Boot"
title={device.state === "Booted" ? "Open" : "Boot"}
icon={Icon.Power}
onAction={() => {
exec(`xcrun simctl boot ${device.udid}`, () => {
fetchSimulators();
});
exec(`open -g -a Simulator`);
const appleScript = `
tell application "System Events"
repeat
set windowFound to false
set theWindows to windows of process "Simulator"
repeat with theWindow in theWindows
set theWindowName to name of theWindow
if theWindowName contains "${device.name}" then
tell application "Simulator" to activate
perform action "AXRaise" of theWindow
set windowFound to true
exit repeat
end if
delay 0.1
end repeat
if windowFound then
exit repeat
end if
end repeat
end tell
`;
exec(`osascript -e '${appleScript}'`);
navigation.pop();
closeMainWindow({ clearRootSearch: true });
}}
/>
);
Expand Down Expand Up @@ -138,7 +130,6 @@ export default function Command() {
]}
actions={
<ActionPanel>
{openAction(device)}
{bootAction(device)}
{shutdownAction(device)}
<Action.Open title="Open Data Folder" icon={Icon.Folder} target={device.dataPath} />
Expand Down

0 comments on commit 1bcd3d9

Please sign in to comment.