mirror of https://github.com/Wox-launcher/Wox
refactor(app): improve unicode handling for shortcut app path on windows. #4236
* Replaced the previous shortcut resolution method with a PowerShell-based approach for better Unicode support. * Improved error handling for shortcut resolution. * Cleaned up unused import statements.
This commit is contained in:
parent
4750fc92ce
commit
fe183f5bf6
|
@ -27,7 +27,7 @@ require (
|
||||||
github.com/olahol/melody v1.2.1
|
github.com/olahol/melody v1.2.1
|
||||||
github.com/openai/openai-go v0.1.0-beta.6
|
github.com/openai/openai-go v0.1.0-beta.6
|
||||||
github.com/otiai10/copy v1.14.0
|
github.com/otiai10/copy v1.14.0
|
||||||
github.com/parsiya/golnk v0.0.0-20221103095132-740a4c27c4ff
|
|
||||||
github.com/petermattis/goid v0.0.0-20241025130422-66cb2e6d7274
|
github.com/petermattis/goid v0.0.0-20241025130422-66cb2e6d7274
|
||||||
github.com/robotn/gohook v0.41.0
|
github.com/robotn/gohook v0.41.0
|
||||||
github.com/rs/cors v1.11.1
|
github.com/rs/cors v1.11.1
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"wox/util/shell"
|
"wox/util/shell"
|
||||||
|
|
||||||
win "github.com/lxn/win"
|
win "github.com/lxn/win"
|
||||||
lnk "github.com/parsiya/golnk"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -94,20 +93,16 @@ func (a *WindowsRetriever) ParseAppInfo(ctx context.Context, path string) (appIn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *WindowsRetriever) parseShortcut(ctx context.Context, appPath string) (appInfo, error) {
|
func (a *WindowsRetriever) parseShortcut(ctx context.Context, appPath string) (appInfo, error) {
|
||||||
f, lnkErr := lnk.File(appPath)
|
// Use PowerShell + COM to resolve shortcut with proper Unicode support
|
||||||
if lnkErr != nil {
|
targetPath, resolveErr := a.resolveShortcutWithAPI(ctx, appPath)
|
||||||
return appInfo{}, lnkErr
|
if resolveErr != nil {
|
||||||
|
return appInfo{}, fmt.Errorf("failed to resolve shortcut %s: %v", appPath, resolveErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
var targetPath = ""
|
a.api.Log(ctx, plugin.LogLevelInfo, fmt.Sprintf("Resolved shortcut %s -> %s", appPath, targetPath))
|
||||||
if f.LinkInfo.LocalBasePath != "" {
|
|
||||||
targetPath = f.LinkInfo.LocalBasePath
|
|
||||||
}
|
|
||||||
if f.LinkInfo.LocalBasePathUnicode != "" {
|
|
||||||
targetPath = f.LinkInfo.LocalBasePathUnicode
|
|
||||||
}
|
|
||||||
if targetPath == "" || !strings.HasSuffix(targetPath, ".exe") {
|
if targetPath == "" || !strings.HasSuffix(targetPath, ".exe") {
|
||||||
return appInfo{}, errors.New("no target path found")
|
return appInfo{}, errors.New("no target path found or not an exe file")
|
||||||
}
|
}
|
||||||
|
|
||||||
// use default icon if no icon is found
|
// use default icon if no icon is found
|
||||||
|
@ -226,6 +221,29 @@ func (a *WindowsRetriever) GetAppIcon(ctx context.Context, path string) (image.I
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolveShortcutWithAPI uses Windows API to resolve shortcut target path with proper Unicode support
|
||||||
|
func (a *WindowsRetriever) resolveShortcutWithAPI(ctx context.Context, shortcutPath string) (string, error) {
|
||||||
|
// Use PowerShell to resolve the shortcut with proper Unicode handling
|
||||||
|
powershellCmd := fmt.Sprintf(`
|
||||||
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
|
$shell = New-Object -ComObject WScript.Shell
|
||||||
|
$shortcut = $shell.CreateShortcut('%s')
|
||||||
|
Write-Output $shortcut.TargetPath
|
||||||
|
`, shortcutPath)
|
||||||
|
|
||||||
|
output, err := shell.RunOutput("powershell", "-Command", powershellCmd)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to resolve shortcut: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
targetPath := strings.TrimSpace(string(output))
|
||||||
|
if targetPath == "" {
|
||||||
|
return "", fmt.Errorf("empty target path")
|
||||||
|
}
|
||||||
|
|
||||||
|
return targetPath, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *WindowsRetriever) GetExtraApps(ctx context.Context) ([]appInfo, error) {
|
func (a *WindowsRetriever) GetExtraApps(ctx context.Context) ([]appInfo, error) {
|
||||||
uwpApps := a.GetUWPApps(ctx)
|
uwpApps := a.GetUWPApps(ctx)
|
||||||
util.GetLogger().Info(ctx, fmt.Sprintf("Found %d UWP apps", len(uwpApps)))
|
util.GetLogger().Info(ctx, fmt.Sprintf("Found %d UWP apps", len(uwpApps)))
|
||||||
|
|
Loading…
Reference in New Issue