Skip to content

Commit a973c36

Browse files
committed
feat: add wezterm support
1 parent 736d6d8 commit a973c36

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

MiniSim/Service/DeviceService.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,10 @@ extension DeviceService {
412412
guard let deviceId = device.identifier else {
413413
throw DeviceError.deviceNotFound
414414
}
415-
guard let preferedTerminal = Terminal(
416-
rawValue: UserDefaults.standard.preferedTerminal ?? Terminal.terminal.rawValue
417-
)
418-
else { return }
419-
let terminal = TerminalService.getTerminal(type: preferedTerminal)
420-
try TerminalService.launchTerminal(terminal: terminal, deviceId: deviceId)
415+
416+
guard let adbPath = try? ADB.getAdbPath() else { return }
417+
let logcatCommand = "\(adbPath) -s \(deviceId) logcat -v color"
418+
try TerminalService.launchTerminal(command: logcatCommand)
421419
}
422420

423421
static func handleAndroidAction(device: Device, commandTag: SubMenuItems.Tags, itemName: String) {

MiniSim/Service/Terminal/Terminal.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ShellOut
1010

1111
protocol TerminalServiceProtocol {
1212
static func getTerminal(type: Terminal) -> TerminalApp
13-
static func launchTerminal(terminal: TerminalApp, deviceId: String) throws
13+
static func launchTerminal(command: String, terminal: TerminalApp) throws
1414
}
1515

1616
class TerminalService: TerminalServiceProtocol {
@@ -20,12 +20,22 @@ class TerminalService: TerminalServiceProtocol {
2020
return AppleTerminal()
2121
case .iterm:
2222
return ITermTerminal()
23+
case .wezterm:
24+
return WezTermTerminal()
2325
}
2426
}
2527

26-
static func launchTerminal(terminal: TerminalApp, deviceId: String) throws {
27-
let logcatCommand = "adb -s \(deviceId) logcat -v color"
28-
let terminalScript = terminal.getLaunchScript(deviceId: deviceId, logcatCommand: logcatCommand)
28+
private static func getPrefferedTerminal() -> TerminalApp {
29+
guard let preferedTerminal = Terminal(
30+
rawValue: UserDefaults.standard.preferedTerminal ?? Terminal.terminal.rawValue
31+
)
32+
else { return getTerminal(type: Terminal.terminal) }
33+
34+
return getTerminal(type: preferedTerminal)
35+
}
36+
37+
static func launchTerminal(command: String, terminal: TerminalApp = getPrefferedTerminal()) throws {
38+
let terminalScript = terminal.getLaunchScript(logcatCommand: command)
2939
try shellOut(to: "osascript -e '\(terminalScript)'")
3040
}
3141
}

MiniSim/Service/Terminal/TerminalApps.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ import Foundation
99

1010
protocol TerminalApp {
1111
var name: String { get }
12-
func getLaunchScript(deviceId: String, logcatCommand: String) -> String
12+
func getLaunchScript(logcatCommand: String) -> String
1313
}
1414

1515
enum Terminal: String, CaseIterable {
1616
case terminal = "Terminal"
1717
case iterm = "iTerm"
18+
case wezterm = "WezTerm"
1819
}
1920

2021
struct AppleTerminal: TerminalApp {
2122
var name: String = "Terminal"
22-
func getLaunchScript(deviceId: String, logcatCommand: String) -> String {
23+
func getLaunchScript(logcatCommand: String) -> String {
2324
"""
2425
tell app \"Terminal\"
2526
activate
@@ -32,7 +33,7 @@ struct AppleTerminal: TerminalApp {
3233
struct ITermTerminal: TerminalApp {
3334
var name: String = "iTerm"
3435

35-
func getLaunchScript(deviceId: String, logcatCommand: String) -> String {
36+
func getLaunchScript(logcatCommand: String) -> String {
3637
"""
3738
tell app \"iTerm\"
3839
set newWindow to (create window with default profile)
@@ -43,3 +44,14 @@ struct ITermTerminal: TerminalApp {
4344
"""
4445
}
4546
}
47+
48+
struct WezTermTerminal: TerminalApp {
49+
var name: String = "WezTerm"
50+
51+
func getLaunchScript(logcatCommand: String) -> String {
52+
"""
53+
tell application \"wezterm\" to activate
54+
do shell script \"/Applications/WezTerm.app/Contents/MacOS/wezterm cli spawn \(logcatCommand)\"
55+
"""
56+
}
57+
}

0 commit comments

Comments
 (0)