I may or may not continue with the System Prefs-style design. If I don't, I'll move to a sidebar layout, something like CleanMyMac but, you know, less pink. Web stuff is my bread and butter so I think I can make a pretty nice settings page reasonably fast!
Is it possible to get the values of a persistent variable in the floating HTML view? I'd like to use it to power classes that change the color of the settings instead of manually swapping out hide and show buttons.
it SHOULD be possible, but I unfortunately think I forgot to route these newer functions to the webview. Will add them tomorrow, so everything that can be used from Apple Script can also be used from Java Script inside the webview.
With v2.672 it will then just work like the other calls:
window.BTT.callHandler('get_persistent_string_variable', {variableName: 'test'},
function callback(currentVariableValue) {
console.log('the variable is set to: ', currentVariableValue);
}
)
Anyway, this is already possible without too much hussle. @Andreas_Hegenberg perhaps you could reconsider adding my btt.js wrapper injected into webview by default? it has dozen of cases already handled, even with custom method for particular actions (and it is documented) That way you would'nt have to maintain window.BTT.* yourself. If you find this idea interesting, this could be made turn-offable via checkbox, just in case.
If any of you guys need a help with any JS related technologies, just mention me - I work with it on daily basis and I'm online often
The main problem with doing that is that it requires the BTT webserver to be activated, which it's not by default (and I feel users should have to do that manually)
Oh, I didn't realize that. That's interesting though - I assumed that window.BTT does that under the hood anyway (I mean, I'm certainly curious how does it work without webserver enabled - some other low level API available to JS within webview ?)
That's some custom code I added which allows to call certain native code directly from JS, without going through any kind of webserver. This only works in the floating HTML view. Maintaining these is usually not a problem, they are just forwarded to the general script-function handler. I just forgot that
Maybe it would be possible to optionally "wrap" these window.BTT.callHandler calls in your library
Yeah that shouldn't be too much hussle - wrapper could just check if window.BTT.callHandler is defined at all, and if it is it can use it and then just fallback to webserver (because the callHandler will work only in BTT invoked webview I suppose)
But I'd need to know what functions are supported etc So If you find this idea useful then we can set it up later, I could help you with building it (though it should be documented enough for you to set it up yourself -> https://worie.github.io/btt/guide/introduction.html)
@Andreas_Hegenberg I'm not super adept at writing my own JS from scratch; how do I actually get this initializing and outputting the value of a variable in context? In my working copy I'm trying to output the esc key style variable, just as a test. I basically just stuck the script you provided in a <script> tag and changed the variable name, no dice, so I'm guessing I'm missing some initialization step or doing something stupid.
This is a good excuse for me to finally get decent at JS
Just FYI Andreas - support for using window.BTT is present in v3.4.0 of the wrapper, if you find it useful. It was really easy to implement thanks to consistencies with webserver API as you mentioned. And it's quite amazing to see such low level functionalities exposed to JS without webserver itself
The only thing that does not work in my wrapper without the webserver is .url of particular action because... Well URL requires a webserver to be visitable But other stuff such as .json or .invoke() or even .chain() should work just fine.
@Andreas_Hegenberg I've been combining a few of my show/hide scripts into single toggle scripts for testing, but using the BTT link doesn't seem to actually do anything when I click it. I also still get an error when using js:
EDIT: Uh, actually none of my triggers seem to be doing anything, even when fired manually. Did they just straight up break in 2.674? I can't even resize the menu bar anymore.
@Worie will try that next, just finished some more styling! I also hooked up all the buttons to their respective trigger actions, which still aren't doing anything...