Skip to content

Commit

Permalink
Reliable way to add to the Dock programmatically
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstrba committed Apr 15, 2024
1 parent c6c9e29 commit 8f5b0da
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions DuckDuckGo/Onboarding/ViewModel/OnboardingViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ final class OnboardingViewModel: ObservableObject {
}
return false
}) {
let appDict = recentApps[recentAppIndex]
// Move from recent to persistent
let appDict = recentApps.remove(at: recentAppIndex)
persistentApps.append(appDict)
} else {
// Create the dictionary for the current application if not found in recent apps
Expand All @@ -163,14 +163,23 @@ final class OnboardingViewModel: ObservableObject {
// Update the plist
dockPlistDict["persistent-apps"] = persistentApps as AnyObject?
dockPlistDict["recent-apps"] = recentApps as AnyObject?

// Mofidy the mod-count
if let modCount = dockPlistDict["mod-count"] as? Int {
dockPlistDict["mod-count"] = (modCount + 1) as AnyObject?
} else {
assertionFailure("mod-count modification failed")
}

// Write
do {
try (dockPlistDict as NSDictionary).write(to: dockPlistURL)
} catch {
return
}

// Restart the Dock to apply changes
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { [weak self] in
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
self?.restartDock()
}
}
Expand Down

0 comments on commit 8f5b0da

Please sign in to comment.