Skip to content

Commit

Permalink
Implement shortcuts on uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
Bios-Marcel committed Apr 16, 2024
1 parent 74ba0d4 commit b846997
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions pkg/scoop/scoop.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,29 @@ func (scoop *Scoop) Uninstall(app *InstalledApp, arch ArchitectureKey) error {
return fmt.Errorf("error removing shim: %w", err)
}

// FIXME Do rest of the uninstall here
// 1. Remove shortcuts
// FIXME Should we instead manually delete all .lnk files and then check for
// leftover empty directories? This could be relevant if there are some dirs
// that share a shortcut subdirectory.
if len(resolvedApp.Shortcuts) > 0 {
startmenuPath, err := scoop.ShortcutDir()
if err != nil {
return err
}

for _, shortcut := range resolvedApp.Shortcuts {
dir := filepath.Dir(shortcut.ShortcutName)
if dir == "." {
if err := os.Remove(filepath.Join(startmenuPath, shortcut.ShortcutName+".lnk")); err != nil {
return fmt.Errorf("error deleting shortcut: %w", err)
}
continue
}

if err := os.RemoveAll(filepath.Join(startmenuPath, dir)); err != nil {
return fmt.Errorf("error deleting shortcut dir: %w", err)
}
}
}

if err := scoop.runScript(resolvedApp.PostUninstall); err != nil {
return fmt.Errorf("error executing post_uninstall script: %w", err)
Expand Down Expand Up @@ -1100,11 +1121,10 @@ func (scoop *Scoop) install(iter *jsoniter.Iterator, appName string, arch Archit
}

if len(resolvedApp.Shortcuts) > 0 {
startmenuPath, err := windows.GetFolderPath("StartMenu")
startmenuPath, err := scoop.ShortcutDir()
if err != nil {
return fmt.Errorf("error determining start menu path: %w", err)
return err
}
startmenuPath = filepath.Join(startmenuPath, "Programs", "Scoop Apps")

var winShortcuts []windows.Shortcut
for _, shortcut := range resolvedApp.Shortcuts {
Expand Down Expand Up @@ -1699,6 +1719,14 @@ func (scoop *Scoop) AppDir() string {
return filepath.Join(scoop.scoopRoot, "apps")
}

func (scoop Scoop) ShortcutDir() (string, error) {
startmenuPath, err := windows.GetFolderPath("StartMenu")
if err != nil {
return "", fmt.Errorf("error determining start menu path: %w", err)
}
return filepath.Join(startmenuPath, "Programs", "Scoop Apps"), nil
}

func NewScoop() (*Scoop, error) {
dir, err := GetDefaultScoopDir()
if err != nil {
Expand Down

0 comments on commit b846997

Please sign in to comment.