Whisky-App / Whisky

A modern Wine wrapper for macOS built with SwiftUI
https://getwhisky.app
GNU General Public License v3.0
13.06k stars 280 forks source link

[Bug]: Created Shortcuts Fails to Run for Programs with Spaces in Path #904

Open Zetacat opened 8 months ago

Zetacat commented 8 months ago

Description

I encountered a bug related to the "Create Shortcut" feature. This feature allows users to create macOS shortcuts for quickly launching target applications. However, shortcuts fail to launch when the target executable's path contains spaces.

Some workaround

After I manually modified the shell script in the "launch" file, the shortcut can be executed normally.

original script:

#!/bin/bash
WINEPREFIX=/Users/{username}/Library/Containers/com.isaacmarovitz.Whisky/Bottles/76EA5598-DC91-479B-982A-2A41E35879B2 WINEDLLOVERRIDES=dxgi,d3d9,d3d10core,d3d11=b WINEDEBUG=fixme-all DXVK_ASYNC=1 WINEMSYNC=1 WINEESYNC=1 LC_ALL=en_US /Users/{username}/Library/Application\ Support/com.isaacmarovitz.Whisky/Libraries/Wine/bin/wine64 start /unix /Users/{username}/Library/Containers/com.isaacmarovitz.Whisky/Bottles/76EA5598-DC91-479B-982A-2A41E35879B2/drive_c/Program Files (x86)/Steam/Steam.exe 

modified script:

#!/bin/bash
WINEPREFIX=/Users/{username}/Library/Containers/com.isaacmarovitz.Whisky/Bottles/76EA5598-DC91-479B-982A-2A41E35879B2 WINEDLLOVERRIDES="dxgi,d3d9,d3d10core,d3d11=b" LC_ALL=en_US WINEESYNC=1 /Users/{username}/Library/Application\ Support/com.isaacmarovitz.Whisky/Libraries/Wine/bin/wine64 start /unix "/Users/{username}/Library/Containers/com.isaacmarovitz.Whisky/Bottles/76EA5598-DC91-479B-982A-2A41E35879B2/drive_c/Program Files (x86)/Steam/Steam.exe" 

Steps to reproduce

  1. Right-click on a program within Whisky that has a path with spaces. e.g. /Users/{username}/Library/Containers/com.isaacmarovitz.Whisky/Bottles/76EA5598-DC91-479B-982A-2A41E35879B2/drive_c/Program Files (x86)/Steam/Steam.exe
  2. Select "Config" and then click on "Create Shortcut" to generate a macOS app shortcut. Attempt to launch the created shortcut.

Workaround:

  1. Right click the created shortcut, select "Show Package Contents".
  2. Open Contents/MacOS/launch with any text editing app.
  3. wrap the .exe path with quotation marks "", save the file.

Expected behaviour

The shortcut successfully launches the Windows application through Whisky.

Logs

There isn't any log file, since the script didn't run successfully.

What version of Whisky are you using?

2.2.4

What version of macOS are you using?

Sonoma (macOS 14)

Issue Language

Zetacat commented 8 months ago

That's quite weird, I found out that the spaces in the path are escaped in the code.

in Whisky/WhiskyKit/Sources/WhiskyKit/Extensions/URL+Extensions.swift:

extension String {
    public var esc: String {
        let esc = ["\\", "\"", "'", " ", "(", ")", "[", "]", "{", "}", "&", "|",
                   ";", "<", ">", "`", "$", "!", "*", "?", "#", "~", "="]
        var str = self
        for char in esc {
            str = str.replacingOccurrences(of: char, with: "\\" + char)
        }
        return str
    }
}