mirror of
https://github.com/lwouis/alt-tab-macos.git
synced 2026-05-24 11:20:36 +00:00
feat: add local usage stats for curious users
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
1C96182DB77D780F714B53B1 /* thumbnails_show_space_number_labels_light@2x.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 1C96145685B5DFCD24C58943 /* thumbnails_show_space_number_labels_light@2x.jpg */; };
|
||||
1C96188384C430DD33DAA11D /* app_icons_show_tabs_as_windows_light@2x.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 1C9612B6E0A459B88CD26DAF /* app_icons_show_tabs_as_windows_light@2x.jpg */; };
|
||||
1C9618872DD3863A8EFE8414 /* Appearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C961AC3633CD0C62CCE050E /* Appearance.swift */; };
|
||||
AA0C8B000000000000000001 /* UsageStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0C8B000000000000000002 /* UsageStats.swift */; };
|
||||
1C9618DD03B2945DB2D15EBE /* thumbnails_align_thumbnails_leading_light@2x.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 1C961A0A3EF637793B0F9B89 /* thumbnails_align_thumbnails_leading_light@2x.jpg */; };
|
||||
1C9618DF753B19DB0A1255E4 /* titles_hide_app_badges_light@2x.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 1C961E051A3A4E4A174BB7C7 /* titles_hide_app_badges_light@2x.jpg */; };
|
||||
1C9619467B05EDC1097EF587 /* thumbnails_show_tabs_as_windows_light@2x.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 1C961F5740647DBFA0540789 /* thumbnails_show_tabs_as_windows_light@2x.jpg */; };
|
||||
@@ -357,6 +358,7 @@
|
||||
1C961A0A3EF637793B0F9B89 /* thumbnails_align_thumbnails_leading_light@2x.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "thumbnails_align_thumbnails_leading_light@2x.jpg"; sourceTree = "<group>"; };
|
||||
1C961A9B3F8ABA1ECFDF7C9F /* app_icons_hide_preview_focused_window_light@2x.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "app_icons_hide_preview_focused_window_light@2x.jpg"; sourceTree = "<group>"; };
|
||||
1C961AC3633CD0C62CCE050E /* Appearance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Appearance.swift; sourceTree = "<group>"; };
|
||||
AA0C8B000000000000000002 /* UsageStats.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UsageStats.swift; sourceTree = "<group>"; };
|
||||
1C961AD30050B3BAC2A8EDD4 /* swiftformat.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = swiftformat.js; sourceTree = "<group>"; };
|
||||
1C961B08E0A6C1F3C2669A58 /* thumbnails_hide_windowless_apps_light@2x.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "thumbnails_hide_windowless_apps_light@2x.jpg"; sourceTree = "<group>"; };
|
||||
1C961B26B70C826BBD762AC5 /* titles_light@2x.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "titles_light@2x.jpg"; sourceTree = "<group>"; };
|
||||
@@ -1437,6 +1439,7 @@
|
||||
BF0C8F58B38F29B2662E6C2D /* PreferencesMigrations.swift */,
|
||||
BF0C8A1E7D3F94B6E8C52A01 /* Throttler.swift */,
|
||||
AA0C8A000000000000000001 /* AXCallScheduler.swift */,
|
||||
AA0C8B000000000000000002 /* UsageStats.swift */,
|
||||
);
|
||||
path = logic;
|
||||
sourceTree = "<group>";
|
||||
@@ -2627,6 +2630,7 @@
|
||||
BF0C832C5BF4C8E9C95F7767 /* MissionControl.swift in Sources */,
|
||||
1C96108A0CB2565233FE100B /* TableGroupView.swift in Sources */,
|
||||
1C9618872DD3863A8EFE8414 /* Appearance.swift in Sources */,
|
||||
AA0C8B000000000000000001 /* UsageStats.swift in Sources */,
|
||||
BF0C83578F7292F307E30751 /* PopupButtonLikeSystemSettings.swift in Sources */,
|
||||
5F04852E2F09AC9700235D4A /* WindowCaptureEvents.swift in Sources */,
|
||||
1C961F9CF4F1BEDF04ACAEE0 /* Switch.swift in Sources */,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
struct UsageStats {
|
||||
private static let defaults = UserDefaults(suiteName: "\(App.bundleIdentifier).usage")!
|
||||
private static let maxAge: TimeInterval = 365 * 24 * 3600
|
||||
private static let allKeys = ["triggers", "searches", "triggersAppIcons", "triggersTitles", "triggersAutoSize"]
|
||||
private(set) static var searchRecordedThisSession = false
|
||||
|
||||
static func recordTrigger() {
|
||||
record("triggers")
|
||||
if Preferences.appearanceStyle == .appIcons { record("triggersAppIcons") }
|
||||
if Preferences.appearanceStyle == .titles { record("triggersTitles") }
|
||||
if Preferences.appearanceSize == .auto { record("triggersAutoSize") }
|
||||
}
|
||||
|
||||
static func recordSearchIfFirst() {
|
||||
guard !searchRecordedThisSession else { return }
|
||||
searchRecordedThisSession = true
|
||||
record("searches")
|
||||
}
|
||||
|
||||
static func resetSession() {
|
||||
searchRecordedThisSession = false
|
||||
}
|
||||
|
||||
static func count(_ key: String, since date: Date) -> Int {
|
||||
let threshold = Int(date.timeIntervalSince1970)
|
||||
return getTimestamps(key).count { $0 >= threshold }
|
||||
}
|
||||
|
||||
static func prune() {
|
||||
let cutoff = Int(Date().timeIntervalSince1970 - maxAge)
|
||||
for key in allKeys {
|
||||
let timestamps = getTimestamps(key)
|
||||
guard !timestamps.isEmpty else { continue }
|
||||
let pruned = timestamps.filter { $0 >= cutoff }
|
||||
defaults.set(pruned, forKey: key)
|
||||
}
|
||||
}
|
||||
|
||||
private static func record(_ key: String) {
|
||||
var timestamps = getTimestamps(key)
|
||||
timestamps.append(Int(Date().timeIntervalSince1970))
|
||||
defaults.set(timestamps, forKey: key)
|
||||
}
|
||||
|
||||
private static func getTimestamps(_ key: String) -> [Int] {
|
||||
defaults.array(forKey: key) as? [Int] ?? []
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ class App: AppCenterApplication {
|
||||
appIsBeingUsed = false
|
||||
isFirstSummon = true
|
||||
forceDoNothingOnRelease = false
|
||||
UsageStats.resetSession()
|
||||
TilesView.endSearchSession()
|
||||
ContextMenuEvents.toggle(false)
|
||||
CursorEvents.toggle(false)
|
||||
@@ -298,6 +299,7 @@ class App: AppCenterApplication {
|
||||
forceDoNothingOnRelease = forceDoNothingOnRelease_
|
||||
Logger.debug { "isFirstSummon:\(isFirstSummon) shortcutIndex:\(shortcutIndex)" }
|
||||
appIsBeingUsed = true
|
||||
UsageStats.recordTrigger()
|
||||
if isFirstSummon || shortcutIndex != App.shortcutIndex {
|
||||
NSScreen.updatePreferred()
|
||||
if isVeryFirstSummon {
|
||||
@@ -393,6 +395,7 @@ class App: AppCenterApplication {
|
||||
#if DEBUG
|
||||
// App.showSettingsWindow()
|
||||
#endif
|
||||
UsageStats.prune()
|
||||
Logger.info { "Finished launching AltTab" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +158,7 @@ class TilesView {
|
||||
|
||||
private static func updateSearchQuery(_ query: String) {
|
||||
if Windows.searchQuery == query { return }
|
||||
if !query.isEmpty { UsageStats.recordSearchIfFirst() }
|
||||
clearHover()
|
||||
Windows.updateSearchQuery(query)
|
||||
stopKeyRepeatTimers()
|
||||
|
||||
Reference in New Issue
Block a user