Add scaffoling for updating the various settings.

This commit is contained in:
Iheanyi Ekechukwu
2024-11-23 15:05:39 -06:00
parent af20b565f6
commit fbe7235e47
2 changed files with 39 additions and 3 deletions

View File

@ -665,8 +665,44 @@ class AppDelegate: NSObject,
setSecureInput(.toggle)
}
@IBAction func makeDefaultTerminal(_ sender: Any) {
@IBAction func makeGhosttyDefaultTerminal(_ sender: Any) {
Ghostty.logger.debug("Clicked makeDefaultTerminal")
let ghosttyBundleID = Bundle.main.bundleIdentifier!
setDefaultTerminal(bundleID: ghosttyBundleID)
}
@IBAction func makeTerminalDefaultTerminal(_ sender: Any) {
Ghostty.logger.debug("Clicked makeTerminalDefaultTerminal")
let terminalBundleID = "com.apple.terminal"
setDefaultTerminal(bundleID: terminalBundleID)
}
func isGhosttyDefault() -> Bool {
return isDefaultTerminal(bundleID: Bundle.main.bundleIdentifier!)
}
func isTerminalDefault() -> Bool {
return isDefaultTerminal(bundleID: "com.apple.terminal")
}
func isDefaultTerminal(bundleID: String) -> Bool {
return bundleID.isEqual(defaultTerminal())
// return CFStringCompare(bundleID as CFString, unixHandler?.takeRetainedValue(), CFStringCompareFlags.compareBackwards) == CFComparisonResult.compareEqualTo
}
func defaultTerminal() -> String {
let unixExecutableContentType: CFString = "public.unix-executable" as CFString
let unixHandler = LSCopyDefaultRoleHandlerForContentType(unixExecutableContentType, LSRolesMask.shell)
let current = unixHandler?.takeRetainedValue() as? String ?? ""
return current
}
func setDefaultTerminal(bundleID: String) {
Ghostty.logger.debug("Setting default terminal to \(bundleID)")
Ghostty.logger.debug("Is Ghostty default? \(self.isGhosttyDefault())")
Ghostty.logger.debug("Is Terminal default? \(self.isTerminalDefault())")
Ghostty.logger.debug("Debugging default terminal: \(self.defaultTerminal())")
}
@IBAction func toggleQuickTerminal(_ sender: Any) {

View File

@ -86,10 +86,10 @@
<action selector="toggleSecureInput:" target="bbz-4X-AYv" id="vWx-z8-5Sy"/>
</connections>
</menuItem>
<menuItem title="Make Default Terminal" id="gFP-FT-8g6">
<menuItem title="Make Ghostty Default Terminal" id="gFP-FT-8g6">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="makeDefaultTerminal:" target="bbz-4X-AYv" id="CaP-G2-Cph"/>
<action selector="makeGhosttyDefaultTerminal:" target="bbz-4X-AYv" id="o1U-Dx-VR6"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="4je-JR-u6R"/>