Skip to content

Commit 4db9077

Browse files
author
Aditya Vaidyam
committed
AppManagement now displays an alert for any available updates, and VibrancyStyle + listeners work.
1 parent 7ef3df5 commit 4db9077

14 files changed

+251
-112
lines changed

Parrot.xcodeproj/project.pbxproj

+22-14
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
489018AA1D3C8CB800CFCA5F /* Focus+Presence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 489018A91D3C8CB800CFCA5F /* Focus+Presence.swift */; };
6767
489018AC1D3C8FE400CFCA5F /* Person+Directory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 489018AB1D3C8FE400CFCA5F /* Person+Directory.swift */; };
6868
489018AE1D3EA2DB00CFCA5F /* LinkPreviewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 489018AD1D3EA2DB00CFCA5F /* LinkPreviewCell.swift */; };
69-
48A452271D19B16500CB588A /* Tone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48A452261D19B16500CB588A /* Tone.swift */; };
69+
48A452271D19B16500CB588A /* TLTone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48A452261D19B16500CB588A /* TLTone.swift */; };
7070
48AD01E11C1ECBE70031FDD7 /* LinkPreviewParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48AD01E01C1ECBE70031FDD7 /* LinkPreviewParser.swift */; };
7171
48B3AD781C38043B0023FAA3 /* Canvas.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48B3AD771C38043B0023FAA3 /* Canvas.swift */; };
7272
48BA5B4B1C37A55A00ACA29B /* Terminal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48BA5B4A1C37A55A00ACA29B /* Terminal.swift */; };
@@ -296,7 +296,7 @@
296296
489018A91D3C8CB800CFCA5F /* Focus+Presence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Focus+Presence.swift"; sourceTree = "<group>"; };
297297
489018AB1D3C8FE400CFCA5F /* Person+Directory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Person+Directory.swift"; sourceTree = "<group>"; };
298298
489018AD1D3EA2DB00CFCA5F /* LinkPreviewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkPreviewCell.swift; sourceTree = "<group>"; };
299-
48A452261D19B16500CB588A /* Tone.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tone.swift; sourceTree = "<group>"; };
299+
48A452261D19B16500CB588A /* TLTone.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TLTone.swift; sourceTree = "<group>"; };
300300
48AD01DE1C1EC8A90031FDD7 /* KeyValueStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = KeyValueStore.swift; path = Parrot/KeyValueStore.swift; sourceTree = SOURCE_ROOT; };
301301
48AD01E01C1ECBE70031FDD7 /* LinkPreviewParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkPreviewParser.swift; sourceTree = "<group>"; };
302302
48B3AD771C38043B0023FAA3 /* Canvas.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Canvas.swift; sourceTree = "<group>"; };
@@ -456,6 +456,7 @@
456456
48196B9C1D480624001D4BAA /* Experimental */ = {
457457
isa = PBXGroup;
458458
children = (
459+
48BFAECF1D1CF19100ADBA3A /* AppActivity.swift */,
459460
48574F121D11F9FC002375E1 /* AppManagement.swift */,
460461
48EB54F51D209DD100F77C2C /* Cache.swift */,
461462
4814E3BA1D2ECB4F0079C3DB /* DispatchTask.swift */,
@@ -480,12 +481,10 @@
480481
isa = PBXGroup;
481482
children = (
482483
488239A21C455CED00C5E8EB /* AppKitSupport.swift */,
483-
48196B9C1D480624001D4BAA /* Experimental */,
484-
48BFAECF1D1CF19100ADBA3A /* AppActivity.swift */,
485484
48AD01DE1C1EC8A90031FDD7 /* KeyValueStore.swift */,
486485
4835ECB61C1C672900193EBC /* Emoji.swift */,
487-
48A452261D19B16500CB588A /* Tone.swift */,
488486
4866337D1C5822FA006C094B /* ListView.swift */,
487+
48A452261D19B16500CB588A /* TLTone.swift */,
489488
4835ECB31C1C672900193EBC /* NSExtendedUserNotificationCenter.swift */,
490489
488201B51D4A962B00C545F0 /* NSExtendedTextView.swift */,
491490
488201B71D4A968F00C545F0 /* NSAntiScrollView.swift */,
@@ -529,6 +528,17 @@
529528
name = API;
530529
sourceTree = "<group>";
531530
};
531+
488201BD1D4AA2D700C545F0 /* Helpers */ = {
532+
isa = PBXGroup;
533+
children = (
534+
4835ECAE1C1C620E00193EBC /* Authenticator.swift */,
535+
48F077161D1DE8DC003964FD /* ParrotAppearance.swift */,
536+
488201BB1D4A970400C545F0 /* PersonaImage.swift */,
537+
48AD01E01C1ECBE70031FDD7 /* LinkPreviewParser.swift */,
538+
);
539+
name = Helpers;
540+
sourceTree = "<group>";
541+
};
532542
48834D891C1B3602009BC442 = {
533543
isa = PBXGroup;
534544
children = (
@@ -566,8 +576,10 @@
566576
children = (
567577
4835ECA51C1C61F300193EBC /* Conversation List */,
568578
481687231C39D3400070EEF6 /* Message List */,
569-
48C35AB31D1E45620022997B /* Helpers */,
579+
48C35AB31D1E45620022997B /* App UI */,
580+
488201BD1D4AA2D700C545F0 /* Helpers */,
570581
4835ECB21C1C672300193EBC /* Extensions */,
582+
48196B9C1D480624001D4BAA /* Experimental */,
571583
48834DC11C1B36D1009BC442 /* Supporting Files */,
572584
);
573585
path = Parrot;
@@ -645,19 +657,15 @@
645657
name = Curses;
646658
sourceTree = "<group>";
647659
};
648-
48C35AB31D1E45620022997B /* Helpers */ = {
660+
48C35AB31D1E45620022997B /* App UI */ = {
649661
isa = PBXGroup;
650662
children = (
651-
48834D951C1B3602009BC442 /* ParrotAppController.swift */,
652663
4884927C1D0B46BB0003D522 /* Main.storyboard */,
653-
48F077161D1DE8DC003964FD /* ParrotAppearance.swift */,
654-
4835ECAE1C1C620E00193EBC /* Authenticator.swift */,
664+
48834D951C1B3602009BC442 /* ParrotAppController.swift */,
655665
48196B9A1D4805D9001D4BAA /* AboutWindowController.swift */,
656666
48808EDC1C6463DD00236E96 /* PreferencesWindowController.swift */,
657-
488201BB1D4A970400C545F0 /* PersonaImage.swift */,
658-
48AD01E01C1ECBE70031FDD7 /* LinkPreviewParser.swift */,
659667
);
660-
name = Helpers;
668+
name = "App UI";
661669
sourceTree = "<group>";
662670
};
663671
48DE52C91C1CC12900647C63 /* ParrotShare */ = {
@@ -1167,7 +1175,7 @@
11671175
48AD01E11C1ECBE70031FDD7 /* LinkPreviewParser.swift in Sources */,
11681176
4835ECB71C1C672900193EBC /* NSExtendedUserNotificationCenter.swift in Sources */,
11691177
4813003A1D25B54300768D79 /* ServiceRegistry.swift in Sources */,
1170-
48A452271D19B16500CB588A /* Tone.swift in Sources */,
1178+
48A452271D19B16500CB588A /* TLTone.swift in Sources */,
11711179
);
11721180
runOnlyForDeploymentPostprocessing = 0;
11731181
};

Parrot/AppActivity.swift

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import class ParrotServiceExtension.Logger
66
/* TODO: Integrate NSProgress, Logger, os_activity, and os_trace. */
77
/* TODO: Add property .cancellable and ensure NSApplication doesn't quit until .cancellable propogates. */
88
/* TODO: Use applicationShouldTerminate() to control this behavior. */
9+
/* TODO: Merge with DispatchOperation perhaps? */
910

1011
/*public var log: Logger {
1112
return AppActivity.current.logger

Parrot/AppManagement.swift

+26-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Foundation
2+
import class AppKit.NSAlert
3+
import class AppKit.NSTextField
24

35
/* TODO: Finish Semver comparison and handle app update mechanism. */
46
let SEMVER_REGEX = "\\bv?(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)(?:-[\\da-z\\-]+(?:\\.[\\da-z\\-]+)*)?(?:\\+[\\da-z\\-]+(?:\\.[\\da-z\\-]+)*)?\\b"
@@ -33,15 +35,15 @@ public struct GithubRelease {
3335
else { return nil }
3436

3537
// If we're in pre-release mode, ensure we have at least one entry.
36-
if prerelease && json[0] != nil {
37-
json = json[0]!
38-
} else { return nil }
38+
if let js = json as? [AnyObject] where prerelease {
39+
json = js[0]
40+
} else if prerelease { return nil }
3941

4042
guard let releaseName = json["name"] as? String,
4143
let buildTag = json["tag_name"] as? String,
4244
let releaseNotes = json["body"] as? String,
4345
let appUpdate = json["zipball_url"] as? String,
44-
let githubURL = json["url"] as? String
46+
let githubURL = json["html_url"] as? String
4547
else { return nil }
4648

4749
return GithubRelease(releaseName: releaseName, buildTag: buildTag,
@@ -73,15 +75,24 @@ public struct Semver {
7375
}
7476
}
7577

76-
// For testing UI updates later.
77-
public func __test() {
78-
let release = GithubRelease.latest(prerelease: true)
79-
let n = NSUserNotification()
80-
n.hasActionButton = true
81-
n.title = "Parrot \(release!.releaseName) available"
82-
n.actionButtonTitle = "Update"
83-
n.identifier = "com.avaidyam.Parrot.UpdateNotification"
84-
n.informativeText = release!.releaseNotes
85-
UserNotificationCenter.deliver(n)
86-
log.info("\(release)")
78+
// For initial release alerts.
79+
// FIXME: Don't hardcode things.
80+
public func checkForUpdates(_ buildTag: String, _ updateHandler: (GithubRelease) -> Void = {_ in}) {
81+
guard let release = GithubRelease.latest(prerelease: true) else { return }
82+
guard release.buildTag == buildTag else { return }
83+
84+
let a = NSAlert()
85+
a.alertStyle = .informational
86+
a.messageText = "\(release.releaseName) available"
87+
a.informativeText = release.releaseNotes
88+
a.addButton(withTitle: "Update")
89+
a.addButton(withTitle: "Ignore")
90+
a.showsSuppressionButton = true // FIXME
91+
92+
a.layout()
93+
a.window.appearance = ParrotAppearance.current()
94+
a.window.enableRealTitlebarVibrancy(.behindWindow) // FIXME
95+
if a.runModal() == 1000 /*NSAlertFirstButtonReturn*/ {
96+
updateHandler(release)
97+
}
8798
}

0 commit comments

Comments
 (0)