Skip to content

Commit

Permalink
added full ability to show notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
DarraghRogan committed Sep 20, 2020
1 parent 22eec9e commit 243c904
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 64 deletions.
8 changes: 4 additions & 4 deletions Miasma.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 11;
CURRENT_PROJECT_VERSION = 12;
DEVELOPMENT_TEAM = VDLCQ62KZH;
ENABLE_HARDENED_RUNTIME = YES;
EXCLUDED_ARCHS = "";
Expand All @@ -568,7 +568,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.06;
MARKETING_VERSION = 1.07;
PRODUCT_BUNDLE_IDENTIFIER = "Darragh-Rogan.Miasma";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -584,7 +584,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 11;
CURRENT_PROJECT_VERSION = 12;
DEVELOPMENT_TEAM = VDLCQ62KZH;
ENABLE_HARDENED_RUNTIME = YES;
EXCLUDED_ARCHS = "";
Expand All @@ -594,7 +594,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.06;
MARKETING_VERSION = 1.07;
PRODUCT_BUNDLE_IDENTIFIER = "Darragh-Rogan.Miasma";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
filePath = "Miasma/Menu.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "354"
endingLineNumber = "354"
landmarkName = "unknown"
landmarkType = "0">
startingLineNumber = "398"
endingLineNumber = "398"
landmarkName = "menuLoadOptionals()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand Down
26 changes: 15 additions & 11 deletions Miasma/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,26 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele

// setup ability to have notifications -code from https://nabtron.com/show-notification-cocoa-xcode-swift/

func showNotification() -> Void {
func showNotification(title: String, subtitle: String, informativeText: String) -> Void {

var notification = NSUserNotification()
// All these values are optional
notification.title = "Test of notification"
notification.subtitle = "Subtitle of notifications"
notification.informativeText = "Main informative text"
// notification.contentImage = Root\Graphics\RoundedIcon.png

notification.title = title
notification.subtitle = subtitle
notification.informativeText = informativeText
// notification.contentImage = contentImage
notification.soundName = NSUserNotificationDefaultSoundName

NSUserNotificationCenter.default.deliver(notification)

}

func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
AppDelegate().defaults.set(1, forKey: "ClimbingAQINotificationsWanted")
return true
}



func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
Expand All @@ -53,9 +56,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
// setup ability to have notifications -code from https://nabtron.com/show-notification-cocoa-xcode-swift/

NSUserNotificationCenter.default.delegate = self

showNotification()



// setting first launch to default to using WAQI with "here" as the city, to give users a nice first impression. Following technique from: https://medium.com/better-programming/checking-for-the-users-first-launch-in-swift-df02a1feb472

Expand All @@ -66,13 +67,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele

} else if (defaults.bool(forKey: "First Launch") == true || defaults.integer(forKey: "PurpleAirInUse") == 1) {

defaults.set(true, forKey: "First Launch")

} else {

defaults.set(true, forKey: "First Launch")
defaults.set("here", forKey: "WAQICity")
defaults.set(1, forKey: "WAQIInUse")
defaults.set(1, forKey:"CO2SignalInUse")
defaults.set(1, forKey:"OpenSkyInUse")
defaults.set(1, forKey:"ClimbingAQINotificationsWanted")

}

Expand Down
Loading

0 comments on commit 243c904

Please sign in to comment.