Skip to content

Commit

Permalink
Bottle Terminal button
Browse files Browse the repository at this point in the history
  • Loading branch information
nastys committed Feb 23, 2024
1 parent e38646a commit 2190ffa
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
35 changes: 35 additions & 0 deletions Whisky/Extensions/Bottle+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,36 @@
import Foundation
import AppKit
import WhiskyKit
import os.log

extension Bottle {
func openCDrive() {
NSWorkspace.shared.open(url.appending(path: "drive_c"))
}

func openTerminal() {
let cmd = Wine.generateTerminalEnvironmentCommand(bottle: self)

let script = """
tell application "Terminal"
activate
do script "\(cmd)"
end tell
"""

Task.detached(priority: .userInitiated) {
var error: NSDictionary?
guard let appleScript = NSAppleScript(source: script) else { return }
appleScript.executeAndReturnError(&error)

if let error = error {
Logger.wineKit.error("Failed to run terminal script \(error)")
guard let description = error["NSAppleScriptErrorMessage"] as? String else { return }
await self.showRunError(message: String(describing: description))
}
}
}

@discardableResult
func getStartMenuPrograms() -> [Program] {
let globalStartMenu = url
Expand Down Expand Up @@ -174,4 +198,15 @@ extension Bottle {
func rename(newName: String) {
settings.name = newName
}

@MainActor private func showRunError(message: String) {
let alert = NSAlert()
alert.messageText = String(localized: "alert.message")
alert.informativeText = String(localized: "alert.info")
+ " \(self.url.lastPathComponent): "
+ message
alert.alertStyle = .critical
alert.addButton(withTitle: String(localized: "button.ok"))
alert.runModal()
}
}
13 changes: 12 additions & 1 deletion Whisky/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,17 @@
}
}
},
"button.terminal" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Terminal"
}
}
}
},
"button.unpin" : {
"localizations" : {
"da" : {
Expand Down Expand Up @@ -16655,4 +16666,4 @@
}
},
"version" : "1.0"
}
}
3 changes: 3 additions & 0 deletions Whisky/Views/Bottle/BottleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ struct BottleView: View {
Button("button.cDrive") {
bottle.openCDrive()
}
Button("button.terminal") {
bottle.openTerminal()
}
Button("button.winetricks") {
showWinetricksSheet.toggle()
}
Expand Down
12 changes: 11 additions & 1 deletion WhiskyKit/Sources/WhiskyKit/Wine/Wine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,22 @@ public class Wine {
var wineCmd = "\(wineBinary.esc) start /unix \(bottle.url.esc) \(args)"
let env = constructWineEnvironment(for: bottle, environment: environment)
for environment in env {
wineCmd = "\(environment.key)=\(environment.value) " + wineCmd
wineCmd = "\(environment.key)=\"\(environment.value)\" " + wineCmd
}

return wineCmd
}

public static func generateTerminalEnvironmentCommand(bottle: Bottle) -> String {
var cmd = "export PATH=\\\"\(GPTKInstaller.binFolder.path):$PATH\\\"\nexport WINE=\\\"wine64\\\"\nalias wine=\\\"wine64\\\"\nalias winecfg=\\\"wine64 winecfg\\\"\nalias msiexec=\\\"wine64 msiexec\\\"\nalias regedit=\\\"wine64 regedit\\\"\nalias regsvr32=\\\"wine64 regsvr32\\\"\nalias wineboot=\\\"wine64 wineboot\\\"\nalias wineconsole=\\\"wine64 wineconsole\\\"\nalias winedbg=\\\"wine64 winedbg\\\"\nalias winefile=\\\"wine64 winefile\\\"\nalias winepath=\\\"wine64 winepath\\\""

Check failure on line 125 in WhiskyKit/Sources/WhiskyKit/Wine/Wine.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 200 characters or less; currently it has 490 characters (line_length)
let env = constructWineEnvironment(for: bottle, environment: constructWineEnvironment(for: bottle))
for environment in env {
cmd += "\nexport \(environment.key)=\\\"\(environment.value)\\\""
}

return cmd
}

/// Run a `wineserver` command with the given arguments and return the output result
private static func runWineserver(_ args: [String], bottle: Bottle) async throws -> String {
var result: [ProcessOutput] = []
Expand Down

0 comments on commit 2190ffa

Please sign in to comment.