Skip to content

Commit 0d0b674

Browse files
committed
Auto update with Sparkle framework.
1 parent f40905b commit 0d0b674

File tree

225 files changed

+8172
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+8172
-65
lines changed

Application/AppDelegate.swift

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121
// along with SyntaxHighlight. If not, see <http://www.gnu.org/licenses/>.
2222

2323
import Cocoa
24+
import Sparkle
2425
import Syntax_Highlight_XPC_Service
2526

2627
typealias ExampleItem = (url: URL, title: String, uti: String)
2728

2829
@NSApplicationMain
29-
class AppDelegate: NSObject, NSApplicationDelegate {
30+
class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
31+
var userDriver: SPUStandardUserDriver?
32+
var updater: SPUUpdater?
33+
3034
lazy var connection: NSXPCConnection = {
3135
let connection = NSXPCConnection(serviceName: "org.sbarex.SourceCodeSyntaxHighlight.XPCService")
3236
connection.remoteObjectInterface = NSXPCInterface(with: SCSHXPCServiceProtocol.self)
@@ -47,6 +51,37 @@ class AppDelegate: NSObject, NSApplicationDelegate {
4751
if #available(OSX 10.12.2, *) {
4852
NSApplication.shared.isAutomaticCustomizeTouchBarMenuItemEnabled = true
4953
}
54+
55+
let hostBundle = Bundle.main
56+
let applicationBundle = hostBundle;
57+
58+
self.userDriver = SPUStandardUserDriver(hostBundle: hostBundle, delegate: nil)
59+
self.updater = SPUUpdater(hostBundle: hostBundle, applicationBundle: applicationBundle, userDriver: self.userDriver!, delegate: nil)
60+
61+
do {
62+
try self.updater!.start()
63+
} catch {
64+
print("Failed to start updater with error: \(error)")
65+
66+
let alert = NSAlert()
67+
alert.messageText = "Updater Error"
68+
alert.informativeText = "The Updater failed to start. For detailed error information, check the Console.app log."
69+
alert.addButton(withTitle: "OK")
70+
alert.runModal()
71+
}
72+
}
73+
74+
@IBAction func checkForUpdates(_ sender: Any)
75+
{
76+
self.updater?.checkForUpdates()
77+
}
78+
79+
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool
80+
{
81+
if menuItem.action == #selector(self.checkForUpdates(_:)) {
82+
return self.userDriver?.canCheckForUpdates ?? false
83+
}
84+
return true
5085
}
5186

5287
func applicationWillTerminate(_ aNotification: Notification) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "ext_on.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
},
12+
"properties" : {
13+
"template-rendering-intent" : "template"
14+
}
15+
}
209 KB
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "ext.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
},
12+
"properties" : {
13+
"preserves-vector-representation" : true,
14+
"template-rendering-intent" : "template"
15+
}
16+
}
212 KB
Binary file not shown.

Application/Base.lproj/Main.storyboard

Lines changed: 55 additions & 40 deletions
Large diffs are not rendered by default.

Application/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<key>LSMinimumSystemVersion</key>
3838
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
3939
<key>NSHumanReadableCopyright</key>
40-
<string>Copyright © 2019 SBAREX. All rights reserved.</string>
40+
<string>Copyright © 2020 SBAREX. All rights reserved.</string>
4141
<key>NSMainStoryboardFile</key>
4242
<string>Main</string>
4343
<key>NSPrincipalClass</key>
@@ -51,7 +51,7 @@
5151
<key>SUPublicEDKey</key>
5252
<string>J+ikFQXeR6eaUV0jvyfZAJKeYh+9UKGJuD/kJSIXnZk=</string>
5353
<key>SUScheduledCheckInterval</key>
54-
<integer>604800</integer>
54+
<integer>86400</integer>
5555
<key>UTExportedTypeDeclarations</key>
5656
<array>
5757
<dict>

