Git Product home page Git Product logo

Comments (6)

orchetect avatar orchetect commented on September 25, 2024

What macOS version is it?

Have you tried reproducing this in a new macOS app project with vanilla SwiftUI using just a window-based MenuBarExtra and SettingsLink? It would be useful to know if this is a SwiftUI issue or an issue related to the packages.

from settingsaccess.

jfid avatar jfid commented on September 25, 2024

I'm in macOS 14.0, Xcode target set to 14.0.

Yes, a brand new project using SwiftUI, window-based MenuBarExtra and SettingsLink.

It could be a SwiftUI issue. If this is the case, is it still possible to capture the Settings window using NSapp.windows in some part of your package code, and try any of the solutions proposed? Something like:

for window in NSApp.windows {
    if let windowId = window.identifier?.rawValue {
        if windowId.contains("Settings") {
            window.level = .floating  // solution 1
            window.becomeKey()  // solution 2
        }
    }
}

from settingsaccess.

orchetect avatar orchetect commented on September 25, 2024

SettingsAccess is really just designed as a wrapper for Apple's SettingsLink. If there's a quirk or bug with Apple's implementation it's best to report that with a radar of course.

I imagine you could shoehorn that code into the post-action closure of the custom SettingsLink provided by the package. But it's brittle and may not cover all bases. It may be best left to the developer to solve this particular issue in that case.

from settingsaccess.

jfid avatar jfid commented on September 25, 2024

Still fighting with it.

I've tried multiple code alternatives in the post-action closure, but none worked out. I had some partial success, for example I was able to hide the minimise and maximise buttons of the Settings window, but no luck when trying to make it .floating or set the focus calling makeKey() or becomeKey(). No worries, let's forget about this.

Then I came back to the original macControlCenterUI Demo app, and I realised that it does what I wanted. If I open the Settings from a fullscreen desktop, it leaves the fullscreen desktop and opens it in the main desktop setting the focus on it.

But creating a dummy sample project from scratch using both packages and doing same steps as macControlCenterUI Demo app does, I got different results. If I open the Settings from a fullscreen desktop, it doesn't leave the fullscreen desktop and opens it in the main desktop, without setting the focus on it.

Definitively I'm missing something but I can't find it.

import SwiftUI
import MenuBarExtraAccess
import SettingsAccess

@main
struct MenuBarPackagesApp: App {
    @State var isMenuPresented: Bool = false
    
    var body: some Scene {
        Settings {
            SettingsView()
        }

        MenuBarExtra("MyApp Menu", systemImage: "folder") {
            MyMenu(isMenuPresented: $isMenuPresented)
                .openSettingsAccess()
        }
        .menuBarExtraStyle(.window)
        .menuBarExtraAccess(isPresented: $isMenuPresented) { statusItem in
            // access status item or store it in a @State var
        }                
    }
}

struct SettingsView: View {
    var body: some View {
        Text("Hello")
            .frame(width: 300, height: 300)
    }
}

struct MyMenu: View {
    @Environment(\.openSettings) var openSettings
    @Binding var isMenuPresented: Bool

    var body: some View {
        Button("Open settings") {
            isMenuPresented = false
            try? openSettings()
        }
        .frame(width: 200, height: 200)
    }
}

from settingsaccess.

jfid avatar jfid commented on September 25, 2024

Oh man, I found it.

I wasn't setting the Target property "Application is agent (UIElement)"=YES. For some reason that had a weird effect.

Doing that in fact opens the Settings window in the current fullscreen desktop. Whatever, that's good to me!

Let me thank you for your excellent work on these two packages, Steffan.

from settingsaccess.

orchetect avatar orchetect commented on September 25, 2024

Oh good! It's nice to find a simple resolution even if it takes time.

from settingsaccess.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.