Git Product home page Git Product logo

settingsaccess's Introduction

About Me

My name is Steffan Andrews and I hail from beautiful Vancouver, Canada.

I'm a professional composer for film and TV with over 16 years of experience specializing in animated series.

I'm also a life-long coder since 1995. I have helped build numerous commercial Mac applications including Audio Design Desk and Dipper. In my spare time I build and maintain open-source packages for Swift and SwiftUI.

Featured Swift Packages

Modern multi-platform Swift CoreMIDI wrapper with MIDI 2.0 support.
Open Sound Control (OSC) library written in Swift.
A robust and precise Swift library for working with SMPTE timecode.
Translate integers to/from radix strings (binary, hex, etc.) using convenient syntax.

Featured SwiftUI Packages

SwiftUI menu builder DSL & controls that mimic macOS Control Center.
Show/hide SwiftUI MenuBarExtra menu using Bindings.
Open your macOS app's Settings scene programmatically without needing SettingsLink.

settingsaccess's People

Contributors

orchetect avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

settingsaccess's Issues

Settings window can not be open in a space with a fullscreen app

Bug Description, Steps to Reproduce, Crash Logs, Screenshots, etc.

I have developed a small sample app using packages MenuBarExtraAccess (of type .menuBarExtraStyle(.window)) and SettingsAccess. Basically, when clicking the status bar icon a small window appears with a button, that will open a Settings window.

Screenshot 2023-10-23 at 23 43 32

When I run the sample app in the Desktop with apps in non-fullscreen, everything works OK. But if I run the app from a Desktop space being used by an app in fullscreen mode, the main window appears correctly, and when I click the button to open the Settings, the Settings window does NOT appear in the Desktop space of the fullscreen app. It appears SILENTLY in the main Desktop. But the macOS focus keeps in the fullscreen app.

A couple of interesting comments:

  • For displaying the SettingsView, I've tried both ways explained in the description (opening settings programatically, and opening settings using a MenuBarExtra. No luck with any of these options.

  • I've run MacControlCenterUI demo and it shows the same problem.

Possible solutions:

Maybe the Settings window could be open with the window option set to floating. This would open it in the fullscreen Desktop:

window.level = .floating

Or make the Settings window as key. This would still show the Settings window in the main Desktop, but the macOS focus window will be set to it, so macOS will shown immediately the main Desktop with the Settings window in focus:

window.makeKey()

Would any of these solutions mitigate this problem?

doesn't actually work programmatically (but this code does)

Bug Description, Steps to Reproduce, Crash Logs, Screenshots, etc.

hey there, thanks for publishing this. your "programmatic" example is called from the action handler of a Button and i found that without the Button click the same code fails into a trigger of the assertion about "this code shouldn't run on sonoma, file a bug report" (or whatever the verbiage is). i expected programmatic to mean "invokable in the absence of user interaction"

but good news is, with the help of chatgpt, i found a solution that works and am sharing it back here in case you'd like to alter the programmatic invocation :)

func openSettingsInSonoma() {
    NSApp.activate(ignoringOtherApps: true)
    if let event = NSEvent.keyEvent(
        with: .keyDown,
        location: NSPoint(),
        modifierFlags: .command,
        timestamp: 0,
        windowNumber: 0,
        context: nil,
        characters: "",
        charactersIgnoringModifiers: ",",
        isARepeat: false,
        keyCode: 43 // comma
    ) {
        NSApplication.shared.postEvent(event, atStart: false)
    }
}

for any other passersby reading this, if you found this snippet helpful please consider joining me in a prayer: dear god we come to you in a moment of enormous frustration to ask for the special blessing of a pock on the houses of everyone at apple who failed to stop SettingsLink from breaking programmatically opening settings, o lord may you bless us with one thousand generations of those apple engineers' lineages stubbing their toes every day of their lives, each and every one, in the name of all that is holy we offer this humble prayer amen ๐Ÿ™

P.S. it's also possible some apps/users may have re-mapped โŒ˜+, and/or the shortcut for Settings, so in that case a fallback that queries the menu for the shortcut could be a good idea:

func openSettingsInSonoma() {
    if let mainMenu = NSApp.mainMenu {
        for menuItem in mainMenu.items {
            if let submenu = menuItem.submenu {
                if let foundMenuItem = submenu.items
                    .first(where: {
                        $0.title
                            .containsI("settings") /// NB: `.title` is not localized (`.localizedTitle` is) so "settings" is a-ok
                    })
                {
                    let keyEquivalent = foundMenuItem.keyEquivalent
                    let keyEquivalentModifierMask = foundMenuItem
                        .keyEquivalentModifierMask
                    if let event = NSEvent.keyEvent(
                        with: .keyDown,
                        location: NSPoint(),
                        modifierFlags: keyEquivalentModifierMask,
                        timestamp: 0,
                        windowNumber: 0,
                        context: nil,
                        characters: keyEquivalent,
                        charactersIgnoringModifiers: keyEquivalent,
                        isARepeat: false,
                        keyCode: 0
                    ) {
                        NSApplication.shared.postEvent(event, atStart: false)
                        return
                    }
                }
            }
        }
    }
    // assume cmd+,
    if let event = NSEvent.keyEvent(
        with: .keyDown,
        location: NSPoint(),
        modifierFlags: .command,
        timestamp: 0,
        windowNumber: 0,
        context: nil,
        characters: "",
        charactersIgnoringModifiers: ",",
        isARepeat: false,
        keyCode: 43 // comma
    ) {
        NSApplication.shared.postEvent(event, atStart: false)
    }
}

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.