[ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Find out what's going on with LiveCode (the company), product releases, announcements, and events.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

[ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by PaulDaMacMan » Mon Aug 09, 2021 7:00 pm

I've just pushed a small update to my macOS Tools LiveCode Builder library, which, if you don't know, is a small library of handlers for macOS specific things, mostly related to AppKit. The idea is that this library should contain mac specific things, stuff that LC has not implemented, that can make your LiveCode macOS apps behave more like native macOS apps.
Update v. 1.0.1 adds two handlers that provide the ability to change the system appearance of a LiveCode window, passed by windowID, to the macOS dark or light appearance style. Use at this at your own risk, although I will say in my limited testing it seems to work just fine here (on macOS 10.14.6).

Screen Shot 2021-08-09 at 1.49.40 PM.png
NOTE:
LiveCode does have some official support for systemAppearance mode changes, but it is currently still very limited and consists of:
on systemAppearanceChanged is a message that is supposed to be sent to the defaultStack when the user changes the macOS system settings to dark or light modes, however this doesn't work for me in the LC IDE (bug?), although it does get triggered if the stack is running as standalone app.
get the systemAppearance seems to work fine for me, returns "light" or "dark"


GitHub project page here:
https://github.com/PaulMcClernan/LCB_ma ... ree/master
Last edited by PaulDaMacMan on Tue Aug 10, 2021 2:01 pm, edited 1 time in total.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by PaulDaMacMan » Mon Aug 09, 2021 11:31 pm

Just out of curiosity I decided to see what it looks like if the dark appearance was applied to all of LiveCode (by setting the appearance property on LiveCode's NSApplication object, which all of the app windows should inherit from), here is a screenshot for anyone else who may be curious:
Screen Shot 2021-08-09 at 6.19.39 PM.jpg
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by PaulDaMacMan » Mon Aug 09, 2021 11:46 pm

I've now tested on macOS 10.15.7 Catalina, it works fine there.

Also tested probable bug in LC IDE with on systemAppearanceChanged messages on 10.15.7, the card of the test stack does receive the systemAppearanceChanged message, but only once (something not retained or reset?), then when user switches the macOS Appearance again no further systemAppearanceChanged messages are received. Again this is only in the IDE, it is being triggered properly in my test standalone app. Has anyone else made use of this message handler?
Last edited by PaulDaMacMan on Wed Aug 11, 2021 12:24 pm, edited 2 times in total.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by stam » Tue Aug 10, 2021 12:44 am

Amazing tool, thank you Paul!
Sadly my real-life uses mean i have to ensure windows and mac offerings but when time allows i'll look at putting this into good use on the mac side!

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by PaulDaMacMan » Tue Aug 10, 2021 1:27 am

stam wrote:
Tue Aug 10, 2021 12:44 am
Amazing tool, thank you Paul!
Sadly my real-life uses mean i have to ensure windows and mac offerings but when time allows i'll look at putting this into good use on the mac side!
Thanks and you're welcome.
Dark Mode has been a part of macOS since like 7 major versions ago (first started to appear in 10.9 I beleive), I know they're stretched but I'm surprised LiveCode's support for it is still so minimal (or maybe even not-functional, at least in the IDE)... I mean it took me just a couple of hours on a whim this morning to get working LCB darkMode handlers.

There's no reason you can't use these with the Mac version of your offerings to give them a bit more 'native' (mostly cosmetic) features.
Once loaded into memory or installed in the IDE, the lib is really easy to use, there's not a lot to it so far.
Here's the script in the darkMode button of the demo stack:

Code: Select all

on mouseUp pMouseButton
   lock screen
    -- TIP: If you wrap LCB handlers in a try/end try structure then the LC Script Engine will ignore the error on 
    --        non-Apple platforms or if the LCB lib/widget is missing or otherwise not loaded. 
   try
  	 setWindowToDarkMode the windowID of this stack -- <-- the only LCB based handler in this script
   end try
   set the backColor of this stack to "gray 15"
   set the backColor of this card to "gray 15"
   set the foreColor of this stack to "white"
   set the foreColor of this card to "white"
   unlock screen
end mouseUp
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by Klaus » Fri Apr 01, 2022 4:39 pm

Hi Paul,

just tested light/dark mode and first time I clicked "Dark mode" in your example stack, LC crashed. :D
Second time I only got an error:
button "DarkMode": execution error at line 4 (LCB Error in file macOStools.lcb at line 406: -[NSTaggedPointerString charValue]: unrecognized selector sent to instance 0x1)
Setting "light mode" works as expected.

And "Answer" dialog opens behind your example stack. Ah, it is set to "systemwindow", so it is probably correct, isn't it?

But "frontmoste application" returns: 4497,com.runrev.livecode,/Applications/Livecode/LiveCode 10.0.0 (dp 3).app
But that is not running, it should read LC 9.6.7.

macOS 12.3.1, LC 9.6.7


Best

Klaus

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by PaulDaMacMan » Mon Apr 04, 2022 4:40 pm

Klaus wrote:
Fri Apr 01, 2022 4:39 pm
Hi Paul,

just tested light/dark mode and first time I clicked "Dark mode" in your example stack, LC crashed. :D
Second time I only got an error:
button "DarkMode": execution error at line 4 (LCB Error in file macOStools.lcb at line 406: -[NSTaggedPointerString charValue]: unrecognized selector sent to instance 0x1)
Setting "light mode" works as expected.

And "Answer" dialog opens behind your example stack. Ah, it is set to "systemwindow", so it is probably correct, isn't it?

But "frontmoste application" returns: 4497,com.runrev.livecode,/Applications/Livecode/LiveCode 10.0.0 (dp 3).app
But that is not running, it should read LC 9.6.7.

macOS 12.3.1, LC 9.6.7


Best

Klaus
Hi Klaus, Thanks for the feedback and testing!
NOTE: I have not tested this beyond BigSur with LCC v9.6.3.
Maybe the name of the "Dark" or "Vibrant Dark" mode selector in macOS Monterey changed?
I doubt anything in LC 9.6.4 to *.7 would've broken it?
I'll be sure to look into this, but I'm not running Monterey on any of my boxes just yet, so that will have to change first (along with some drive repartitioning changes) and just so you know I may not be testing with LC >= 9.6.4 anytime soon either.
Are you using the version here? https://github.com/PaulMcClernan/OpenXT ... -App-Tools
ALSO NOTE: This macTools (renamed 'macOS-Native-App-Tools' ) wrapper lib is licensed as GPLv3, so keep that in mind if using it.
But it's just wrapping for Cocoa APIs so you could always roll your own :wink: .
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by Klaus » Mon Apr 04, 2022 7:13 pm

Hi Paul,
Are you using the version here? https://github.com/PaulMcClernan/OpenXT ... -App-Tools
yes, will keep GPLv3 in mind, after I have looked up on the net what that means for my freeware.
I hardly understand all the fineprint if it is written in german. 8-)

Just send me a copy of a new version or drop a line and I will be happy to test it with LC >= 9.6.7!
Thank you very much!


Best

Klaus

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by PaulDaMacMan » Mon Apr 04, 2022 11:54 pm

Klaus wrote:
Mon Apr 04, 2022 7:13 pm
Hi Paul,
Are you using the version here? https://github.com/PaulMcClernan/OpenXT ... -App-Tools
yes, will keep GPLv3 in mind, after I have looked up on the net what that means for my freeware.
I hardly understand all the fineprint if it is written in german. 8-)

Just send me a copy of a new version or drop a line and I will be happy to test it with LC >= 9.6.7!
Thank you very much!


Best

Klaus
Freeware + GPLv3 = all good, just post your .lcb code somewhere people can get it if you make any changes.
I will likely take you up on that offer to test once I figure out what the problem is.
It may be an entitlement issue, 9.6.x is built against the now very old macOS 10.9 SDK, so it may be that it needs to have:
NSRequiresAquaSystemAppearance : false key/value pair added to the IDE/App's Info.plist
in order to enable DarkMode support on macOS 12.x+? (I'm just making guesses right now, DarkMode works OK for me in macOS 11.6)
Reference: https://developer.apple.com/documentati ... _macos_app

It looks like LC 10 is still being built against 10.9 SDK!? But maybe the release docs info has not been updated yet?
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by Klaus » Tue Apr 05, 2022 8:21 am

Hi Paul,
PaulDaMacMan wrote:
Mon Apr 04, 2022 11:54 pm
Freeware + GPLv3 = all good, just post your .lcb code somewhere people can get it if you make any changes.
My .lcb code? You mean your .lcb code? I could add a link to your github page.
Sorry, now I'm cofused a lot. :D
PaulDaMacMan wrote:
Mon Apr 04, 2022 11:54 pm
It looks like LC 10 is still being built against 10.9 SDK!? But maybe the release docs info has not been updated yet?
No idea, sorry, but thank a bunch for taking a look at your extension!


Best

Klaus

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by PaulDaMacMan » Wed Apr 06, 2022 12:41 pm

Klaus wrote:
Tue Apr 05, 2022 8:21 am
Hi Paul,
PaulDaMacMan wrote:
Mon Apr 04, 2022 11:54 pm
Freeware + GPLv3 = all good, just post your .lcb code somewhere people can get it if you make any changes.
My .lcb code? You mean your .lcb code? I could add a link to your github page.
Sorry, now I'm cofused a lot. :D
PaulDaMacMan wrote:
Mon Apr 04, 2022 11:54 pm
It looks like LC 10 is still being built against 10.9 SDK!? But maybe the release docs info has not been updated yet?
No idea, sorry, but thank a bunch for taking a look at your extension!


Best

Klaus
Sorry for the confusion. I meant to imply that you or anybody else could just change the handler names and some of the code and then it would be like an original work. I mean there's really only one correct way to create the binding strings for an API so that can't be a factor in determining originality. Does that makes sense?
Last edited by PaulDaMacMan on Tue Apr 26, 2022 8:54 pm, edited 1 time in total.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by Klaus » Wed Apr 06, 2022 12:56 pm

Yes, a bit. ;-)

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by PaulDaMacMan » Fri May 06, 2022 2:20 pm

Klaus wrote:
Fri Apr 01, 2022 4:39 pm
Hi Paul,

just tested light/dark mode and first time I clicked "Dark mode" in your example stack, LC crashed. :D
Second time I only got an error:
button "DarkMode": execution error at line 4 (LCB Error in file macOStools.lcb at line 406: -[NSTaggedPointerString charValue]: unrecognized selector sent to instance 0x1)
Setting "light mode" works as expected.

And "Answer" dialog opens behind your example stack. Ah, it is set to "systemwindow", so it is probably correct, isn't it?

But "frontmoste application" returns: 4497,com.runrev.livecode,/Applications/Livecode/LiveCode 10.0.0 (dp 3).app
But that is not running, it should read LC 9.6.7.

macOS 12.3.1, LC 9.6.7


Best

Klaus
I'm not sure if there is something different on your end, but I finally got around to installing macOS 12 on my iMac and the dark mode handlers seem to be working fine with LCC 9.6.3 Engine on my end. See screenshot (which has a few additional IDE mods for better darkMode).
Maybe you're using an older version of the library? Or maybe the demo stack is outdated, I've changed the name of the handler setLCtoDarkMode at least twice, setAllToDarkMode or setAppToDarkMode, which is the handler that sets a dark appearance (there's Regular Dark or Vibrant Dark) on the NSApp object so that all of an App's windows will inherit that appearance by default.
Screen Shot 2022-05-06 at 8.43.07 AM.jpg

Not sure what that comment about "Answer dialog" being a systemWIndow is about?

What exactly is reporting "frontmost application" as: 4497,com.runrev.livecode,/Applications/Livecode/LiveCode 10.0.0 (dp 3).app, GetFrontmostApplication() ? The library has nothing to do with how that is reported. What is happening is that the window is being identified by the OS by resolving that reverse DNS identifier (com.runrev.livecode), and the OS is reporting the newest version for that identifier that is installed on your system (LiveCode 10.0.0 (dp 3). My modded IDE just returned: 1435,org.openxtalk,/Volumes/iMac2 HD/Users/paulmcclernan/Desktop/OpenXTalk 1.963.1rc1.app
So not exactly a bug, or rather it's not MY bug but Apple's... or its a feature. I should at least add a note that this value is coming from a macOS API's evaluation of the ID, and might NOT be the same as the (older) version that is actually running.

If you try GetRunningApplications() you will see that some apps do not have an associated app bundle (such as the case with background app processes), but they all have an identifier such as: com.apple.print.daemon.printtool

Maybe I should rename these two handlers to something a little more clear about the distiction, such as getRunningProcesses and getFrontmostProcess ?

Thanks again for testing!
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by Klaus » Fri May 06, 2022 4:59 pm

Hi Paul,

you're welcome!

But still no dice! :-(

I downsloaded all the stuff from here:
https://github.com/PaulMcClernan/OpenXT ... ree/master
Then I installed: org.openxtalk.library.macosnativeapptools.1.0.1.lce via the "Extension manager".
NO older version was installed!
Restarted LC and opened your "MacOS-Native-Tools-Tester.rev", which opened in "dark mode" (? at least it was black).
Clicked the "dark mode" button and LC crashed, tried three times, same result LC crshed.
I can supply the crash log if that helps.

Restarted LC and I opened your "DarkModeTests.livecode" stack.
Went to the macOS settings and switched to "Dark" and voila, that namely stack went black, switched bak to "Bright", but the stack stayed black!?

When using: setLCtoDarkMode the windowsID of this stack, I get the error: Handler not found
MacOS 12.3.1, LC 9.6.7

Hmm...


Best

Klaus

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: [ANN] macOSTools LCB Lib v.1.0.1 Native Dark Mode

Post by Klaus » Fri May 06, 2022 5:05 pm

Five minutes later...

OK, changing the stack from "System Window" to "toplevel" cured the crash and "dark mode" works as advertized!? :D
Great, thanks a LOT!

However the window title stays black after setting to "light" again with -> setAppToLightMode
Using "setWindowToLightMode the windowID of this stack" makes if white again.
But this throws an error: IDEToLightMode -> in stack "macOS Tools Tester"

Post Reply

Return to “Announcements”