Skip to content

Commit

Permalink
Disable new apps by default
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Nov 30, 2023
1 parent e6b5883 commit d4c1a50
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 43 deletions.
28 changes: 1 addition & 27 deletions WakaTime/Helpers/MonitoringManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ class MonitoringManager {
let isMonitored = UserDefaults.standard.bool(forKey: isMonitoredKey)
return isMonitored
} else {

// make sure newly supported apps are cached before we set defaults
assert(newlySupportedApps.count > -1)

UserDefaults.standard.set(true, forKey: isMonitoredKey)
UserDefaults.standard.set(false, forKey: isMonitoredKey)
UserDefaults.standard.synchronize()
}
return true
Expand All @@ -32,28 +28,6 @@ class MonitoringManager {
return isAppMonitored(for: bundleId)
}

static func isAppNewlySupported(for bundleId: String) -> Bool {
guard MonitoredApp.allBundleIds.contains(bundleId) else { return false }

let isMonitoredKey = monitoredKey(bundleId: bundleId)

return UserDefaults.standard.string(forKey: isMonitoredKey) == nil
}

static var newlySupportedApps: [String] = {
// cache newly supported apps
var newApps: [String] = []
for bundleId in MonitoredApp.allBundleIds {
guard
AppInfo.getIcon(bundleId: bundleId) != nil,
AppInfo.getAppName(bundleId: bundleId) != nil,
isAppNewlySupported(for: bundleId)
else { continue }
newApps.append(bundleId)
}
return newApps
}()

static func isAppElectron(for bundleId: String) -> Bool {
MonitoredApp.electronAppIds.contains(bundleId)
}
Expand Down
18 changes: 2 additions & 16 deletions WakaTime/WakaTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class WakaTime: HeartbeatEventHandler {
}

configureFirebase()
checkForApiKeyOrNewApps()
checkForApiKey()
watcher.heartbeatEventHandler = self
watcher.statusBarDelegate = delegate

Expand Down Expand Up @@ -57,27 +57,13 @@ class WakaTime: HeartbeatEventHandler {
FirebaseApp.configure()
}

private func checkForApiKeyOrNewApps() {
private func checkForApiKey() {
let apiKey = ConfigFile.getSetting(section: "settings", key: "api_key")
if apiKey.isEmpty {
openSettingsDeeplink()
} else {
checkForNewlySupportedApps()
}
}

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() {
guard let url = DeepLink.settings.url else { return }

Expand Down

0 comments on commit d4c1a50

Please sign in to comment.