-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Simplify the icon loading - Use paths instead of a model to load icons from disk - Add `PathFinderController` to make sure that we have all the correct application paths inside the application commands
- Loading branch information
Showing
14 changed files
with
73 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
LogicFramework/Sources/Applications/PathFinderController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Foundation | ||
import ModelKit | ||
|
||
/// Make sure that all current path reference are correct for the persisted groups | ||
public class PathFinderController { | ||
public init() {} | ||
|
||
public func patch(_ groups: [Group], applications: [Application]) -> [Group] { | ||
var appDictionary = [String: Application]() | ||
for app in applications { | ||
appDictionary[app.bundleIdentifier] = app | ||
} | ||
|
||
var groups = groups | ||
for (gOffset, group) in groups.enumerated() { | ||
for (wOffset, workflow) in group.workflows.enumerated() { | ||
for (cOffset, command) in workflow.commands.enumerated() { | ||
|
||
if case .application(let appCommand) = command, | ||
let application = appDictionary[appCommand.application.bundleIdentifier], | ||
application.path != appCommand.application.path { | ||
let newCommand = Command.application(.init( | ||
id: appCommand.id, | ||
name: appCommand.name, | ||
application: application | ||
)) | ||
|
||
groups[gOffset].workflows[wOffset].commands[cOffset] = newCommand | ||
} | ||
} | ||
} | ||
} | ||
|
||
return groups | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,16 @@ | ||
import ModelKit | ||
|
||
extension Command { | ||
var icon: Icon { | ||
let icon: Icon | ||
var icon: String { | ||
switch self { | ||
case .application(let applicationCommand): | ||
icon = Icon(identifier: applicationCommand.application.bundleIdentifier, | ||
path: applicationCommand.application.path) | ||
return applicationCommand.application.path | ||
case .script: | ||
icon = Icon(identifier: "com.apple.ScriptEditor2", | ||
path: "/System/Applications/Utilities/Script Editor.app") | ||
return "/System/Applications/Utilities/Script Editor.app" | ||
case .keyboard: | ||
icon = Icon(identifier: "com.apple.preference.keyboard", | ||
path: "/System/Library/PreferencePanes/Keyboard.prefPane") | ||
return "/System/Library/PreferencePanes/Keyboard.prefPane" | ||
case .open: | ||
icon = Icon(identifier: "com.apple.finder", | ||
path: "/System/Library/CoreServices/Finder.app") | ||
return "/System/Library/CoreServices/Finder.app" | ||
} | ||
|
||
return icon | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
import Cocoa | ||
import SwiftUI | ||
|
||
public protocol IconLoader: ObservableObject where ObjectWillChangePublisher.Output == Void { | ||
associatedtype State | ||
class IconLoader: ObservableObject { | ||
@Published public private(set) var image: Image? | ||
|
||
var icon: State { get } | ||
func load(_ path: String) { | ||
image = Image(nsImage: NSWorkspace.shared.icon(forFile: path)) | ||
} | ||
|
||
func cancel() { | ||
image = nil | ||
} | ||
|
||
deinit { | ||
cancel() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters