fix: rewrote the preference window to fix crashes and jank (closes #502)
This commit is contained in:
1 parent
cf0504437b
commit
f9f5b8ae7e
41 files changed
+752
-2176
No files matched your search
@@ -6,6 +6,5 @@ target 'alt-tab-macos' do
|
||||
pod 'Sparkle', :podspec => 'https://raw.githubusercontent.com/lwouis/Sparkle/master/Sparkle.podspec'
|
||||
pod 'ShortcutRecorder', :git => 'https://github.com/Kentzo/ShortcutRecorder.git', :commit => 'f718220854575bad86fa89dd2bb3decd0b14b2b0'
|
||||
pod 'SwiftyMarkdown', '1.1.0'
|
||||
pod 'Preferences', '1.0.1'
|
||||
pod 'AppCenter/Crashes', '3.3.1'
|
||||
end
|
||||
+1
-5
@@ -3,7 +3,6 @@ PODS:
|
||||
- AppCenter/Crashes (3.3.1):
|
||||
- AppCenter/Core
|
||||
- LetsMove (1.24)
|
||||
- Preferences (1.0.1)
|
||||
- ShortcutRecorder (3.1)
|
||||
- Sparkle (1.23.1)
|
||||
- SwiftyMarkdown (1.1.0)
|
||||
@@ -11,7 +10,6 @@ PODS:
|
||||
DEPENDENCIES:
|
||||
- AppCenter/Crashes (= 3.3.1)
|
||||
- LetsMove (from `https://github.com/lwouis/LetsMove.git`, commit `7abf4daed1a25218f2b52f2dfd190aee5a50071c`)
|
||||
- Preferences (= 1.0.1)
|
||||
- ShortcutRecorder (from `https://github.com/Kentzo/ShortcutRecorder.git`, commit `f718220854575bad86fa89dd2bb3decd0b14b2b0`)
|
||||
- Sparkle (from `https://raw.githubusercontent.com/lwouis/Sparkle/master/Sparkle.podspec`)
|
||||
- SwiftyMarkdown (= 1.1.0)
|
||||
@@ -19,7 +17,6 @@ DEPENDENCIES:
|
||||
SPEC REPOS:
|
||||
trunk:
|
||||
- AppCenter
|
||||
- Preferences
|
||||
- SwiftyMarkdown
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
@@ -43,11 +40,10 @@ CHECKOUT OPTIONS:
|
||||
SPEC CHECKSUMS:
|
||||
AppCenter: 76ecf7e959a68e36b0fd314e8dc5897660214423
|
||||
LetsMove: fefe56bc7bc7fb7d37049e28a14f297961229fc5
|
||||
Preferences: a5afbe0ae3e6bd886328b1960f4998e65d58f2c4
|
||||
ShortcutRecorder: fdf620aca34101b0cba3b10fca815e0459254189
|
||||
Sparkle: ea073ba9c69cee3ebaab8685ba1e732e14d249f7
|
||||
SwiftyMarkdown: 033abc9dad9a37903f81aec5188cade436f40520
|
||||
|
||||
PODFILE CHECKSUM: 356279aa09d4eac74abe0d828422386fe7345766
|
||||
PODFILE CHECKSUM: 78df0a34910c4c031a65ac3b58dc004c21b552d0
|
||||
|
||||
COCOAPODS: 1.9.1
|
||||
Generated
+1
-5
@@ -3,7 +3,6 @@ PODS:
|
||||
- AppCenter/Crashes (3.3.1):
|
||||
- AppCenter/Core
|
||||
- LetsMove (1.24)
|
||||
- Preferences (1.0.1)
|
||||
- ShortcutRecorder (3.1)
|
||||
- Sparkle (1.23.1)
|
||||
- SwiftyMarkdown (1.1.0)
|
||||
@@ -11,7 +10,6 @@ PODS:
|
||||
DEPENDENCIES:
|
||||
- AppCenter/Crashes (= 3.3.1)
|
||||
- LetsMove (from `https://github.com/lwouis/LetsMove.git`, commit `7abf4daed1a25218f2b52f2dfd190aee5a50071c`)
|
||||
- Preferences (= 1.0.1)
|
||||
- ShortcutRecorder (from `https://github.com/Kentzo/ShortcutRecorder.git`, commit `f718220854575bad86fa89dd2bb3decd0b14b2b0`)
|
||||
- Sparkle (from `https://raw.githubusercontent.com/lwouis/Sparkle/master/Sparkle.podspec`)
|
||||
- SwiftyMarkdown (= 1.1.0)
|
||||
@@ -19,7 +17,6 @@ DEPENDENCIES:
|
||||
SPEC REPOS:
|
||||
trunk:
|
||||
- AppCenter
|
||||
- Preferences
|
||||
- SwiftyMarkdown
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
@@ -43,11 +40,10 @@ CHECKOUT OPTIONS:
|
||||
SPEC CHECKSUMS:
|
||||
AppCenter: 76ecf7e959a68e36b0fd314e8dc5897660214423
|
||||
LetsMove: fefe56bc7bc7fb7d37049e28a14f297961229fc5
|
||||
Preferences: a5afbe0ae3e6bd886328b1960f4998e65d58f2c4
|
||||
ShortcutRecorder: fdf620aca34101b0cba3b10fca815e0459254189
|
||||
Sparkle: ea073ba9c69cee3ebaab8685ba1e732e14d249f7
|
||||
SwiftyMarkdown: 033abc9dad9a37903f81aec5188cade436f40520
|
||||
|
||||
PODFILE CHECKSUM: 356279aa09d4eac74abe0d828422386fe7345766
|
||||
PODFILE CHECKSUM: 78df0a34910c4c031a65ac3b58dc004c21b552d0
|
||||
|
||||
COCOAPODS: 1.9.1
|
||||
Generated
+610
-828
File diff suppressed because it is too large.
Load diff
-134
@@ -1,134 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
struct Localization {
|
||||
enum Identifier {
|
||||
case preferences
|
||||
case preferencesEllipsized
|
||||
}
|
||||
|
||||
private static let localizedStrings: [Identifier: [String: String]] = [
|
||||
.preferences: [
|
||||
"ar": "تفضيلات",
|
||||
"ca": "Preferències",
|
||||
"cs": "Předvolby",
|
||||
"da": "Indstillinger",
|
||||
"de": "Einstellungen",
|
||||
"el": "Προτιμήσεις",
|
||||
"en": "Preferences",
|
||||
"en-AU": "Preferences",
|
||||
"en-GB": "Preferences",
|
||||
"es": "Preferencias",
|
||||
"es-419": "Preferencias",
|
||||
"fi": "Asetukset",
|
||||
"fr": "Préférences",
|
||||
"fr-CA": "Préférences",
|
||||
"he": "העדפות",
|
||||
"hi": "प्राथमिकता",
|
||||
"hr": "Postavke",
|
||||
"hu": "Beállítások",
|
||||
"id": "Preferensi",
|
||||
"it": "Preferenze",
|
||||
"ja": "環境設定",
|
||||
"ko": "환경설정",
|
||||
"ms": "Keutamaan",
|
||||
"nl": "Voorkeuren",
|
||||
"no": "Valg",
|
||||
"pl": "Preferencje",
|
||||
"pt": "Preferências",
|
||||
"pt-PT": "Preferências",
|
||||
"ro": "Preferințe",
|
||||
"ru": "Настройки",
|
||||
"sk": "Nastavenia",
|
||||
"sv": "Inställningar",
|
||||
"th": "การตั้งค่า",
|
||||
"tr": "Tercihler",
|
||||
"uk": "Параметри",
|
||||
"vi": "Tùy chọn",
|
||||
"zh-CN": "偏好设置",
|
||||
"zh-HK": "偏好設定",
|
||||
"zh-TW": "偏好設定"
|
||||
],
|
||||
.preferencesEllipsized: [
|
||||
"ar": "تفضيلات…",
|
||||
"ca": "Preferències…",
|
||||
"cs": "Předvolby…",
|
||||
"da": "Indstillinger…",
|
||||
"de": "Einstellungen…",
|
||||
"el": "Προτιμήσεις…",
|
||||
"en": "Preferences…",
|
||||
"en-AU": "Preferences…",
|
||||
"en-GB": "Preferences…",
|
||||
"es": "Preferencias…",
|
||||
"es-419": "Preferencias…",
|
||||
"fi": "Asetukset…",
|
||||
"fr": "Préférences…",
|
||||
"fr-CA": "Préférences…",
|
||||
"he": "העדפות…",
|
||||
"hi": "प्राथमिकता…",
|
||||
"hr": "Postavke…",
|
||||
"hu": "Beállítások…",
|
||||
"id": "Preferensi…",
|
||||
"it": "Preferenze…",
|
||||
"ja": "環境設定…",
|
||||
"ko": "환경설정...",
|
||||
"ms": "Keutamaan…",
|
||||
"nl": "Voorkeuren…",
|
||||
"no": "Valg…",
|
||||
"pl": "Preferencje…",
|
||||
"pt": "Preferências…",
|
||||
"pt-PT": "Preferências…",
|
||||
"ro": "Preferințe…",
|
||||
"ru": "Настройки…",
|
||||
"sk": "Nastavenia…",
|
||||
"sv": "Inställningar…",
|
||||
"th": "การตั้งค่า…",
|
||||
"tr": "Tercihler…",
|
||||
"uk": "Параметри…",
|
||||
"vi": "Tùy chọn…",
|
||||
"zh-CN": "偏好设置…",
|
||||
"zh-HK": "偏好設定⋯",
|
||||
"zh-TW": "偏好設定⋯"
|
||||
]
|
||||
]
|
||||
|
||||
/**
|
||||
Returns the localized version of the given string.
|
||||
|
||||
- Parameter identifier: Identifier of the string to localize.
|
||||
|
||||
- Note: If the system's locale can't be determined, the English localization of the string will be returned.
|
||||
*/
|
||||
static subscript(identifier: Identifier) -> String {
|
||||
// Force-unwrapped since all of the involved code is under our control.
|
||||
let localizedDict = Localization.localizedStrings[identifier]!
|
||||
let defaultLocalizedString = localizedDict["en"]!
|
||||
|
||||
// Iterate through all user-preferred languages until we find one that has a valid language code.
|
||||
let preferredLocale = Locale.preferredLanguages
|
||||
.lazy
|
||||
.map { Locale(identifier: $0) }
|
||||
.first { $0.languageCode != nil }
|
||||
?? Locale.current
|
||||
|
||||
guard let languageCode = preferredLocale.languageCode else {
|
||||
return defaultLocalizedString
|
||||
}
|
||||
|
||||
// Chinese is the only language where different region codes result in different translations.
|
||||
if languageCode == "zh" {
|
||||
let regionCode = preferredLocale.regionCode ?? ""
|
||||
if regionCode == "HK" || regionCode == "TW" {
|
||||
return localizedDict["\(languageCode)-\(regionCode)"]!
|
||||
} else {
|
||||
// Fall back to "regular" zh-CN if neither the HK or TW region codes are found.
|
||||
return localizedDict["\(languageCode)-CN"]!
|
||||
}
|
||||
} else {
|
||||
if let localizedString = localizedDict[languageCode] {
|
||||
return localizedString
|
||||
}
|
||||
}
|
||||
|
||||
return defaultLocalizedString
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
import Cocoa
|
||||
|
||||
public struct PreferencePaneIdentifier: Hashable, RawRepresentable, Codable {
|
||||
public typealias Identifier = PreferencePaneIdentifier
|
||||
|
||||
public let rawValue: String
|
||||
|
||||
public init(rawValue: String) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
}
|
||||
|
||||
public protocol PreferencePane: NSViewController {
|
||||
typealias Identifier = PreferencePaneIdentifier
|
||||
|
||||
var preferencePaneIdentifier: Identifier { get }
|
||||
var preferencePaneTitle: String { get }
|
||||
var toolbarItemIcon: NSImage { get }
|
||||
}
|
||||
|
||||
extension PreferencePane {
|
||||
public var toolbarItemIdentifier: NSToolbarItem.Identifier {
|
||||
preferencePaneIdentifier.toolbarItemIdentifier
|
||||
}
|
||||
|
||||
public var toolbarItemIcon: NSImage { .empty }
|
||||
}
|
||||
|
||||
extension PreferencePane.Identifier {
|
||||
public init(_ rawValue: String) {
|
||||
self.init(rawValue: rawValue)
|
||||
}
|
||||
|
||||
public init(fromToolbarItemIdentifier itemIdentifier: NSToolbarItem.Identifier) {
|
||||
self.init(rawValue: itemIdentifier.rawValue)
|
||||
}
|
||||
|
||||
public var toolbarItemIdentifier: NSToolbarItem.Identifier {
|
||||
NSToolbarItem.Identifier(rawValue)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import Cocoa
|
||||
|
||||
public enum PreferencesStyle {
|
||||
case toolbarItems
|
||||
case segmentedControl
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import Cocoa
|
||||
|
||||
protocol PreferencesStyleController: AnyObject {
|
||||
var delegate: PreferencesStyleControllerDelegate? { get set }
|
||||
var isKeepingWindowCentered: Bool { get }
|
||||
|
||||
func toolbarItemIdentifiers() -> [NSToolbarItem.Identifier]
|
||||
func toolbarItem(preferenceIdentifier: PreferencePane.Identifier) -> NSToolbarItem?
|
||||
func selectTab(index: Int)
|
||||
}
|
||||
|
||||
protocol PreferencesStyleControllerDelegate: AnyObject {
|
||||
func activateTab(preferenceIdentifier: PreferencePane.Identifier, animated: Bool)
|
||||
func activateTab(index: Int, animated: Bool)
|
||||
}
|
||||
@@ -1,224 +0,0 @@
|
||||
import Cocoa
|
||||
|
||||
final class PreferencesTabViewController: NSViewController, PreferencesStyleControllerDelegate {
|
||||
private var activeTab: Int?
|
||||
private var preferencePanes = [PreferencePane]()
|
||||
internal var preferencePanesCount: Int { preferencePanes.count }
|
||||
private var preferencesStyleController: PreferencesStyleController!
|
||||
private var isKeepingWindowCentered: Bool { preferencesStyleController.isKeepingWindowCentered }
|
||||
|
||||
private var toolbarItemIdentifiers: [NSToolbarItem.Identifier] {
|
||||
preferencesStyleController?.toolbarItemIdentifiers() ?? []
|
||||
}
|
||||
|
||||
var window: NSWindow! { view.window }
|
||||
|
||||
var isAnimated: Bool = true
|
||||
|
||||
override func loadView() {
|
||||
self.view = NSView()
|
||||
self.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
|
||||
func configure(preferencePanes: [PreferencePane], style: PreferencesStyle) {
|
||||
self.preferencePanes = preferencePanes
|
||||
self.children = preferencePanes
|
||||
|
||||
let toolbar = NSToolbar(identifier: "PreferencesToolbar")
|
||||
toolbar.allowsUserCustomization = false
|
||||
toolbar.displayMode = .iconAndLabel
|
||||
toolbar.showsBaselineSeparator = true
|
||||
toolbar.delegate = self
|
||||
|
||||
switch style {
|
||||
case .segmentedControl:
|
||||
preferencesStyleController = SegmentedControlStyleViewController(preferencePanes: preferencePanes)
|
||||
case .toolbarItems:
|
||||
preferencesStyleController = ToolbarItemStyleViewController(
|
||||
preferencePanes: preferencePanes,
|
||||
toolbar: toolbar,
|
||||
centerToolbarItems: false
|
||||
)
|
||||
}
|
||||
preferencesStyleController.delegate = self
|
||||
|
||||
// Called last so that `preferencesStyleController` can be asked for items.
|
||||
window.toolbar = toolbar
|
||||
}
|
||||
|
||||
func activateTab(preferencePane: PreferencePane, animated: Bool) {
|
||||
activateTab(preferenceIdentifier: preferencePane.preferencePaneIdentifier, animated: animated)
|
||||
}
|
||||
|
||||
func activateTab(preferenceIdentifier: PreferencePane.Identifier, animated: Bool) {
|
||||
guard let index = (preferencePanes.firstIndex { $0.preferencePaneIdentifier == preferenceIdentifier }) else {
|
||||
return activateTab(index: 0, animated: animated)
|
||||
}
|
||||
|
||||
activateTab(index: index, animated: animated)
|
||||
}
|
||||
|
||||
func activateTab(index: Int, animated: Bool) {
|
||||
defer {
|
||||
activeTab = index
|
||||
preferencesStyleController.selectTab(index: index)
|
||||
updateWindowTitle(tabIndex: index)
|
||||
}
|
||||
|
||||
if activeTab == nil {
|
||||
immediatelyDisplayTab(index: index)
|
||||
} else {
|
||||
guard index != activeTab else {
|
||||
return
|
||||
}
|
||||
|
||||
animateTabTransition(index: index, animated: animated)
|
||||
}
|
||||
}
|
||||
|
||||
func restoreInitialTab() {
|
||||
if activeTab == nil {
|
||||
activateTab(index: 0, animated: false)
|
||||
}
|
||||
}
|
||||
|
||||
private func updateWindowTitle(tabIndex: Int) {
|
||||
self.window.title = {
|
||||
if preferencePanes.count > 1 {
|
||||
return preferencePanes[tabIndex].preferencePaneTitle
|
||||
} else {
|
||||
let preferences = Localization[.preferences]
|
||||
let appName = Bundle.main.appName
|
||||
return "\(appName) \(preferences)"
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
/// Cached constraints that pin `childViewController` views to the content view.
|
||||
private var activeChildViewConstraints = [NSLayoutConstraint]()
|
||||
|
||||
private func immediatelyDisplayTab(index: Int) {
|
||||
let toViewController = preferencePanes[index]
|
||||
view.addSubview(toViewController.view)
|
||||
activeChildViewConstraints = toViewController.view.constrainToSuperviewBounds()
|
||||
setWindowFrame(for: toViewController, animated: false)
|
||||
}
|
||||
|
||||
private func animateTabTransition(index: Int, animated: Bool) {
|
||||
guard let activeTab = activeTab else {
|
||||
assertionFailure("animateTabTransition called before a tab was displayed; transition only works from one tab to another")
|
||||
immediatelyDisplayTab(index: index)
|
||||
return
|
||||
}
|
||||
|
||||
let fromViewController = preferencePanes[activeTab]
|
||||
let toViewController = preferencePanes[index]
|
||||
|
||||
// View controller animations only work on macOS 10.14 and newer.
|
||||
let options: NSViewController.TransitionOptions
|
||||
if #available(macOS 10.14, *) {
|
||||
options = animated && isAnimated ? [.crossfade] : []
|
||||
} else {
|
||||
options = []
|
||||
}
|
||||
|
||||
view.removeConstraints(activeChildViewConstraints)
|
||||
|
||||
transition(
|
||||
from: fromViewController,
|
||||
to: toViewController,
|
||||
options: options
|
||||
) {
|
||||
self.activeChildViewConstraints = toViewController.view.constrainToSuperviewBounds()
|
||||
}
|
||||
}
|
||||
|
||||
override func transition(
|
||||
from fromViewController: NSViewController,
|
||||
to toViewController: NSViewController,
|
||||
options: NSViewController.TransitionOptions = [],
|
||||
completionHandler completion: (() -> Void)? = nil
|
||||
) {
|
||||
let isAnimated = options
|
||||
.intersection([
|
||||
.crossfade,
|
||||
.slideUp,
|
||||
.slideDown,
|
||||
.slideForward,
|
||||
.slideBackward,
|
||||
.slideLeft,
|
||||
.slideRight
|
||||
])
|
||||
.isEmpty == false
|
||||
|
||||
if isAnimated {
|
||||
NSAnimationContext.runAnimationGroup({ context in
|
||||
context.allowsImplicitAnimation = true
|
||||
context.duration = 0.25
|
||||
context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
|
||||
setWindowFrame(for: toViewController, animated: true)
|
||||
|
||||
super.transition(
|
||||
from: fromViewController,
|
||||
to: toViewController,
|
||||
options: options,
|
||||
completionHandler: completion
|
||||
)
|
||||
}, completionHandler: nil)
|
||||
} else {
|
||||
super.transition(
|
||||
from: fromViewController,
|
||||
to: toViewController,
|
||||
options: options,
|
||||
completionHandler: completion
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private func setWindowFrame(for viewController: NSViewController, animated: Bool = false) {
|
||||
guard let window = window else {
|
||||
preconditionFailure()
|
||||
}
|
||||
|
||||
let contentSize = viewController.view.fittingSize
|
||||
|
||||
let newWindowSize = window.frameRect(forContentRect: CGRect(origin: .zero, size: contentSize)).size
|
||||
var frame = window.frame
|
||||
frame.origin.y += frame.height - newWindowSize.height
|
||||
frame.size = newWindowSize
|
||||
|
||||
if isKeepingWindowCentered {
|
||||
let horizontalDiff = (window.frame.width - newWindowSize.width) / 2
|
||||
frame.origin.x += horizontalDiff
|
||||
}
|
||||
|
||||
let animatableWindow = animated ? window.animator() : window
|
||||
animatableWindow.setFrame(frame, display: false)
|
||||
}
|
||||
}
|
||||
|
||||
extension PreferencesTabViewController: NSToolbarDelegate {
|
||||
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||
toolbarItemIdentifiers
|
||||
}
|
||||
|
||||
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||
toolbarItemIdentifiers
|
||||
}
|
||||
|
||||
func toolbarSelectableItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||
toolbarItemIdentifiers
|
||||
}
|
||||
|
||||
public func toolbar(
|
||||
_ toolbar: NSToolbar,
|
||||
itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier,
|
||||
willBeInsertedIntoToolbar flag: Bool
|
||||
) -> NSToolbarItem? {
|
||||
if itemIdentifier == .flexibleSpace {
|
||||
return nil
|
||||
}
|
||||
|
||||
return preferencesStyleController.toolbarItem(preferenceIdentifier: .Identifier(fromToolbarItemIdentifier: itemIdentifier))
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
import Cocoa
|
||||
|
||||
extension NSWindow.FrameAutosaveName {
|
||||
static let preferences: NSWindow.FrameAutosaveName = "com.sindresorhus.Preferences.FrameAutosaveName"
|
||||
}
|
||||
|
||||
public final class PreferencesWindowController: NSWindowController {
|
||||
private let tabViewController = PreferencesTabViewController()
|
||||
|
||||
public var isAnimated: Bool {
|
||||
get { tabViewController.isAnimated }
|
||||
set {
|
||||
tabViewController.isAnimated = newValue
|
||||
}
|
||||
}
|
||||
|
||||
public var hidesToolbarForSingleItem: Bool {
|
||||
didSet {
|
||||
updateToolbarVisibility()
|
||||
}
|
||||
}
|
||||
|
||||
private func updateToolbarVisibility() {
|
||||
window?.toolbar?.isVisible = (hidesToolbarForSingleItem == false)
|
||||
|| (tabViewController.preferencePanesCount > 1)
|
||||
}
|
||||
|
||||
public init(
|
||||
preferencePanes: [PreferencePane],
|
||||
style: PreferencesStyle = .toolbarItems,
|
||||
animated: Bool = true,
|
||||
hidesToolbarForSingleItem: Bool = true
|
||||
) {
|
||||
precondition(!preferencePanes.isEmpty, "You need to set at least one view controller")
|
||||
|
||||
let window = UserInteractionPausableWindow(
|
||||
contentRect: preferencePanes[0].view.bounds,
|
||||
styleMask: [
|
||||
.titled,
|
||||
.closable
|
||||
],
|
||||
backing: .buffered,
|
||||
defer: true
|
||||
)
|
||||
self.hidesToolbarForSingleItem = hidesToolbarForSingleItem
|
||||
super.init(window: window)
|
||||
|
||||
window.contentViewController = tabViewController
|
||||
|
||||
window.titleVisibility = {
|
||||
switch style {
|
||||
case .toolbarItems:
|
||||
return .visible
|
||||
case .segmentedControl:
|
||||
return preferencePanes.count <= 1 ? .visible : .hidden
|
||||
}
|
||||
}()
|
||||
|
||||
tabViewController.isAnimated = animated
|
||||
tabViewController.configure(preferencePanes: preferencePanes, style: style)
|
||||
updateToolbarVisibility()
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
override public init(window: NSWindow?) {
|
||||
fatalError("init(window:) is not supported, use init(preferences:style:animated:)")
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
public required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) is not supported, use init(preferences:style:animated:)")
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Show the preferences window and brings it to front.
|
||||
|
||||
If you pass a `PreferencePane.Identifier`, the window will activate the corresponding tab.
|
||||
|
||||
- Parameter preferencePane: Identifier of the preference pane to display, or `nil` to show the tab that was open when the user last closed the window.
|
||||
|
||||
- Note: Unless you need to open a specific pane, prefer not to pass a parameter at all or `nil`.
|
||||
|
||||
- See `close()` to close the window again.
|
||||
- See `showWindow(_:)` to show the window without the convenience of activating the app.
|
||||
*/
|
||||
public func show(preferencePane preferenceIdentifier: PreferencePane.Identifier? = nil) {
|
||||
if let preferenceIdentifier = preferenceIdentifier {
|
||||
tabViewController.activateTab(preferenceIdentifier: preferenceIdentifier, animated: false)
|
||||
} else {
|
||||
tabViewController.restoreInitialTab()
|
||||
}
|
||||
|
||||
showWindow(self)
|
||||
restoreWindowPosition()
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
}
|
||||
|
||||
private func restoreWindowPosition() {
|
||||
guard
|
||||
let window = self.window,
|
||||
let screenContainingWindow = window.screen
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
window.setFrameOrigin(CGPoint(
|
||||
x: screenContainingWindow.visibleFrame.midX - window.frame.width / 2,
|
||||
y: screenContainingWindow.visibleFrame.midY - window.frame.height / 2
|
||||
))
|
||||
window.setFrameUsingName(.preferences)
|
||||
window.setFrameAutosaveName(.preferences)
|
||||
}
|
||||
}
|
||||
-143
@@ -1,143 +0,0 @@
|
||||
import Cocoa
|
||||
|
||||
extension NSToolbarItem.Identifier {
|
||||
static var toolbarSegmentedControlItem: NSToolbarItem.Identifier {
|
||||
NSToolbarItem.Identifier("toolbarSegmentedControlItem")
|
||||
}
|
||||
}
|
||||
|
||||
extension NSUserInterfaceItemIdentifier {
|
||||
static var toolbarSegmentedControl: NSUserInterfaceItemIdentifier {
|
||||
NSUserInterfaceItemIdentifier("toolbarSegmentedControl")
|
||||
}
|
||||
}
|
||||
|
||||
final class SegmentedControlStyleViewController: NSViewController, PreferencesStyleController {
|
||||
var segmentedControl: NSSegmentedControl! {
|
||||
get { view as? NSSegmentedControl }
|
||||
set {
|
||||
view = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var isKeepingWindowCentered: Bool { true }
|
||||
|
||||
weak var delegate: PreferencesStyleControllerDelegate?
|
||||
|
||||
private var preferencePanes: [PreferencePane]!
|
||||
|
||||
required init(preferencePanes: [PreferencePane]) {
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
self.preferencePanes = preferencePanes
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func loadView() {
|
||||
view = createSegmentedControl(preferencePanes: preferencePanes)
|
||||
}
|
||||
|
||||
fileprivate func createSegmentedControl(preferencePanes: [PreferencePane]) -> NSSegmentedControl {
|
||||
let segmentedControl = NSSegmentedControl()
|
||||
segmentedControl.segmentCount = preferencePanes.count
|
||||
segmentedControl.segmentStyle = .texturedSquare
|
||||
segmentedControl.target = self
|
||||
segmentedControl.action = #selector(segmentedControlAction)
|
||||
segmentedControl.identifier = .toolbarSegmentedControl
|
||||
|
||||
if let cell = segmentedControl.cell as? NSSegmentedCell {
|
||||
cell.controlSize = .regular
|
||||
cell.trackingMode = .selectOne
|
||||
}
|
||||
|
||||
let segmentSize: CGSize = {
|
||||
let insets = CGSize(width: 36, height: 12)
|
||||
var maxSize = CGSize.zero
|
||||
|
||||
for preferencePane in preferencePanes {
|
||||
let title = preferencePane.preferencePaneTitle
|
||||
let titleSize = title.size(
|
||||
withAttributes: [
|
||||
.font: NSFont.systemFont(ofSize: NSFont.systemFontSize(for: .regular))
|
||||
]
|
||||
)
|
||||
|
||||
maxSize = CGSize(
|
||||
width: max(titleSize.width, maxSize.width),
|
||||
height: max(titleSize.height, maxSize.height)
|
||||
)
|
||||
}
|
||||
|
||||
return CGSize(
|
||||
width: maxSize.width + insets.width,
|
||||
height: maxSize.height + insets.height
|
||||
)
|
||||
}()
|
||||
|
||||
let segmentBorderWidth = CGFloat(preferencePanes.count) + 1
|
||||
let segmentWidth = segmentSize.width * CGFloat(preferencePanes.count) + segmentBorderWidth
|
||||
let segmentHeight = segmentSize.height
|
||||
segmentedControl.frame = CGRect(x: 0, y: 0, width: segmentWidth, height: segmentHeight)
|
||||
|
||||
for (index, preferencePane) in preferencePanes.enumerated() {
|
||||
segmentedControl.setLabel(preferencePane.preferencePaneTitle, forSegment: index)
|
||||
segmentedControl.setWidth(segmentSize.width, forSegment: index)
|
||||
if let cell = segmentedControl.cell as? NSSegmentedCell {
|
||||
cell.setTag(index, forSegment: index)
|
||||
}
|
||||
}
|
||||
|
||||
return segmentedControl
|
||||
}
|
||||
|
||||
@IBAction private func segmentedControlAction(_ control: NSSegmentedControl) {
|
||||
delegate?.activateTab(index: control.selectedSegment, animated: true)
|
||||
}
|
||||
|
||||
func selectTab(index: Int) {
|
||||
segmentedControl.selectedSegment = index
|
||||
}
|
||||
|
||||
func toolbarItemIdentifiers() -> [NSToolbarItem.Identifier] {
|
||||
[
|
||||
.flexibleSpace,
|
||||
.toolbarSegmentedControlItem,
|
||||
.flexibleSpace
|
||||
]
|
||||
}
|
||||
|
||||
func toolbarItem(preferenceIdentifier: PreferencePane.Identifier) -> NSToolbarItem? {
|
||||
let toolbarItemIdentifier = preferenceIdentifier.toolbarItemIdentifier
|
||||
precondition(toolbarItemIdentifier == .toolbarSegmentedControlItem)
|
||||
|
||||
// When the segments outgrow the window, we need to provide a group of
|
||||
// NSToolbarItems with custom menu item labels and action handling for the
|
||||
// context menu that pops up at the right edge of the window.
|
||||
let toolbarItemGroup = NSToolbarItemGroup(itemIdentifier: toolbarItemIdentifier)
|
||||
toolbarItemGroup.view = segmentedControl
|
||||
toolbarItemGroup.subitems = preferencePanes.enumerated().map { index, preferenceable -> NSToolbarItem in
|
||||
let item = NSToolbarItem(itemIdentifier: .init("segment-\(preferenceable.preferencePaneTitle)"))
|
||||
item.label = preferenceable.preferencePaneTitle
|
||||
|
||||
let menuItem = NSMenuItem(
|
||||
title: preferenceable.preferencePaneTitle,
|
||||
action: #selector(segmentedControlMenuAction),
|
||||
keyEquivalent: ""
|
||||
)
|
||||
menuItem.tag = index
|
||||
menuItem.target = self
|
||||
item.menuFormRepresentation = menuItem
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
return toolbarItemGroup
|
||||
}
|
||||
|
||||
@IBAction private func segmentedControlMenuAction(_ menuItem: NSMenuItem) {
|
||||
delegate?.activateTab(index: menuItem.tag, animated: true)
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
import Cocoa
|
||||
|
||||
final class ToolbarItemStyleViewController: NSObject, PreferencesStyleController {
|
||||
let toolbar: NSToolbar
|
||||
let centerToolbarItems: Bool
|
||||
let preferencePanes: [PreferencePane]
|
||||
var isKeepingWindowCentered: Bool { centerToolbarItems }
|
||||
weak var delegate: PreferencesStyleControllerDelegate?
|
||||
|
||||
init(preferencePanes: [PreferencePane], toolbar: NSToolbar, centerToolbarItems: Bool) {
|
||||
self.preferencePanes = preferencePanes
|
||||
self.toolbar = toolbar
|
||||
self.centerToolbarItems = centerToolbarItems
|
||||
}
|
||||
|
||||
func toolbarItemIdentifiers() -> [NSToolbarItem.Identifier] {
|
||||
var toolbarItemIdentifiers = [NSToolbarItem.Identifier]()
|
||||
|
||||
if centerToolbarItems {
|
||||
toolbarItemIdentifiers.append(.flexibleSpace)
|
||||
}
|
||||
|
||||
for preferencePane in preferencePanes {
|
||||
toolbarItemIdentifiers.append(preferencePane.toolbarItemIdentifier)
|
||||
}
|
||||
|
||||
if centerToolbarItems {
|
||||
toolbarItemIdentifiers.append(.flexibleSpace)
|
||||
}
|
||||
|
||||
return toolbarItemIdentifiers
|
||||
}
|
||||
|
||||
func toolbarItem(preferenceIdentifier: PreferencePane.Identifier) -> NSToolbarItem? {
|
||||
guard let preference = (preferencePanes.first { $0.preferencePaneIdentifier == preferenceIdentifier }) else {
|
||||
preconditionFailure()
|
||||
}
|
||||
|
||||
let toolbarItem = NSToolbarItem(itemIdentifier: preferenceIdentifier.toolbarItemIdentifier)
|
||||
toolbarItem.label = preference.preferencePaneTitle
|
||||
toolbarItem.image = preference.toolbarItemIcon
|
||||
toolbarItem.target = self
|
||||
toolbarItem.action = #selector(toolbarItemSelected)
|
||||
return toolbarItem
|
||||
}
|
||||
|
||||
@IBAction private func toolbarItemSelected(_ toolbarItem: NSToolbarItem) {
|
||||
delegate?.activateTab(
|
||||
preferenceIdentifier: PreferencePane.Identifier(fromToolbarItemIdentifier: toolbarItem.itemIdentifier),
|
||||
animated: true
|
||||
)
|
||||
}
|
||||
|
||||
func selectTab(index: Int) {
|
||||
toolbar.selectedItemIdentifier = preferencePanes[index].toolbarItemIdentifier
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import Cocoa
|
||||
|
||||
/**
|
||||
A window that allows you to disable all user interactions via `isUserInteractionEnabled`.
|
||||
|
||||
Used to avoid breaking animations when the user clicks too fast. Disable user interactions during animations and you're set.
|
||||
*/
|
||||
class UserInteractionPausableWindow: NSWindow {
|
||||
var isUserInteractionEnabled = true
|
||||
|
||||
override func sendEvent(_ event: NSEvent) {
|
||||
guard isUserInteractionEnabled || !event.isUserInteraction else {
|
||||
return
|
||||
}
|
||||
|
||||
super.sendEvent(event)
|
||||
}
|
||||
|
||||
override func responds(to selector: Selector!) -> Bool {
|
||||
// Deactivate toolbar interactions from the Main Menu.
|
||||
if selector == #selector(NSWindow.toggleToolbarShown(_:)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return super.responds(to: selector)
|
||||
}
|
||||
}
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
import Cocoa
|
||||
|
||||
extension NSImage {
|
||||
static var empty: NSImage { NSImage(size: .zero) }
|
||||
}
|
||||
|
||||
extension NSView {
|
||||
@discardableResult
|
||||
func constrainToSuperviewBounds() -> [NSLayoutConstraint] {
|
||||
guard let superview = superview else {
|
||||
preconditionFailure("superview has to be set first")
|
||||
}
|
||||
|
||||
var result = [NSLayoutConstraint]()
|
||||
result.append(contentsOf: NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[subview]-0-|", options: .directionLeadingToTrailing, metrics: nil, views: ["subview": self]))
|
||||
result.append(contentsOf: NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[subview]-0-|", options: .directionLeadingToTrailing, metrics: nil, views: ["subview": self]))
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
superview.addConstraints(result)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
extension NSEvent {
|
||||
/// Events triggered by user interaction.
|
||||
static let userInteractionEvents: [NSEvent.EventType] = {
|
||||
var events: [NSEvent.EventType] = [
|
||||
.leftMouseDown,
|
||||
.leftMouseUp,
|
||||
.rightMouseDown,
|
||||
.rightMouseUp,
|
||||
.leftMouseDragged,
|
||||
.rightMouseDragged,
|
||||
.keyDown,
|
||||
.keyUp,
|
||||
.scrollWheel,
|
||||
.tabletPoint,
|
||||
.otherMouseDown,
|
||||
.otherMouseUp,
|
||||
.otherMouseDragged,
|
||||
.gesture,
|
||||
.magnify,
|
||||
.swipe,
|
||||
.rotate,
|
||||
.beginGesture,
|
||||
.endGesture,
|
||||
.smartMagnify,
|
||||
.quickLook,
|
||||
.directTouch
|
||||
]
|
||||
|
||||
if #available(macOS 10.10.3, *) {
|
||||
events.append(.pressure)
|
||||
}
|
||||
|
||||
return events
|
||||
}()
|
||||
|
||||
/// Whether the event was triggered by user interaction.
|
||||
var isUserInteraction: Bool { NSEvent.userInteractionEvents.contains(type) }
|
||||
}
|
||||
|
||||
extension Bundle {
|
||||
var appName: String {
|
||||
string(forInfoDictionaryKey: "CFBundleDisplayName")
|
||||
?? string(forInfoDictionaryKey: "CFBundleName")
|
||||
?? string(forInfoDictionaryKey: "CFBundleExecutable")
|
||||
?? "<Unknown App Name>"
|
||||
}
|
||||
|
||||
private func string(forInfoDictionaryKey key: String) -> String? {
|
||||
// `object(forInfoDictionaryKey:)` prefers localized info dictionary over the regular one automatically
|
||||
object(forInfoDictionaryKey: key) as? String
|
||||
}
|
||||
}
|
||||
Generated
-9
@@ -1,9 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
Generated
-251
@@ -1,251 +0,0 @@
|
||||
# Preferences
|
||||
|
||||
> Add a preferences window to your macOS app in minutes
|
||||
|
||||
<img src="screenshot.gif" width="628" height="416">
|
||||
|
||||
Just pass in some view controllers and this package will take care of the rest.
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
- macOS 10.10+
|
||||
- Xcode 11+
|
||||
- Swift 5.1+
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
#### SwiftPM
|
||||
|
||||
```swift
|
||||
.package(url: "https://github.com/sindresorhus/Preferences", from: "1.0.1")
|
||||
```
|
||||
|
||||
#### Carthage
|
||||
|
||||
```
|
||||
github "sindresorhus/Preferences"
|
||||
```
|
||||
|
||||
#### CocoaPods
|
||||
|
||||
```ruby
|
||||
pod 'Preferences'
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
*Run the `PreferencesExample` target in Xcode to try a live example.*
|
||||
|
||||
First, create some preference pane identifiers:
|
||||
|
||||
```swift
|
||||
import Preferences
|
||||
|
||||
extension PreferencePane.Identifier {
|
||||
static let general = Identifier("general")
|
||||
static let advanced = Identifier("advanced")
|
||||
}
|
||||
```
|
||||
|
||||
Second, create a couple of view controllers for the preference panes you want. The only difference from implementing a normal view controller is that you have to add the `PreferencePane` protocol and implement the `preferencePaneIdentifier`, `toolbarItemTitle`, and `toolbarItemIcon` properties, as shown below. You can leave out `toolbarItemIcon` if you're using the `.segmentedControl` style.
|
||||
|
||||
`GeneralPreferenceViewController.swift`
|
||||
|
||||
```swift
|
||||
import Cocoa
|
||||
import Preferences
|
||||
|
||||
final class GeneralPreferenceViewController: NSViewController, PreferencePane {
|
||||
let preferencePaneIdentifier = PreferencePane.Identifier.general
|
||||
let preferencePaneTitle = "General"
|
||||
let toolbarItemIcon = NSImage(named: NSImage.preferencesGeneralName)!
|
||||
|
||||
override var nibName: NSNib.Name? { "GeneralPreferenceViewController" }
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Setup stuff here
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`AdvancedPreferenceViewController.swift`
|
||||
|
||||
```swift
|
||||
import Cocoa
|
||||
import Preferences
|
||||
|
||||
final class AdvancedPreferenceViewController: NSViewController, PreferencePane {
|
||||
let preferencePaneIdentifier = PreferencePane.Identifier.advanced
|
||||
let preferencePaneTitle = "Advanced"
|
||||
let toolbarItemIcon = NSImage(named: NSImage.advancedName)!
|
||||
|
||||
override var nibName: NSNib.Name? { "AdvancedPreferenceViewController" }
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Setup stuff here
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In the `AppDelegate`, initialize a new `PreferencesWindowController` and pass it the view controllers. Then add an action outlet for the `Preferences…` menu item to show the preferences window.
|
||||
|
||||
`AppDelegate.swift`
|
||||
|
||||
```swift
|
||||
import Cocoa
|
||||
import Preferences
|
||||
|
||||
@NSApplicationMain
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
@IBOutlet private var window: NSWindow!
|
||||
|
||||
lazy var preferencesWindowController = PreferencesWindowController(
|
||||
preferencePanes: [
|
||||
GeneralPreferenceViewController(),
|
||||
AdvancedPreferenceViewController()
|
||||
]
|
||||
)
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {}
|
||||
|
||||
@IBAction
|
||||
func preferencesMenuItemActionHandler(_ sender: NSMenuItem) {
|
||||
preferencesWindowController.show()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Preferences Tab Styles
|
||||
|
||||
When you create the `PreferencesWindowController`, you can choose between the `NSToolbarItem`-based style (default) and the `NSSegmentedControl`:
|
||||
|
||||
```swift
|
||||
// …
|
||||
lazy var preferencesWindowController = PreferencesWindowController(
|
||||
preferencePanes: [
|
||||
GeneralPreferenceViewController(),
|
||||
AdvancedPreferenceViewController()
|
||||
],
|
||||
style: .segmentedControl
|
||||
)
|
||||
// …
|
||||
```
|
||||
|
||||
`.toolbarItem` style:
|
||||
|
||||

|
||||
|
||||
`.segmentedControl` style:
|
||||
|
||||

|
||||
|
||||
|
||||
## API
|
||||
|
||||
```swift
|
||||
public protocol PreferencePane: NSViewController {
|
||||
var preferencePaneIdentifier: PreferencePane.Identifier { get }
|
||||
var preferencePaneTitle: String { get }
|
||||
var toolbarItemIcon: NSImage { get } // Not required when using the .`segmentedControl` style
|
||||
}
|
||||
|
||||
public enum PreferencesStyle {
|
||||
case toolbarItems
|
||||
case segmentedControl
|
||||
}
|
||||
|
||||
public final class PreferencesWindowController: NSWindowController {
|
||||
init(
|
||||
preferencePanes: [PreferencePane],
|
||||
style: PreferencesStyle = .toolbarItems,
|
||||
animated: Bool = true,
|
||||
hidesToolbarForSingleItem: Bool = true
|
||||
)
|
||||
|
||||
func show(preferencePane: PreferencePane.Identifier? = nil)
|
||||
}
|
||||
```
|
||||
|
||||
As with any `NSWindowController`, call `NSWindowController#close()` to close the preferences window.
|
||||
|
||||
|
||||
## Recommendation
|
||||
|
||||
The easiest way to create the user interface within each pane is to use a [`NSGridView`](https://developer.apple.com/documentation/appkit/nsgridview) in Interface Builder. See the example project in this repo for a demo.
|
||||
|
||||
|
||||
## Known issues
|
||||
|
||||
### The preferences window doesn't show
|
||||
|
||||
This can happen when you are not using auto-layout or have not set a size for the view controller. You can fix this by either using auto-layout or setting an explicit size, for example, `preferredContentSize` in `viewDidLoad()`. [We intend to fix this.](https://github.com/sindresorhus/Preferences/pull/28)
|
||||
|
||||
### There are no animations on macOS 10.13 and earlier
|
||||
|
||||
The `animated` parameter of `PreferencesWindowController.init` has no effect on macOS 10.13 or earlier as those versions don't support `NSViewController.TransitionOptions.crossfade`.
|
||||
|
||||
|
||||
## FAQ
|
||||
|
||||
### How can I localize the window title?
|
||||
|
||||
The `PreferencesWindowController` adheres to the [macOS Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/macos/app-architecture/preferences/) and uses this set of rules to determine the window title:
|
||||
|
||||
- **Multiple preference panes:** Uses the currently selected `preferencePaneTitle` as the window title. Localize your `preferencePaneTitle`s to get localized window titles.
|
||||
- **Single preference pane:** Sets the window title to `APPNAME Preferences`. The app name is obtained from your app's bundle. You can localize its `Info.plist` to customize the title. The `Preferences` part is taken from the "Preferences…" menu item, see #12. The order of lookup for the app name from your bundle:
|
||||
1. `CFBundleDisplayName`
|
||||
2. `CFBundleName`
|
||||
3. `CFBundleExecutable`
|
||||
4. Fall back to `"<Unknown App Name>"` to show you're missing some settings.
|
||||
|
||||
### Why should I use this instead of just manually implementing it myself?
|
||||
|
||||
It can't be that hard right? Well, turns out it is:
|
||||
|
||||
- The recommended way is to implement it using storyboards. [But storyboards...](https://gist.github.com/iraycd/01b45c5e1be7ef6957b7) And if you want the segmented control style, you have to implement it programmatically, [which is quite complex](https://github.com/sindresorhus/Preferences/blob/85f8d793050004fc0154c7f6a061412e00d13fa3/Sources/Preferences/SegmentedControlStyleViewController.swift).
|
||||
- [Even Apple gets it wrong, a lot.](https://twitter.com/sindresorhus/status/1113382212584464384)
|
||||
- You have to correctly handle [window](https://github.com/sindresorhus/Preferences/commit/cc25d58a9ec379812fc8f2fd7ba48f3d35b4cbff) and [tab restoration](https://github.com/sindresorhus/Preferences/commit/2bb3fc7418f3dc49b534fab986807c4e70ba78c3).
|
||||
- [The window title format depends on whether you have a single or multiple panes.](https://developer.apple.com/design/human-interface-guidelines/macos/app-architecture/preferences/)
|
||||
- It's difficult to get the transition animation right. A lot of apps have flaky animation between panes.
|
||||
- You end up having to deal with a lot of gnarly auto-layout complexities.
|
||||
|
||||
### How is it better than [`MASPreferences`](https://github.com/shpakovski/MASPreferences)?
|
||||
|
||||
- Written in Swift. *(No bridging header!)*
|
||||
- Swifty API using a protocol.
|
||||
- Supports segmented control style tabs.
|
||||
- Fully documented.
|
||||
- Adheres to the [macOS Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/macos/app-architecture/preferences/).
|
||||
- The window title is automatically localized by using the system string.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [Defaults](https://github.com/sindresorhus/Defaults) - Swifty and modern UserDefaults
|
||||
- [LaunchAtLogin](https://github.com/sindresorhus/LaunchAtLogin) - Add "Launch at Login" functionality to your macOS app
|
||||
- [DockProgress](https://github.com/sindresorhus/DockProgress) - Show progress in your app's Dock icon
|
||||
- [More…](https://github.com/search?q=user%3Asindresorhus+language%3Aswift)
|
||||
|
||||
You might also like Sindre's [apps](https://sindresorhus.com/apps).
|
||||
|
||||
|
||||
## Used in these apps
|
||||
|
||||
- [TableFlip](https://tableflipapp.com) - Visual Markdown table editor by [Christian Tietze](https://github.com/DivineDominion)
|
||||
- [The Archive](https://zettelkasten.de/the-archive/) - Note-taking app by [Christian Tietze](https://github.com/DivineDominion)
|
||||
- [Word Counter](https://wordcounterapp.com) - Measuring writer's productivity by [Christian Tietze](https://github.com/DivineDominion)
|
||||
|
||||
Want to tell the world about your app that is using Preferences? Open a PR!
|
||||
|
||||
|
||||
## Maintainers
|
||||
|
||||
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||
- [Christian Tietze](https://github.com/DivineDominion)
|
||||
-13
@@ -29,19 +29,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
## Preferences
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
## ShortcutRecorder
|
||||
|
||||
Creative Commons Attribution 4.0 International Public License
|
||||
|
||||
-19
@@ -46,25 +46,6 @@ THE SOFTWARE.</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
</string>
|
||||
<key>License</key>
|
||||
<string>MIT</string>
|
||||
<key>Title</key>
|
||||
<string>Preferences</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Creative Commons Attribution 4.0 International Public License
|
||||
|
||||
-2
@@ -198,7 +198,6 @@ fi
|
||||
|
||||
if [[ "$CONFIGURATION" == "Debug" ]]; then
|
||||
install_framework "${BUILT_PRODUCTS_DIR}/LetsMove/LetsMove.framework"
|
||||
install_framework "${BUILT_PRODUCTS_DIR}/Preferences/Preferences.framework"
|
||||
install_framework "${BUILT_PRODUCTS_DIR}/ShortcutRecorder/ShortcutRecorder.framework"
|
||||
install_framework "${PODS_ROOT}/Sparkle/Sparkle.framework"
|
||||
install_dsym "${PODS_ROOT}/Sparkle/Sparkle.framework.dSYM"
|
||||
@@ -206,7 +205,6 @@ if [[ "$CONFIGURATION" == "Debug" ]]; then
|
||||
fi
|
||||
if [[ "$CONFIGURATION" == "Release" ]]; then
|
||||
install_framework "${BUILT_PRODUCTS_DIR}/LetsMove/LetsMove.framework"
|
||||
install_framework "${BUILT_PRODUCTS_DIR}/Preferences/Preferences.framework"
|
||||
install_framework "${BUILT_PRODUCTS_DIR}/ShortcutRecorder/ShortcutRecorder.framework"
|
||||
install_framework "${PODS_ROOT}/Sparkle/Sparkle.framework"
|
||||
install_dsym "${PODS_ROOT}/Sparkle/Sparkle.framework.dSYM"
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
|
||||
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LetsMove" "${PODS_CONFIGURATION_BUILD_DIR}/Preferences" "${PODS_CONFIGURATION_BUILD_DIR}/ShortcutRecorder" "${PODS_CONFIGURATION_BUILD_DIR}/SwiftyMarkdown" "${PODS_ROOT}/AppCenter/AppCenter-SDK-Apple/macOS" "${PODS_ROOT}/Sparkle"
|
||||
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LetsMove" "${PODS_CONFIGURATION_BUILD_DIR}/ShortcutRecorder" "${PODS_CONFIGURATION_BUILD_DIR}/SwiftyMarkdown" "${PODS_ROOT}/AppCenter/AppCenter-SDK-Apple/macOS" "${PODS_ROOT}/Sparkle"
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LetsMove/LetsMove.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/Preferences/Preferences.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/ShortcutRecorder/ShortcutRecorder.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/SwiftyMarkdown/SwiftyMarkdown.framework/Headers"
|
||||
HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LetsMove/LetsMove.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/ShortcutRecorder/ShortcutRecorder.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/SwiftyMarkdown/SwiftyMarkdown.framework/Headers"
|
||||
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/../Frameworks' '@loader_path/Frameworks' @loader_path/../Frameworks
|
||||
OTHER_LDFLAGS = $(inherited) -ObjC -l"c++" -l"sqlite3" -l"z" -framework "AppCenter" -framework "AppCenterCrashes" -framework "AppKit" -framework "Carbon" -framework "Cocoa" -framework "Foundation" -framework "LetsMove" -framework "Preferences" -framework "ShortcutRecorder" -framework "Sparkle" -framework "SwiftyMarkdown" -framework "SystemConfiguration"
|
||||
OTHER_LDFLAGS = $(inherited) -ObjC -l"c++" -l"sqlite3" -l"z" -framework "AppCenter" -framework "AppCenterCrashes" -framework "AppKit" -framework "Carbon" -framework "Cocoa" -framework "Foundation" -framework "LetsMove" -framework "ShortcutRecorder" -framework "Sparkle" -framework "SwiftyMarkdown" -framework "SystemConfiguration"
|
||||
OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS
|
||||
PODS_BUILD_DIR = ${BUILD_DIR}
|
||||
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
|
||||
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LetsMove" "${PODS_CONFIGURATION_BUILD_DIR}/Preferences" "${PODS_CONFIGURATION_BUILD_DIR}/ShortcutRecorder" "${PODS_CONFIGURATION_BUILD_DIR}/SwiftyMarkdown" "${PODS_ROOT}/AppCenter/AppCenter-SDK-Apple/macOS" "${PODS_ROOT}/Sparkle"
|
||||
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LetsMove" "${PODS_CONFIGURATION_BUILD_DIR}/ShortcutRecorder" "${PODS_CONFIGURATION_BUILD_DIR}/SwiftyMarkdown" "${PODS_ROOT}/AppCenter/AppCenter-SDK-Apple/macOS" "${PODS_ROOT}/Sparkle"
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LetsMove/LetsMove.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/Preferences/Preferences.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/ShortcutRecorder/ShortcutRecorder.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/SwiftyMarkdown/SwiftyMarkdown.framework/Headers"
|
||||
HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LetsMove/LetsMove.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/ShortcutRecorder/ShortcutRecorder.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/SwiftyMarkdown/SwiftyMarkdown.framework/Headers"
|
||||
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/../Frameworks' '@loader_path/Frameworks' @loader_path/../Frameworks
|
||||
OTHER_LDFLAGS = $(inherited) -ObjC -l"c++" -l"sqlite3" -l"z" -framework "AppCenter" -framework "AppCenterCrashes" -framework "AppKit" -framework "Carbon" -framework "Cocoa" -framework "Foundation" -framework "LetsMove" -framework "Preferences" -framework "ShortcutRecorder" -framework "Sparkle" -framework "SwiftyMarkdown" -framework "SystemConfiguration"
|
||||
OTHER_LDFLAGS = $(inherited) -ObjC -l"c++" -l"sqlite3" -l"z" -framework "AppCenter" -framework "AppCenterCrashes" -framework "AppKit" -framework "Carbon" -framework "Cocoa" -framework "Foundation" -framework "LetsMove" -framework "ShortcutRecorder" -framework "Sparkle" -framework "SwiftyMarkdown" -framework "SystemConfiguration"
|
||||
OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS
|
||||
PODS_BUILD_DIR = ${BUILD_DIR}
|
||||
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.1</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,5 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
@interface PodsDummy_Preferences : NSObject
|
||||
@end
|
||||
@implementation PodsDummy_Preferences
|
||||
@end
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifdef __OBJC__
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#else
|
||||
#ifndef FOUNDATION_EXPORT
|
||||
#if defined(__cplusplus)
|
||||
#define FOUNDATION_EXPORT extern "C"
|
||||
#else
|
||||
#define FOUNDATION_EXPORT extern
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifdef __OBJC__
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#else
|
||||
#ifndef FOUNDATION_EXPORT
|
||||
#if defined(__cplusplus)
|
||||
#define FOUNDATION_EXPORT extern "C"
|
||||
#else
|
||||
#define FOUNDATION_EXPORT extern
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
FOUNDATION_EXPORT double PreferencesVersionNumber;
|
||||
FOUNDATION_EXPORT const unsigned char PreferencesVersionString[];
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
CODE_SIGN_IDENTITY =
|
||||
CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/Preferences
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS
|
||||
PODS_BUILD_DIR = ${BUILD_DIR}
|
||||
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
PODS_TARGET_SRCROOT = ${PODS_ROOT}/Preferences
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
|
||||
SKIP_INSTALL = YES
|
||||
USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
|
||||
@@ -1,6 +0,0 @@
|
||||
framework module Preferences {
|
||||
umbrella header "Preferences-umbrella.h"
|
||||
|
||||
export *
|
||||
module * { export * }
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
CODE_SIGN_IDENTITY =
|
||||
CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/Preferences
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS
|
||||
PODS_BUILD_DIR = ${BUILD_DIR}
|
||||
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
PODS_TARGET_SRCROOT = ${PODS_ROOT}/Preferences
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
|
||||
SKIP_INSTALL = YES
|
||||
USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
|
||||
@@ -105,6 +105,7 @@
|
||||
D04BAD451966B43720120D2E /* Menubar.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04BAD905546AA93E5117B0A /* Menubar.swift */; };
|
||||
D04BADA3F2DAB820D6FC6E75 /* AppCenterApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = D04BA48BC82D3060C3A1AB11 /* AppCenterApplication.m */; };
|
||||
D04BADCDA9F9A6C3D6499877 /* SystemPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04BA7C6F2519091717F4B4E /* SystemPermissions.swift */; };
|
||||
D04BADE4DDF7597749FB13BD /* PreferencesWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04BA099FA155FB4D517D66B /* PreferencesWindow.swift */; };
|
||||
D04BAE8B16A06A10E2FA94DE /* AccessibilityEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04BA8FDCF137D892114F5F3 /* AccessibilityEvents.swift */; };
|
||||
D04BAEE31B6FFCDC779E6C17 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = D04BAC2FF99F629CD4ED20FC /* MainMenu.xib */; };
|
||||
D04BAF12DF5D15B9D7D316A4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D04BA61693F710CD7BD054D7 /* InfoPlist.strings */; };
|
||||
@@ -127,6 +128,7 @@
|
||||
D04BA075E359F36C27CD5BAE /* package-lock.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "package-lock.json"; sourceTree = "<group>"; };
|
||||
D04BA084F638725465234830 /* favicon-16x16.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "favicon-16x16.png"; sourceTree = "<group>"; };
|
||||
D04BA088B8A550D9367A4AAB /* it */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = it; path = InfoPlist.strings; sourceTree = "<group>"; };
|
||||
D04BA099FA155FB4D517D66B /* PreferencesWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferencesWindow.swift; sourceTree = "<group>"; };
|
||||
D04BA0AAAE82C72855DBBA26 /* update_appcast.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = update_appcast.sh; sourceTree = "<group>"; };
|
||||
D04BA0CDCFF1F0B1A77E3E86 /* SF-Pro-Text-Regular-Full.otf */ = {isa = PBXFileReference; lastKnownFileType = file.otf; path = "SF-Pro-Text-Regular-Full.otf"; sourceTree = "<group>"; };
|
||||
D04BA0CE87BE264C52987ED1 /* 7 windows - 2 lines - wide window.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "7 windows - 2 lines - wide window.jpg"; sourceTree = "<group>"; };
|
||||
@@ -860,6 +862,7 @@
|
||||
children = (
|
||||
D04BA2526DC6726E0F7ACF7C /* LabelAndControl.swift */,
|
||||
D04BA3FA52AA40B827A72F10 /* tabs */,
|
||||
D04BA099FA155FB4D517D66B /* PreferencesWindow.swift */,
|
||||
);
|
||||
path = "preferences-window";
|
||||
sourceTree = "<group>";
|
||||
@@ -1114,7 +1117,6 @@
|
||||
inputPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-alt-tab-macos/Pods-alt-tab-macos-frameworks.sh",
|
||||
"${BUILT_PRODUCTS_DIR}/LetsMove/LetsMove.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/Preferences/Preferences.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/ShortcutRecorder/ShortcutRecorder.framework",
|
||||
"${PODS_ROOT}/Sparkle/Sparkle.framework",
|
||||
"${PODS_ROOT}/Sparkle/Sparkle.framework.dSYM",
|
||||
@@ -1123,7 +1125,6 @@
|
||||
name = "[CP] Embed Pods Frameworks";
|
||||
outputPaths = (
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/LetsMove.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Preferences.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ShortcutRecorder.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Sparkle.framework",
|
||||
"${DWARF_DSYM_FOLDER_PATH}/Sparkle.framework.dSYM",
|
||||
@@ -1193,6 +1194,7 @@
|
||||
D04BA56789A2AF52557A9BFF /* AppCenterCrashes.swift in Sources */,
|
||||
D04BADA3F2DAB820D6FC6E75 /* AppCenterApplication.m in Sources */,
|
||||
D04BAA16F21AC41A23DDA63D /* ControlsTab.swift in Sources */,
|
||||
D04BADE4DDF7597749FB13BD /* PreferencesWindow.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
+15
-46
@@ -2,7 +2,6 @@ import Cocoa
|
||||
import Darwin
|
||||
import LetsMove
|
||||
import ShortcutRecorder
|
||||
import Preferences
|
||||
|
||||
let cgsMainConnectionId = CGSMainConnectionID()
|
||||
|
||||
@@ -14,7 +13,7 @@ class App: AppCenterApplication, NSApplicationDelegate {
|
||||
static let repository = "https://github.com/lwouis/alt-tab-macos"
|
||||
static var app: App!
|
||||
var thumbnailsPanel: ThumbnailsPanel!
|
||||
var preferencesWindowController: PreferencesWindowController!
|
||||
var preferencesWindow: PreferencesWindow!
|
||||
var feedbackWindow: FeedbackWindow?
|
||||
var isFirstSummon = true
|
||||
var appIsBeingUsed = false
|
||||
@@ -34,7 +33,7 @@ class App: AppCenterApplication, NSApplicationDelegate {
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
appCenterDelegate = AppCenterCrash()
|
||||
NSApp.disableRelaunchOnLogin()
|
||||
App.shared.disableRelaunchOnLogin()
|
||||
#if DEBUG
|
||||
UserDefaults.standard.set(true, forKey: "NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints")
|
||||
#endif
|
||||
@@ -52,21 +51,20 @@ class App: AppCenterApplication, NSApplicationDelegate {
|
||||
self.thumbnailsPanel = ThumbnailsPanel()
|
||||
Spaces.initialDiscovery()
|
||||
Applications.initialDiscovery()
|
||||
self.loadPreferencesWindow()
|
||||
self.preferencesWindow = PreferencesWindow()
|
||||
KeyboardEvents.observe()
|
||||
MouseEvents.observe()
|
||||
// TODO: undeterministic; events in the queue may still be processing; good enough for now
|
||||
DispatchQueue.main.async { () -> () in Windows.sortByLevel() }
|
||||
self.preloadWindows()
|
||||
#if DEBUG
|
||||
self.showPreferencesPanel()
|
||||
self.showPreferencesWindow()
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
showPreferencesPanel()
|
||||
showPreferencesWindow()
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -81,37 +79,6 @@ class App: AppCenterApplication, NSApplicationDelegate {
|
||||
thumbnailsPanel.orderOut(nil)
|
||||
}
|
||||
|
||||
private func loadPreferencesWindow() {
|
||||
let tabs = [
|
||||
GeneralTab(),
|
||||
ControlsTab(),
|
||||
AppearanceTab(),
|
||||
PoliciesTab(),
|
||||
BlacklistsTab(),
|
||||
AboutTab(),
|
||||
AcknowledgmentsTab(),
|
||||
]
|
||||
// pre-load tabs so we can interact with them before the user opens the preferences window
|
||||
let widest = tabs.reduce(CGFloat(0), {
|
||||
$1.loadView()
|
||||
return max($0, $1.view.subviews[0].fittingSize.width)
|
||||
})
|
||||
tabs.forEach {
|
||||
$0.view.fit(widest, $0.view.subviews[0].fittingSize.height)
|
||||
}
|
||||
|
||||
preferencesWindowController = PreferencesWindowController(preferencePanes: tabs as! [PreferencePane])
|
||||
|
||||
let window = preferencesWindowController.window!
|
||||
window.styleMask.update(with: .miniaturizable)
|
||||
let quitButton = NSButton(title: NSLocalizedString("Quit", comment: ""), target: nil, action: #selector(NSApplication.terminate(_:)))
|
||||
let titleBarView = window.standardWindowButton(.closeButton)!.superview!
|
||||
titleBarView.addSubview(quitButton)
|
||||
quitButton.translatesAutoresizingMaskIntoConstraints = false
|
||||
quitButton.topAnchor.constraint(equalTo: titleBarView.topAnchor, constant: 5).isActive = true
|
||||
quitButton.rightAnchor.constraint(equalTo: titleBarView.rightAnchor, constant: -8).isActive = true
|
||||
}
|
||||
|
||||
// keyboard shortcuts are broken without a menu. We generated the default menu from XCode and load it
|
||||
// see https://stackoverflow.com/a/3746058/2249756
|
||||
private func loadMainMenuXib() {
|
||||
@@ -169,19 +136,21 @@ class App: AppCenterApplication, NSApplicationDelegate {
|
||||
PoliciesTab.checkForUpdatesNow(sender)
|
||||
}
|
||||
|
||||
@objc func showPreferencesPanel() {
|
||||
if let preferencesWindow = preferencesWindowController?.window {
|
||||
preferencesWindowController.show()
|
||||
Screen.repositionPanel(preferencesWindow, Screen.preferred(), .appleCentered)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func showFeedbackPanel() {
|
||||
if feedbackWindow == nil {
|
||||
feedbackWindow = FeedbackWindow()
|
||||
}
|
||||
Screen.repositionPanel(feedbackWindow!, Screen.preferred(), .appleCentered)
|
||||
feedbackWindow?.show()
|
||||
App.shared.activate(ignoringOtherApps: true)
|
||||
feedbackWindow!.makeKeyAndOrderFront(nil)
|
||||
}
|
||||
|
||||
@objc func showPreferencesWindow() {
|
||||
if let preferencesWindow = preferencesWindow {
|
||||
Screen.repositionPanel(preferencesWindow, Screen.preferred(), .appleCentered)
|
||||
App.shared.activate(ignoringOtherApps: true)
|
||||
preferencesWindow.makeKeyAndOrderFront(nil)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func showUi() {
|
||||
|
||||
@@ -13,11 +13,6 @@ class FeedbackWindow: NSWindow {
|
||||
setupView()
|
||||
}
|
||||
|
||||
func show() {
|
||||
App.shared.activate(ignoringOtherApps: true)
|
||||
makeKeyAndOrderFront(nil)
|
||||
}
|
||||
|
||||
private func setupWindow() {
|
||||
title = NSLocalizedString("Send feedback", comment: "")
|
||||
hidesOnDeactivate = false
|
||||
|
||||
@@ -12,7 +12,7 @@ class Menubar {
|
||||
keyEquivalent: "")
|
||||
statusItem.menu!.addItem(
|
||||
withTitle: NSLocalizedString("Preferences…", comment: "Menubar option"),
|
||||
action: #selector(App.app.showPreferencesPanel),
|
||||
action: #selector(App.app.showPreferencesWindow),
|
||||
keyEquivalent: ",")
|
||||
statusItem.menu!.addItem(
|
||||
withTitle: NSLocalizedString("Check for updates…", comment: "Menubar option"),
|
||||
|
||||
@@ -65,7 +65,7 @@ class PermissionsWindow: NSWindow, NSWindowDelegate {
|
||||
}
|
||||
let view = GridView(rows as! [[NSView]])
|
||||
view.fit()
|
||||
// view.cell(atColumnIndex: 0, rowIndex: 4).xPlacement = .trailing
|
||||
|
||||
setContentSize(view.fittingSize)
|
||||
contentView = view
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import Cocoa
|
||||
|
||||
class PreferencesWindow: NSWindow, NSToolbarDelegate {
|
||||
var toolbarItems = [NSToolbarItem.Identifier: (Int, NSToolbarItem, NSView)]()
|
||||
|
||||
override init(contentRect: NSRect, styleMask style: StyleMask, backing backingStoreType: BackingStoreType, defer flag: Bool) {
|
||||
super.init(contentRect: .zero, styleMask: style, backing: backingStoreType, defer: flag)
|
||||
setupWindow()
|
||||
setupView()
|
||||
}
|
||||
|
||||
private func setupWindow() {
|
||||
isReleasedWhenClosed = false
|
||||
hidesOnDeactivate = false
|
||||
styleMask.insert([.miniaturizable, .closable])
|
||||
addQuitButton()
|
||||
}
|
||||
|
||||
private func addQuitButton() {
|
||||
let quitButton = NSButton(title: NSLocalizedString("Quit", comment: ""), target: nil, action: #selector(NSApplication.terminate(_:)))
|
||||
quitButton.translatesAutoresizingMaskIntoConstraints = false
|
||||
let accessoryViewController = NSTitlebarAccessoryViewController()
|
||||
accessoryViewController.view = quitButton
|
||||
accessoryViewController.layoutAttribute = NSLayoutConstraint.Attribute.trailing
|
||||
addTitlebarAccessoryViewController(accessoryViewController)
|
||||
}
|
||||
|
||||
private func setupView() {
|
||||
toolbar = NSToolbar(identifier: "1")
|
||||
toolbar!.delegate = self
|
||||
toolbar!.displayMode = .iconAndLabel
|
||||
toolbar!.showsBaselineSeparator = true
|
||||
[
|
||||
(0, NSLocalizedString("General", comment: ""), "general", GeneralTab.initTab()),
|
||||
(1, NSLocalizedString("Controls", comment: ""), "controls", ControlsTab.initTab()),
|
||||
(2, NSLocalizedString("Appearance", comment: ""), "appearance", AppearanceTab.initTab()),
|
||||
(3, NSLocalizedString("Policies", comment: ""), "policies", PoliciesTab.initTab()),
|
||||
(4, NSLocalizedString("Blacklists", comment: ""), "blacklists", BlacklistsTab.initTab()),
|
||||
(5, NSLocalizedString("About", comment: ""), "about", AboutTab.initTab()),
|
||||
(6, NSLocalizedString("Acknowledgments", comment: ""), "acknowledgments", AcknowledgmentsTab.initTab()),
|
||||
]
|
||||
.forEach { makeToolbarItem($0.0, $0.1, $0.2, $0.3) }
|
||||
|
||||
let largestTabWidth = Array(toolbarItems.values).reduce(CGFloat(0)) { max($0, $1.2.subviews[0].fittingSize.width) }
|
||||
Array(toolbarItems.values).forEach {
|
||||
$0.2.fit(largestTabWidth, $0.2.subviews[0].fittingSize.height)
|
||||
}
|
||||
toolbar!.selectedItemIdentifier = Array(toolbarItems).first { (k, v) in v.0 == 0 }!.key
|
||||
tabItemClicked(toolbarItems[toolbar!.selectedItemIdentifier!]!.1)
|
||||
}
|
||||
|
||||
func makeToolbarItem(_ index: Int, _ label: String, _ image: String, _ view: NSView) {
|
||||
let id = NSToolbarItem.Identifier(rawValue: image)
|
||||
let item = NSToolbarItem(itemIdentifier: id)
|
||||
item.label = label
|
||||
item.image = NSImage.initTemplateCopy(image)
|
||||
item.target = self
|
||||
item.action = #selector(tabItemClicked)
|
||||
let wrapView = NSView(frame: .zero)
|
||||
wrapView.translatesAutoresizingMaskIntoConstraints = false
|
||||
wrapView.subviews = [view]
|
||||
view.centerXAnchor.constraint(equalTo: wrapView.centerXAnchor).isActive = true
|
||||
toolbarItems[id] = (index, item, wrapView)
|
||||
toolbar!.insertItem(withItemIdentifier: id, at: index)
|
||||
}
|
||||
|
||||
@objc func tabItemClicked(_ item: NSToolbarItem) {
|
||||
let item = toolbarItems[item.itemIdentifier]!
|
||||
contentView = item.2
|
||||
title = item.1.label
|
||||
}
|
||||
|
||||
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
|
||||
return toolbarItems[itemIdentifier]!.1
|
||||
}
|
||||
|
||||
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||
return Array(toolbarItems.keys)
|
||||
}
|
||||
|
||||
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||
return Array(toolbarItems.keys)
|
||||
}
|
||||
|
||||
func toolbarSelectableItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||
return Array(toolbarItems.keys)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
import Cocoa
|
||||
import Preferences
|
||||
|
||||
class AboutTab: NSViewController, PreferencePane {
|
||||
let preferencePaneIdentifier = PreferencePane.Identifier("About")
|
||||
let preferencePaneTitle = NSLocalizedString("About", comment: "")
|
||||
let toolbarItemIcon = NSImage.initTemplateCopy("about")
|
||||
|
||||
override func loadView() {
|
||||
class AboutTab {
|
||||
static func initTab() -> NSView {
|
||||
let appIcon = NSImageView(image: NSImage.initResizedCopy("app-icon", 256, 256))
|
||||
appIcon.imageScaling = .scaleNone
|
||||
let appText = StackView([
|
||||
@@ -32,6 +27,6 @@ class AboutTab: NSViewController, PreferencePane {
|
||||
sendFeedbackCell.row!.topPadding = GridView.interPadding
|
||||
grid.fit()
|
||||
|
||||
setView(grid)
|
||||
return grid
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,11 @@
|
||||
import Cocoa
|
||||
import SwiftyMarkdown
|
||||
import Preferences
|
||||
|
||||
class AcknowledgmentsTab: NSViewController, PreferencePane {
|
||||
class AcknowledgmentsTab {
|
||||
// going taller than this will crop the view on small screens or low scaling modes on retina displays
|
||||
static let maxTabHeight = CGFloat(450)
|
||||
let preferencePaneIdentifier = PreferencePane.Identifier("Acknowledgments")
|
||||
let preferencePaneTitle = NSLocalizedString("Acknowledgments", comment: "")
|
||||
let toolbarItemIcon = NSImage.initTemplateCopy("acknowledgments")
|
||||
|
||||
override func loadView() {
|
||||
static func initTab() -> NSView {
|
||||
let textViews: [TextField] = ["Contributors", "Acknowledgments"].map {
|
||||
let markdownFileUrl = Bundle.main.url(forResource: $0, withExtension: "md")!
|
||||
let md = SwiftyMarkdown(url: markdownFileUrl)!
|
||||
@@ -37,6 +33,6 @@ class AcknowledgmentsTab: NSViewController, PreferencePane {
|
||||
scrollView.documentView!.frame.size = subGrid.fittingSize
|
||||
scrollView.fit(totalWidth, totalHeight)
|
||||
|
||||
setView(scrollView)
|
||||
return scrollView
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
import Cocoa
|
||||
import Preferences
|
||||
|
||||
class AppearanceTab: NSViewController, PreferencePane {
|
||||
let preferencePaneIdentifier = PreferencePane.Identifier("Appearance")
|
||||
let preferencePaneTitle = NSLocalizedString("Appearance", comment: "")
|
||||
let toolbarItemIcon = NSImage.initTemplateCopy("appearance")
|
||||
|
||||
override func loadView() {
|
||||
class AppearanceTab {
|
||||
static func initTab() -> NSView {
|
||||
let grid = GridView([
|
||||
LabelAndControl.makeLabelWithDropdown(NSLocalizedString("Theme:", comment: ""), "theme", ThemePreference.allCases),
|
||||
LabelAndControl.makeLabelWithDropdown(NSLocalizedString("Align windows:", comment: ""), "alignThumbnails", AlignThumbnailsPreference.allCases),
|
||||
@@ -30,6 +25,6 @@ class AppearanceTab: NSViewController, PreferencePane {
|
||||
grid.rowAlignment = .lastBaseline
|
||||
grid.fit()
|
||||
|
||||
setView(grid)
|
||||
return grid
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,8 @@
|
||||
import Cocoa
|
||||
import Sparkle
|
||||
import Preferences
|
||||
|
||||
class BlacklistsTab: NSViewController, PreferencePane {
|
||||
let preferencePaneIdentifier = PreferencePane.Identifier("Blacklists")
|
||||
let preferencePaneTitle = NSLocalizedString("Blacklists", comment: "")
|
||||
let toolbarItemIcon = NSImage.initTemplateCopy("blacklists")
|
||||
|
||||
override func loadView() {
|
||||
class BlacklistsTab {
|
||||
static func initTab() -> NSView {
|
||||
let dontShowBlacklistLabel = NSTextField(labelWithString: NSLocalizedString("Don’t show windows from these apps", comment: ""))
|
||||
let dontShowBlacklist = LabelAndControl.makeTextArea(50, 3, ["com.apple.Safari", "com.apple.TextEdit"].joined(separator: "\n"), "dontShowBlacklist")
|
||||
let disableShortcutsBlacklistLabel = NSTextField(labelWithString: NSLocalizedString("Ignore shortcuts while a window from these apps is active", comment: ""))
|
||||
@@ -24,6 +19,6 @@ class BlacklistsTab: NSViewController, PreferencePane {
|
||||
grid.row(at: 2).topPadding = GridView.interPadding * 1.5
|
||||
grid.fit()
|
||||
|
||||
setView(grid)
|
||||
return grid
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
import Cocoa
|
||||
import ShortcutRecorder
|
||||
import Preferences
|
||||
|
||||
class ControlsTab: NSViewController, PreferencePane {
|
||||
let preferencePaneIdentifier = PreferencePane.Identifier("Controls")
|
||||
let preferencePaneTitle = NSLocalizedString("Controls", comment: "")
|
||||
let toolbarItemIcon = NSImage.initTemplateCopy("controls")
|
||||
|
||||
class ControlsTab {
|
||||
static var nextWindowShortcut: [NSControl]!
|
||||
static var localShortcuts = [String: Shortcut]()
|
||||
static var globalShortcuts = [String: Shortcut]()
|
||||
@@ -28,7 +23,7 @@ class ControlsTab: NSViewController, PreferencePane {
|
||||
"hideShowAppShortcut": { App.app.hideShowSelectedApp() },
|
||||
]
|
||||
|
||||
override func loadView() {
|
||||
static func initTab() -> NSView {
|
||||
let shortcutStyle = LabelAndControl.makeLabelWithDropdown(NSLocalizedString("then release:", comment: ""), "shortcutStyle", ShortcutStylePreference.allCases)
|
||||
let focusWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Focus selected window", comment: ""), "focusWindowShortcut", Preferences.focusWindowShortcut, labelPosition: .right)
|
||||
let previousWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Select previous window", comment: ""), "previousWindowShortcut", Preferences.previousWindowShortcut, labelPosition: .right)
|
||||
@@ -71,10 +66,10 @@ class ControlsTab: NSViewController, PreferencePane {
|
||||
tabView.leftAnchor.constraint(equalTo: tabView.superview!.leftAnchor, constant: leftColumnWidthTopView - leftColumnWidthTabView + 3).isActive = true
|
||||
}
|
||||
|
||||
setView(grid)
|
||||
return grid
|
||||
}
|
||||
|
||||
private func toShowSection(_ postfix: String) -> ([NSView], GridView) {
|
||||
private static func toShowSection(_ postfix: String) -> ([NSView], GridView) {
|
||||
let toShowExplanations = LabelAndControl.makeLabel(NSLocalizedString("Show the following windows:", comment: ""))
|
||||
var holdShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Hold", comment: ""), "holdShortcut" + postfix, Preferences.holdShortcut[postfix == "" ? 0 : 1], false, labelPosition: .leftWithoutSeparator)
|
||||
holdShortcut.append(LabelAndControl.makeLabel(NSLocalizedString("and press:", comment: "")))
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import Cocoa
|
||||
import Preferences
|
||||
|
||||
class GeneralTab: NSViewController, PreferencePane {
|
||||
let preferencePaneIdentifier = PreferencePane.Identifier("General")
|
||||
let preferencePaneTitle = NSLocalizedString("General", comment: "")
|
||||
let toolbarItemIcon = NSImage.initTemplateCopy("general")
|
||||
|
||||
override func loadView() {
|
||||
class GeneralTab {
|
||||
static func initTab() -> NSView {
|
||||
let startAtLogin = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Start at login:", comment: ""), "startAtLogin", extraAction: startAtLoginCallback)
|
||||
let menubarIcon = LabelAndControl.makeLabelWithDropdown(NSLocalizedString("Menubar icon:", comment: ""), "menubarIcon", MenubarIconPreference.allCases, extraAction: Menubar.menubarIconCallback)
|
||||
let menubarIconDropdown = menubarIcon[1] as! NSPopUpButton
|
||||
@@ -28,14 +23,14 @@ class GeneralTab: NSViewController, PreferencePane {
|
||||
grid.column(at: 0).xPlacement = .trailing
|
||||
grid.fit()
|
||||
|
||||
setView(grid)
|
||||
|
||||
startAtLoginCallback(startAtLogin[1] as! NSControl)
|
||||
|
||||
return grid
|
||||
}
|
||||
|
||||
// adding/removing login item depending on the checkbox state
|
||||
@available(OSX, deprecated: 10.11)
|
||||
func startAtLoginCallback(_ sender: NSControl) {
|
||||
static func startAtLoginCallback(_ sender: NSControl) {
|
||||
let loginItems = LSSharedFileListCreate(nil, kLSSharedFileListSessionLoginItems.takeRetainedValue(), nil).takeRetainedValue()
|
||||
let loginItemsSnapshot = LSSharedFileListCopySnapshot(loginItems, nil).takeRetainedValue() as! [LSSharedFileListItem]
|
||||
let itemName = Bundle.main.bundleURL.lastPathComponent as CFString
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
import Cocoa
|
||||
import Sparkle
|
||||
import Preferences
|
||||
|
||||
class PoliciesTab: NSViewController, PreferencePane {
|
||||
let preferencePaneIdentifier = PreferencePane.Identifier("Policies")
|
||||
let preferencePaneTitle = NSLocalizedString("Policies", comment: "")
|
||||
let toolbarItemIcon = NSImage.initTemplateCopy("policies")
|
||||
|
||||
class PoliciesTab {
|
||||
static var updateButtons: [NSButton]!
|
||||
static var crashButtons: [NSButton]!
|
||||
// this helps prevent double-dipping (i.e. user updates the UI > changes the preference > updates the UI)
|
||||
static var policyLock = false
|
||||
|
||||
override func loadView() {
|
||||
static func initTab() -> NSView {
|
||||
let updateLabel = LabelAndControl.makeLabel(NSLocalizedString("Updates policy:", comment: ""))
|
||||
PoliciesTab.updateButtons = LabelAndControl.makeRadioButtons(UpdatePolicyPreference.allCases, "updatePolicy", extraAction: { _ in
|
||||
PoliciesTab.policyLock = true
|
||||
@@ -36,9 +31,9 @@ class PoliciesTab: NSViewController, PreferencePane {
|
||||
grid.row(at: 2).topPadding = GridView.interPadding * 1.5
|
||||
grid.fit()
|
||||
|
||||
setView(grid)
|
||||
|
||||
UserDefaultsEvents.observe()
|
||||
|
||||
return grid
|
||||
}
|
||||
|
||||
@objc static func checkForUpdatesNow(_ sender: Any) {
|
||||
|
||||
Reference in new issue
Block a user