Application/PreferencesViewController.swift

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class PreferencesViewController: NSViewController {
106106
/// Search field for filter the UTI list.
107107
@IBOutlet weak var searchField: NSSearchField!
108108
@IBOutlet weak var filterButton: NSButton!
109+
@IBOutlet weak var extensionButton: NSButton!
109110

110111
/// Preview view.
111112
@IBOutlet weak var previewView: PreviewView!
@@ -125,6 +126,15 @@ class PreferencesViewController: NSViewController {
125126

126127
internal var initialized = false
127128

129+
/// Show UTI instead of extensions.
130+
var showUTI: Bool = false {
131+
didSet {
132+
self.extensionButton.image = NSImage(named: !showUTI ? "ext-ON" : "ext")
133+
self.extensionButton.contentTintColor = !showUTI ? NSColor.controlAccentColor : NSColor.secondaryLabelColor
134+
self.tableView.reloadData()
135+
}
136+
}
137+
128138
internal var isDirty = false {
129139
didSet {
130140
self.view.window?.isDocumentEdited = isDirty
@@ -273,6 +283,8 @@ class PreferencesViewController: NSViewController {
273283

274284
// MARK: -
275285
override func viewDidLoad() {
286+
self.showUTI = false // Force the button refresh.
287+
276288
globalSettingsView.delegate = self
277289
appearanceView.delegate = self
278290
extraSettingsView.delegate = self
@@ -598,6 +610,11 @@ class PreferencesViewController: NSViewController {
598610
sender.contentTintColor = sender.state == .on ? NSColor.controlAccentColor : NSColor.secondaryLabelColor
599611
}
600612

613+
/// Show UTIs or extensions.
614+
@IBAction func handleExtensionButton(_ sender: NSButton) {
615+
self.showUTI = sender.state == .off
616+
}
617+
601618
// MARK: -
602619

603620
@IBAction func showHelp(_ sender: Any) {
@@ -830,7 +847,7 @@ extension PreferencesViewController: NSTableViewDataSource {
830847
}
831848
}
832849

833-
// MARK: - NSTableViewDelegate
850+
// MARK: NSTableViewDelegate
834851
extension PreferencesViewController: NSTableViewDelegate {
835852
func tableViewSelectionIsChanging(_ notification: Notification) {
836853
if currentUTI == nil {
@@ -861,7 +878,7 @@ extension PreferencesViewController: NSTableViewDelegate {
861878
}
862879

863880
func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
864-
return row == 0 || row == 2 ? 30 : 38
881+
return row == 0 || row == 2 ? 30 : 42
865882
}
866883

867884
func tableView(_ tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
@@ -881,17 +898,21 @@ extension PreferencesViewController: NSTableViewDelegate {
881898
} else if column.identifier == NSUserInterfaceItemIdentifier("Name") {
882899
if row > 2 {
883900
let suppressed = fileTypes[row - 3].extensions.count > 0 && fileTypes[row - 3].suppressedExtensions.count == fileTypes[row - 3].extensions.count
901+
v.textField?.stringValue = fileTypes[row - 3].description
902+
v.textField?.textColor = suppressed ? .disabledControlTextColor : .labelColor
884903
if let cell = v as? UTITableCellView {
885-
v.textField?.stringValue = fileTypes[row - 3].description
886-
cell.extensionTextField.stringValue = fileTypes[row - 3].extensions.count > 0 ? "." + fileTypes[row - 3].extensions.joined(separator: ", .") : ""
904+
let extensions = fileTypes[row - 3].extensions.count > 0 ? "." + fileTypes[row - 3].extensions.joined(separator: ", .") : ""
905+
if showUTI {
906+
cell.extensionTextField.stringValue = fileTypes[row - 3].uti.UTI
907+
} else {
908+
cell.extensionTextField.stringValue = extensions
909+
}
887910
cell.extensionTextField.isHidden = false
888911
cell.extensionTextField.textColor = suppressed ? .disabledControlTextColor : .labelColor
912+
cell.extensionTextField.toolTip = showUTI ? extensions : self.fileTypes[row - 3].uti.UTI
889913
} else {
890-
v.textField?.stringValue = fileTypes[row - 3].fullDescription
914+
v.toolTip = self.fileTypes[row - 3].uti.UTI
891915
}
892-
v.toolTip = self.fileTypes[row - 3].uti.UTI
893-
894-
v.textField?.textColor = suppressed ? .disabledControlTextColor : .labelColor
895916
} else if row == 1 {
896917
v.textField?.stringValue = "Global"
897918
v.textField?.textColor = .labelColor
@@ -918,6 +939,7 @@ extension PreferencesViewController: NSTabViewDelegate {
918939

919940
}
920941

942+
// MARK: - AppearanceViewDelegate
921943
extension PreferencesViewController: AppearanceViewDelegate {
922944
func appearance(appearanceView: AppearanceView, requestBrowserForTheme theme: SCSHTheme?, mode: ThemeStyleFilterEnum, fromView: NSView, onComplete: @escaping (_ theme: SCSHTheme?)->Void) {
923945
guard let vc = self.storyboard?.instantiateController(withIdentifier:"ThemeSelector") as? ThemeSelectorViewController else {
@@ -950,12 +972,14 @@ extension PreferencesViewController: AppearanceViewDelegate {
950972
}
951973
}
952974

975+
// MARK: ExtraSettingsViewDelegate
953976
extension PreferencesViewController: ExtraSettingsViewDelegate {
954977
func extraSettingsRequestRefreshPreview(extraSettingsView: ExtraSettingsView) {
955978
previewView.refresh(extraSettingsView)
956979
}
957980
}
958981

982+
// MARK: GlobalSettingsViewDelegate
959983
extension PreferencesViewController: GlobalSettingsViewDelegate {
960984
/// Shows the about highlight window,
961985
func globalSettings(globalSettingsView: GlobalSettingsView, showHighlightInfoForPath path: String?) {
@@ -1002,7 +1026,7 @@ extension PreferencesViewController: GlobalSettingsViewDelegate {
10021026
}
10031027
}
10041028

1005-
1029+
// MARK: - NSTouchBarDelegate
10061030
extension PreferencesViewController: NSTouchBarDelegate {
10071031

10081032
}

Application/SCSHApp.entitlements

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<true/>
77
<key>com.apple.security.automation.apple-events</key>
88
<true/>
9+
<key>com.apple.security.cs.disable-library-validation</key>
10+
<true/>
911
<key>com.apple.security.files.user-selected.read-write</key>
1012
<true/>
1113
<key>com.apple.security.get-task-allow</key>
-2 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)