Plutoberth / SonyHeadphonesClient

A {Windows, macOS, Linux} client recreating the functionality of the Sony Headphones app
MIT License
1.09k stars 85 forks source link

Fix the macOS version for Monterey #68

Closed semvis123 closed 2 years ago

semvis123 commented 2 years ago

This brings back functionality, but it still consumes one full cpu core, so it isn't ready for merging. Closes #62

semvis123 commented 2 years ago

Seems to be working correctly now. image I don't know if this breaks the versions before Monterey.

Plutoberth commented 2 years ago

Did they break the API in Monterey? LGTM anyway, let me know when you want this to be merged (as it's still marked as draft)

semvis123 commented 2 years ago

Did they break the API in Monterey?

Kinda, they changed some threading related behavior I think.

let me know when you want this to be merged

I just tested it on an older macOS version, and it appears to be broken. I guess I could check on which version it is and use the old method on older macOS.

semvis123 commented 2 years ago

Okay, it seems to be working correctly on both macOS versions (High Sierra and Monterey) now.

Plutoberth commented 2 years ago

It's weird to me that such a fundamental thing would break on macOS. I think that it must be that we're doing something wrong, that probably introduces additional bugs. Can we try to find a solution that works on both versions?

semvis123 commented 2 years ago

It's weird to me that such a fundamental thing would break on macOS.

Yeah it's indeed weird, even some Xcode provided bluetooth tools seem to be broken.

Can we try to find a solution that works on both versions?

Yeah I guess that's a good idea, I will setup a High Sierra VM (to make testing a bit faster) and test a few more things.

semvis123 commented 2 years ago

I will setup a High Sierra VM

This didn't work, couldn't get bluetooth working in a macOS VM.

However I did discover a solution that works on both versions, but wakes the cpu every second on Monterey (which should only be needed on High Sierra)

std::unique_lock<std::mutex> lk(macOSBluetoothConnector->disconnectionMutex);
while (macOSBluetoothConnector->running) {
    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:.1]];
    macOSBluetoothConnector->disconnectionConditionVariable.wait_for(lk, std::chrono::milliseconds(1000), [&]() {
        return !macOSBluetoothConnector->running;
    });
}

lk.unlock();

I guess it is a decent solution for both versions.

Plutoberth commented 2 years ago

Not quite sure that I understand the macOS concurrency model, but it sounds like it works this way. Merging :)