kean / Pulse

Network logger for Apple platforms
https://pulselogger.com
MIT License
6.32k stars 302 forks source link

Pulse overrides the app's accent color #207

Closed MrAsterisco closed 1 year ago

MrAsterisco commented 1 year ago

Hello!

I am embedding Pulse into my SwiftUI application via Swift Package Manager. Updating to any version higher than 3.5.7 causes the app accent color to be overridden to the default blue, regardless of what I have set in my Assets catalogue.

I tried to change the Global Accent Color Name build setting in my app target to another name (not the default AccentColor that I was using before) but nothing changes: it seems that Pulse is somehow overriding my color.

With version 3.5.7 everything works normally.

Is this a known issue? How can I work around it? I tried looking for similar issues on the repo but couldn't find any: is this a problem with only SwiftUI apps?

kean commented 1 year ago

Hey, @MrAsterisco. Pulse doesn't make any app-level changes and never accessed the view hierarchy outside of its views, so it seems unlikely it would have such an effect. Can you please provide a sample that reproduces it?

kean commented 1 year ago

Potentially related: in Pulse 4.0.2, the Console view now respects the app's accent color for all its controls. I'm going to assume that's what the issue meant. If not, please feel free to reopen it with more details.

MrAsterisco commented 1 year ago

Hey sorry for not updating the issue: I was taking some time off. After my initial investigation, it seems that, as you said, the problem is caused by my project configuration. Although, it is caused by Pulse, I was not able to reproduce it in a new SwiftUI project.

To recap what I'm seeing:

Thank you anyway for your help. I will try to update to 4.0.2 to see if that fixes the issue, otherwise I'll have to continue investigating where the conflict happens.

kean commented 1 year ago

3.6.0 had around 5K lines of changes. If it's the accent color, it probably has to do with the AccentColor.colorset from the demo projects. Please, make sure you don't include these in your app. The safest bet is to use Swift Package Manager or XCFrameworks to install it. If you find the root cause, please post it to the thread for future references.

MrAsterisco commented 1 year ago

Yes, I looked into it weeks ago, but still couldn't find a reason. It is definitely that, but I don't know why it would be included: I am using SPM.

MrAsterisco commented 5 months ago

Hey folks!

I finally got some time (better late than never, I guess) to investigate this issue. Completely removing any trace of Pulse while still including it as a dependency fixes the issue, which led me to think that there's something that Pulse is doing which SwiftUI doesn't like.

I found this SO Answer which seems to be pointing at Pulse trying to access some application properties before the first window is presented.

I was able to workaround this by setting the tint on the main view of the app, but this causes some weird behaviors in popups: the tint color is presented correctly, but changes back to the default blue while they're being dismissed.

@kean out of curiosity, is there anything that comes to mind that Pulse might be doing that would access colors or similar properties?

MrAsterisco commented 5 months ago

To add even more context, invoking LoggerStore.shared while the app is starting (which I do because I'm appending content to the Pulse log manually through my logging infrastructure, which gets instantiated on app start) triggers the issue.

Delaying the first log to the time the first window is visible does not trigger the issue.

MrAsterisco commented 5 months ago

The same also happens when instantiating the NetworkLogger. So it seems Pulse is doing something statically regardless of which class is instantiated?

kean commented 5 months ago

I wish I could help as I understand it seems pretty frustrating, but there is absolutely nothing that the framework does on the global label and includes no resources.

There is an appearance override in https://github.com/kean/Pulse/blob/32707c62d9ee9ca5f0aefd090781cb0b384c8d62/Sources/PulseUI/Views/PulseUI%2BUIKit.swift#L46, but it's localized to MainViewController and this code doesn't run until you show it. If you are using SwiftUI, it never runs.

MrAsterisco commented 5 months ago

Well... I solved it! Maybe I was doing something wrong on my side and, for whatever reason, Pulse was highlighting my wrong doing... no idea.

In any case, I was instantiating NetworkLogger and LoggerStore as properties of the App instance (indirectly through injected dependencies). Moving them to the main view of the app solved the issue!

The key point was debugging when the NetworkLogger was being initialized: before it was happening in the init function of the App struct, which apparently it's not a good place to initialize Pulse.

Thank you anyway for your help!