Skip to content

Commit

Permalink
feat: can pass the --logs= flags at launch to show logs
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Nov 10, 2024
1 parent f7de2bb commit 81eb07e
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 131 deletions.
28 changes: 20 additions & 8 deletions alt-tab-macos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
1C96132D9BFCC988B0013509 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 1C961334F059C39979BEDF19 /* [email protected] */; };
1C961383737C00845E881EA6 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 1C9617A90991E963760F7475 /* [email protected] */; };
1C9614261DF293C650675A6C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 1C9619DEB8B7905DBF9A6030 /* [email protected] */; };
1C96143D5AD69C894A4D8375 /* LogManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C96110EB5B28C814DA35465 /* LogManager.swift */; };
1C96143D5AD69C894A4D8375 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C96110EB5B28C814DA35465 /* Logger.swift */; };
1C96149CFE6DB491DCAEA943 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 1C961B26B70C826BBD762AC5 /* [email protected] */; };
1C9614C924F2EEB592314C67 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 1C96127120349FE18C5C39DA /* [email protected] */; };
1C9614D96191FACFACD38055 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 1C9610071E9F3434C893DC95 /* [email protected] */; };
Expand Down Expand Up @@ -74,6 +74,7 @@
5F706EC32BA448D8004D542D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5F706EC12BA448D8004D542D /* InfoPlist.strings */; };
76D02BB22BFE7C9E0056008D /* Pods_alt_tab_macos.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0712B3BEA2B3780398C0999 /* Pods_alt_tab_macos.framework */; };
AA974BA929B7D84C0099A29E /* PreviewPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA974BA829B7D84C0099A29E /* PreviewPanel.swift */; };
BF0C80484AA63306D0DB4DB2 /* SpacesEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8DF008F1EB5F23291A13 /* SpacesEvents.swift */; };
BF0C8052AE41B1B10E42BFCE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C875C983226CB16DBD90F /* InfoPlist.strings */; };
BF0C8053A58DFB383A3E3351 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8E237569FA2A8FE20707 /* InfoPlist.strings */; };
BF0C807D26E465F467B066F7 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C849EBA5A547912BD8BB9 /* Localizable.strings */; };
Expand All @@ -84,6 +85,7 @@
BF0C81A79128CF877FE895CC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8A48BBB3BF649864DB08 /* InfoPlist.strings */; };
BF0C81B64A1205F066AC796A /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C80404D3455D496C02F29 /* Localizable.strings */; };
BF0C81D836A8A4CA393B135F /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C82E55127D38ABF969CA0 /* InfoPlist.strings */; };
BF0C8203D0EFEDEED0F908E8 /* ScreensEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C822D3BEDAB1F1C9F775E /* ScreensEvents.swift */; };
BF0C820C6E89C2D90FA30A4B /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8F67ABD271F26FA0EDEF /* Localizable.strings */; };
BF0C8224CFD1ED511F3F0063 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8D94228D90FE99D4A3C8 /* Localizable.strings */; };
BF0C823630E3DEAC576FAFE6 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = BF0C88BF67CF4D71002A60EB /* [email protected] */; };
Expand Down Expand Up @@ -120,6 +122,7 @@
BF0C898511686611E4D7D81E /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8B2C057099EDABE46779 /* Button.swift */; };
BF0C89C49CFBAAB4646BB8CB /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C82A8848224E76B880A83 /* InfoPlist.strings */; };
BF0C89F0632E0A2EC52D9168 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C87749F1A64E2D3305181 /* InfoPlist.strings */; };
BF0C8A3F32B2177AF407DC7E /* DockEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C870C14C20C936BA4AF40 /* DockEvents.swift */; };
BF0C8A739A74695E60F16369 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8062E78677398A4A217B /* InfoPlist.strings */; };
BF0C8A95AAD9DADC95887A2D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C895A9AF79A869EE6B108 /* Localizable.strings */; };
BF0C8AC57CE5E9BBEEE2442A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C885D34CDCE2AFC5A94F7 /* InfoPlist.strings */; };
Expand Down Expand Up @@ -160,7 +163,7 @@
D04BA15A1B0C4871EA7CB899 /* GeneralTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04BACE22DC907F03D193075 /* GeneralTab.swift */; };
D04BA1621718FF26F8D5E75D /* CustomRecorderControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04BAE333F7170E87C5AC0EF /* CustomRecorderControl.swift */; };
D04BA1637E125D38546C26E2 /* StackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04BA8AC77465E1B2BC947CF /* StackView.swift */; };
D04BA1766FBCB2E941D081A5 /* WorkspaceEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04BA76AEE37D6656EB80126 /* WorkspaceEvents.swift */; };
D04BA1766FBCB2E941D081A5 /* RunningApplicationsEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04BA76AEE37D6656EB80126 /* RunningApplicationsEvents.swift */; };
D04BA1B133D53572D7B312C2 /* ThumbnailFontIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04BA1DF8CAB2FAB7FE9244B /* ThumbnailFontIconView.swift */; };
D04BA1C85041FB043FD43E65 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D04BA05006D56C7AA011C0CE /* Localizable.strings */; };
D04BA1CEC6B9C8945FEC8740 /* ThumbnailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04BA258B56193958D60978A /* ThumbnailView.swift */; };
Expand Down Expand Up @@ -254,7 +257,7 @@
1C961093FB75180759EC6972 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "[email protected]"; sourceTree = "<group>"; };
1C9610B2E76F1E429C8D3660 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "[email protected]"; sourceTree = "<group>"; };
1C9611039BDBE0C84F349BA1 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "[email protected]"; sourceTree = "<group>"; };
1C96110EB5B28C814DA35465 /* LogManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogManager.swift; sourceTree = "<group>"; };
1C96110EB5B28C814DA35465 /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
1C96112432E87D36F90AFBED /* translate_i18n_tools.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = translate_i18n_tools.py; sourceTree = "<group>"; };
1C9611334B667767A4514B57 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "[email protected]"; sourceTree = "<group>"; };
1C961139B16ADE6E0B8A33A6 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "[email protected]"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -333,6 +336,7 @@
BF0C816F38751995E4F49BB0 /* he */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = he; path = InfoPlist.strings; sourceTree = "<group>"; };
BF0C817E063D1405392D6C5B /* he */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = he; path = Localizable.strings; sourceTree = "<group>"; };
BF0C81D602ED642A48D50B78 /* notarytool */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = notarytool; sourceTree = "<group>"; };
BF0C822D3BEDAB1F1C9F775E /* ScreensEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScreensEvents.swift; sourceTree = "<group>"; };
BF0C828AF7BCC4F47E70B28F /* menubar-2.svg */ = {isa = PBXFileReference; lastKnownFileType = file.svg; path = "menubar-2.svg"; sourceTree = "<group>"; };
BF0C82C381FCBCF8109735AC /* pl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = pl; path = InfoPlist.strings; sourceTree = "<group>"; };
BF0C82D44C2DFAA5D8F60394 /* sq */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = sq; path = Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -360,6 +364,7 @@
BF0C864F182B6155A66D241D /* KeyRepeatTimer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyRepeatTimer.swift; sourceTree = "<group>"; };
BF0C86C2BB70A8E05D2103CA /* cs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = cs; path = Localizable.strings; sourceTree = "<group>"; };
BF0C86E06A44AC151FEA4903 /* sv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = sv; path = InfoPlist.strings; sourceTree = "<group>"; };
BF0C870C14C20C936BA4AF40 /* DockEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DockEvents.swift; sourceTree = "<group>"; };
BF0C87320241EAE01E38EF53 /* .periphery.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.yaml; path = .periphery.yml; sourceTree = "<group>"; };
BF0C87897C24638DDE4A9889 /* app-icons-style.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "app-icons-style.jpg"; sourceTree = "<group>"; };
BF0C87B913292EE53EDE4220 /* menubar-1.svg */ = {isa = PBXFileReference; lastKnownFileType = file.svg; path = "menubar-1.svg"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -411,6 +416,7 @@
BF0C8D7DE89E594FEE6DA692 /* ta */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = ta; path = Localizable.strings; sourceTree = "<group>"; };
BF0C8D87C20B7308B16498B6 /* et */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = et; path = InfoPlist.strings; sourceTree = "<group>"; };
BF0C8D9E024876AD9A92BE8D /* sr */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = sr; path = Localizable.strings; sourceTree = "<group>"; };
BF0C8DF008F1EB5F23291A13 /* SpacesEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpacesEvents.swift; sourceTree = "<group>"; };
BF0C8DF400A1AF64EB0CD0B3 /* TrafficLightButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrafficLightButton.swift; sourceTree = "<group>"; };
BF0C8E1FBCBC7B64C69D933C /* titles-style-full.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "titles-style-full.jpg"; sourceTree = "<group>"; };
BF0C8E25373671B528AD448D /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -509,7 +515,7 @@
D04BA72AC9B57A1673C28B2E /* android-chrome-256x256.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "android-chrome-256x256.png"; sourceTree = "<group>"; };
D04BA7457E30F608E139B695 /* zh-TW */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = "zh-TW"; path = Localizable.strings; sourceTree = "<group>"; };
D04BA765138B5E1C512245BE /* Thanks.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = Thanks.md; sourceTree = "<group>"; };
D04BA76AEE37D6656EB80126 /* WorkspaceEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WorkspaceEvents.swift; sourceTree = "<group>"; };
D04BA76AEE37D6656EB80126 /* RunningApplicationsEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RunningApplicationsEvents.swift; sourceTree = "<group>"; };
D04BA788228BA86D9EFBD1ED /* AcknowledgmentsTab.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AcknowledgmentsTab.swift; sourceTree = "<group>"; };
D04BA7957E5E02FB09BCE10C /* de */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = de; path = InfoPlist.strings; sourceTree = "<group>"; };
D04BA7A758026814667273DC /* convert_iconset_to_icns.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = convert_iconset_to_icns.sh; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1171,7 +1177,7 @@
D04BA1C271F0DA573345B860 /* permission-window */,
D04BAAF79737A0673502FEB5 /* AppCenterApplication.h */,
D04BA48BC82D3060C3A1AB11 /* AppCenterApplication.m */,
1C96110EB5B28C814DA35465 /* LogManager.swift */,
1C96110EB5B28C814DA35465 /* Logger.swift */,
);
path = ui;
sourceTree = "<group>";
Expand Down Expand Up @@ -1643,9 +1649,12 @@
children = (
D04BA8FDCF137D892114F5F3 /* AccessibilityEvents.swift */,
D04BA4A621A8A15660F973C1 /* KeyboardEvents.swift */,
D04BA76AEE37D6656EB80126 /* WorkspaceEvents.swift */,
D04BA76AEE37D6656EB80126 /* RunningApplicationsEvents.swift */,
D04BA5D9B4EBEB9E4333AE39 /* UserDefaultsEvents.swift */,
D04BAF320F4D43F0DDFE063E /* MouseEvents.swift */,
BF0C870C14C20C936BA4AF40 /* DockEvents.swift */,
BF0C8DF008F1EB5F23291A13 /* SpacesEvents.swift */,
BF0C822D3BEDAB1F1C9F775E /* ScreensEvents.swift */,
);
path = events;
sourceTree = "<group>";
Expand Down Expand Up @@ -2102,7 +2111,7 @@
5F21C9E02C6E94240091F72F /* ShortcutsWhenActiveSheet.swift in Sources */,
D04BAE8B16A06A10E2FA94DE /* AccessibilityEvents.swift in Sources */,
D04BAAAF5CFA991D3B078DB8 /* KeyboardEvents.swift in Sources */,
D04BA1766FBCB2E941D081A5 /* WorkspaceEvents.swift in Sources */,
D04BA1766FBCB2E941D081A5 /* RunningApplicationsEvents.swift in Sources */,
D04BA0AE9865276FF8EF5DEB /* UserDefaultsEvents.swift in Sources */,
D04BA4A11F821548EE3C5E95 /* Bash.swift in Sources */,
5F21C9E62C6E94920091F72F /* AnimationsSheet.swift in Sources */,
Expand All @@ -2126,8 +2135,11 @@
BF0C83578F7292F307E30751 /* PopupButtonLikeSystemSettings.swift in Sources */,
1C961F9CF4F1BEDF04ACAEE0 /* Switch.swift in Sources */,
1C96182D2ECA735740ED474E /* ImageTextButtonView.swift in Sources */,
1C96143D5AD69C894A4D8375 /* LogManager.swift in Sources */,
1C96143D5AD69C894A4D8375 /* Logger.swift in Sources */,
BF0C860F1779DDE8C0171EA0 /* WindowlessAppIndicator.swift in Sources */,
BF0C8A3F32B2177AF407DC7E /* DockEvents.swift in Sources */,
BF0C80484AA63306D0DB4DB2 /* SpacesEvents.swift in Sources */,
BF0C8203D0EFEDEED0F908E8 /* ScreensEvents.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 6 additions & 0 deletions alt-tab-macos.xcodeproj/xcshareddata/xcschemes/Debug.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
identifier = "com.apple.dt.IDEFoundation.CurrentLocationScenarioIdentifier"
referenceType = "1">
</LocationScenarioReference>
<CommandLineArguments>
<CommandLineArgument
argument = "--logs=info"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Debug"
Expand Down
27 changes: 0 additions & 27 deletions src/api-wrappers/MissionControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import Foundation

class MissionControl {
private static var state_ = MissionControlState.inactive
private static var axObserver: AXObserver?
private static var axUiElement: AXUIElement?

static func state() -> MissionControlState {
if #available(macOS 12.0, *) {
Expand Down Expand Up @@ -32,29 +30,4 @@ class MissionControl {
}
return false
}

static func observe(_ dockPid: pid_t) {
if #available(macOS 12.0, *) {
axUiElement = AXUIElementCreateApplication(dockPid)
AXObserverCreate(dockPid, axObserverCallbackDock, &axObserver)
// are we sure we always get a non-nil axObserver?
for notification in MissionControlState.allCases {
retryAxCallUntilTimeout {
try axUiElement!.subscribeToNotification(axObserver!, notification.rawValue, nil)
}
}
CFRunLoopAddSource(BackgroundWork.missionControlThread.runLoop, AXObserverGetRunLoopSource(axObserver!), .defaultMode)
} else {
// we could handle macOS < 12 here like yabai does. However, they poll with ax calls until they notice Mission Control stops
// this takes up ressources when Mission Control is open. If the user keeps it open for a few hours, this would accelerate battery usage
// SLSRegisterConnectionNotifyProc(g_connection, connection_handler, 1204, NULL);
// then listen every 0.1f * NSEC_PER_SEC for layer == 18 and owner = "Dock"
// when found, mission control is not active anymore
}
}
}

fileprivate let axObserverCallbackDock: AXObserverCallback = { _, element, notificationName, _ in
logger.d(notificationName, element)
MissionControl.setState(MissionControlState(rawValue: notificationName as String)!)
}
4 changes: 2 additions & 2 deletions src/logic/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Application: NSObject {
}

deinit {
logger.i("Deinit app", runningApplication.bundleIdentifier ?? runningApplication.bundleURL ?? "nil")
logger.d("Deinit app", runningApplication.bundleIdentifier ?? runningApplication.bundleURL ?? "nil")
}

override var description: String {
Expand Down Expand Up @@ -73,7 +73,7 @@ class Application: NSObject {
if runningApplication.activationPolicy != .prohibited && axUiElement == nil {
axUiElement = AXUIElementCreateApplication(pid)
AXObserverCreate(pid, axObserverCallback, &axObserver)
logger.i("Adding app", pid ?? "nil", runningApplication.bundleIdentifier ?? "nil")
logger.d("Adding app", pid ?? "nil", runningApplication.bundleIdentifier ?? "nil")
observeEvents()
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/logic/Applications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Applications {
static func initialDiscovery() {
addInitialRunningApplications()
addInitialRunningApplicationsWindows()
WorkspaceEvents.observeRunningApplications()
RunningApplicationsEvents.observe()
}

static func addInitialRunningApplications() {
Expand All @@ -48,7 +48,7 @@ class Applications {
static func addRunningApplications(_ runningApps: [NSRunningApplication]) {
runningApps.forEach {
if $0.bundleIdentifier == "com.apple.dock" {
MissionControl.observe($0.processIdentifier)
DockEvents.observe($0.processIdentifier)
}
if isActualApplication($0) {
Applications.list.append(Application($0))
Expand All @@ -68,7 +68,7 @@ class Applications {
}
Windows.list.removeAll { $0.application.runningApplication.isEqual(runningApp) }
}
guard Windows.list.count > 0 else { App.app.hideUi(); return }
if Windows.list.count == 0 { App.app.hideUi(); return }
if windowsOnTheLeftOfFocusedWindow > 0 {
Windows.cycleFocusedWindowIndex(-windowsOnTheLeftOfFocusedWindow)
}
Expand Down
Loading

0 comments on commit 81eb07e

Please sign in to comment.