I am trying to build a UI for a panel using spectrum-web-components. If using this, the parts must be placed under the sp-theme component or they will not be displayed.
The problem is that sp-theme needs to specify the brightness as an attribute, such as light or dark.
I want to choose the brightness according to the user’s InDesign preferences, but I don’t know how to track changes in the target item app.generalPreferences.uiBrightnessPreference.
I tried monitoring MutationEvent.AFTER_ATTRIBUTE_CHANGED, but there was no response. What is the way to capture changes in uiBrightnessPreference without using IdleTask or setInterval?
As far as I can see, there doesn’t seem to be any direct event that can catch app.generalPreferences.uiBrightnessPreference changes.
As an alternative, I thought of the following: That is, the user must open the “User Interface” in the “Preferences” window to change the app.generalPreferences.uiBrightnessPreference. After changing uiBrightnessPreference, the next operation cannot be performed unless the window is closed. By observing this behavior, you can catch uiBrightnessPreference changes, if not in real time.
The following code is what I checked with ExtendScript. Since it is not UXP, $.sleep() etc. need to be rewritten.
The problem with this approach is that the afterInvoke event fires multiple times between opening and closing the window (without switching the list on the left). I don’t know why.
All but one of them, “flag = app.generalPreferences.uiBrightnessPreference;” fails. I don’t know why either.
#targetengine "getEv"
if (app.eventListeners.itemByName("ev08").isValid) {
app.eventListeners.itemByName("ev08").remove();
}
app.menuActions.itemByID(91232).addEventListener("afterInvoke", evtCheck).name = "ev08";
function evtCheck(ev) {
while (app.modalState) {
$.sleep(200);
}
var flag = -1;
flag = app.generalPreferences.uiBrightnessPreference;
if (flag == -1) return;
alert(flag);
}
I’m interested in this, as well. But I think that Adobe should provide a good way of dealing with this out-of-the-box (in a UXP-cross-app-way) given that UXP now has “official” support for SWC.
The thing is that in cross-app plugins, the UI should be re-usable (for the most part). And with that, <sp-theme> is an integral part of the UI (which really shouldn’t be host-app-specific, although different host apps might “only” offer specific themes – like XD only offering a light theme).
Perhaps UXP could offer a <uxp-sp-theme> that handles this automatically? (definitely not the best idea how this could be implemented, but there should, in my opinion, be some easy solution, whatever that looks like)
The Theme switching process is usually needed even though it is not an essential plugin feature. You are right, it would be nice if special components or custom hooks or something could be provided that feature automatically in any app, if possible.
Thanks for the great sample plugins. It’s simple and easy to understand; the writing of package.json, webpack.config.js, and manifest.json is complex enough, so I like that the other code is minimal.