Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v4.0.0 #185

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions WakaTime/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {

@objc func checkForUpdatesClicked(_ sender: AnyObject) {
updater.check {
if self.notificationsEnabled {
self.sendNotification(title: "Updating to latest release")
}
self.toastNotification("Updating to latest release")
}.catch(policy: .allErrors) { error in
if error.isCancelled {
let alert = NSAlert()
Expand Down Expand Up @@ -154,14 +152,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {
monitoredAppsWindowController.showWindow(self)
}

private func sendNotification(title: String, body: String = "") {
internal func toastNotification(_ title: String) {
guard notificationsEnabled else { return }

let content = UNMutableNotificationContent()
content.title = title

if !body.isEmpty {
content.body = body
}

let uuidString = UUID().uuidString
let request = UNNotificationRequest(
identifier: uuidString,
Expand Down
15 changes: 15 additions & 0 deletions WakaTime/Helpers/PropertiesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class PropertiesManager {
enum Keys: String {
case shouldLaunchOnLogin = "launch_on_login"
case shouldAutomaticallyDownloadUpdates = "should_automatically_download_updates"
case hasLaunchedBefore = "has_launched_before"
}
static var shouldLaunchOnLogin: Bool {
get {
Expand Down Expand Up @@ -34,4 +35,18 @@ class PropertiesManager {
UserDefaults.standard.synchronize()
}
}

static var hasLaunchedBefore: Bool {
get {
guard UserDefaults.standard.string(forKey: Keys.hasLaunchedBefore.rawValue) != nil else {
return false
}

return UserDefaults.standard.bool(forKey: Keys.hasLaunchedBefore.rawValue)
}
set {
UserDefaults.standard.set(newValue, forKey: Keys.hasLaunchedBefore.rawValue)
UserDefaults.standard.synchronize()
}
}
}
10 changes: 10 additions & 0 deletions WakaTime/WakaTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class WakaTime: HeartbeatEventHandler {
}
print("********* End Running Applications *********")
}

if !PropertiesManager.hasLaunchedBefore {
PropertiesManager.hasLaunchedBefore = true
}
}

private func configureFirebase() {
Expand All @@ -63,10 +67,15 @@ class WakaTime: HeartbeatEventHandler {
}

private func checkForNewlySupportedApps() {
guard PropertiesManager.hasLaunchedBefore else { return }

let newApps = MonitoringManager.newlySupportedApps()
guard !newApps.isEmpty else { return }

openMonitoredAppsDeeplink()

let plural = newApps.count == 1 ? "" : "s"
delegate.toastNotification("Review \(newApps.count) new app\(plural)")
}

private func openSettingsDeeplink() {
Expand Down Expand Up @@ -181,6 +190,7 @@ enum Category: String {

protocol StatusBarDelegate: AnyObject {
func a11yStatusChanged(_ hasPermission: Bool)
func toastNotification(_ title: String)
}

protocol HeartbeatEventHandler {
Expand Down
Loading