TT-ReBORN / Georgia-ReBORN

A Clean · Full Dynamic Color Reborn · Foobar2000 player
MIT License
525 stars 25 forks source link

Details grid edit #91

Closed regorxxx closed 1 year ago

regorxxx commented 1 year ago

Ok, as said, it was easy. Now I have 2 questions, don't want to investigate all files until I get it right spending hours (for me learning the internals, and then you testing it).

  1. How to force the panel to use new settings? After editing "metagrid" variable, the panel gets updated some seconds later, so I used a callback.
    // I have used the new track callback
    // But have to test it when no tracks are being played or nowPlaying returns gargabe
    // Is there any other routine?
    on_playback_new_track(fb.GetNowPlaying());
  2. To save the values to the file? I see at gr-menu line 2489. Is that the right routine to save them?
themeConfigMenu.addItem('Save settings to config file', false, () => {
...
setThemeSettings(true) // And that's it?
});

image themet

regorxxx commented 1 year ago

Once I get the basics, we can go fancy with a popup showing the current rows and asking which row to edit, etc.

TT-ReBORN commented 1 year ago
  1. It's in gr-callbacks.js -> metadata grid will be rebuild from function on_metadb_changed(handle_list, fromhook) {

        str.grid = [];
        for (let k = 0; k < metadataGrid.length; k++) {
            let val = $(metadataGrid[k].val);
            if (val && metadataGrid[k].label) {
                if (metadataGrid[k].age) {
                    val = $('$date(' + val + ')'); // Never show time
                    const age = calcAgeDateString(val);
                    if (age) {
                        val += ` (${age})`;
                    }
                }
                str.grid.push({
                    age: metadataGrid[k].age,
                    label: metadataGrid[k].label,
                    val
                });
            }
        }

And there is also a function clearUIVariables() { which clears all, used for example on_playback_stop or in initMain()

  1. No but you were right on track, the setThemeSettings() function is to save ( with parameter true ) or load ( with no parameter ) all current using SMP panel properties to the config file BUT NOT ALL are linked to the config file. If you open the config file ( georgia-reborn-config.jsonc ) each section has a NOTE: in the comment header that starts with: // * Note: These settings will Almost all settings are saved but some not: "title_format_strings": { "themeStyleCustom": { "themeCustomFont": { "metadataGrid": [ "settings": { These are not saved and only for manual edits, that means user need to manually open the config file and modify them themselves. All others settings will be saved automatically to the config file via top menu Options > Settings > Theme configuration > Save settings to config file -> setThemeSettings(true)

The configuration file is defined via gr-configuration.js with settings from gr-defaults.js ( const defaultMetadataGrid = [ ) and gr-settings.js ( Line 1180 ).

There is also this in gr-settings: config.addConfigurationObject(gridSchema, prefs.metadataGrid); // Can't Object.assign here to add new fields. Add new fields in the upgrade section of migrateCheck

function migrateCheck(version, storedVersion) {
    /**
     * Adds or Replaces value in the grid with updated string from defaults
     * @param {MetadataGridEntry[]} grid
     * @param {string} label Label of the value to add or replace
     * @param {number} position 0-based index of place to insert new value if existing entry not found
     */
    const replaceGridEntry = (grid, label, position) => {
        const entryIdx = grid.findIndex(gridEntry => gridEntry && gridEntry.label.toLowerCase() === label.toLowerCase());
        const newVal = defaultMetadataGrid[defaultMetadataGrid.findIndex(e => e && e.label.toLowerCase() === label.toLowerCase())];
        if (entryIdx >= 0) {
            grid[entryIdx] = newVal;
        } else {
            grid.splice(position, 0, newVal);
        }
    };

    if (version !== storedVersion) {
        const configFile = config.readConfiguration();
        /** @type {MetadataGridEntry[]} */
        const grid = configFile.metadataGrid;

        // This function clears default values which have changed
        switch (storedVersion) {
            case '2.0.3':
            default:
                break;
        }
    }
    pref.version = currentVersion;  // Always update the version panel property
}

That would be it. Mordred is using the migrateCheck function for updates, that means when he releases a new update on Github it will be triggered and it should update also the config file. When a new version is released, there will be a hyperlink in the lowerbar. This will link to the releases page on Github. Never tried it myself because I don't have the public release yet on Github ;)

I have stripped it down, but original it looks like this: https://github.com/kbuffington/Georgia/blob/11d434e6e0882810a5cff7522c395c71557b85a2/js/settings.js#L200

Hope that helps and thanks for your help!

-Tom

regorxxx commented 1 year ago

Uhm... 1) solved. I refactored code.

image So on on_metadb_changed is reused with lp value. image And the same on the menu, not needing to process all again. image

The second took me some time, since I kept using the method without the file reflecting the changes XD (and no error being thrown). Not sure why Mordred did not add an update method for arrays anyway.

So fixed that... just in case this is not the last time another array config gets the same treatment. gr-configuration.js image And throws a popup in case you fuck up mixing config value types. image

details_grid_02_11_2022.zip

TT-ReBORN commented 1 year ago

Good work and thanks @regorxxx, tried it out and it works as it should =) Sorry I didn't warn you about how the configuration system works ;)

But we should add a guard if the user types invalid stuff ( delete all and type random stuff in the input ) in the pattern:

Error: Spider Monkey Panel v1.6.2-dev+7c0928bf ({04620F16-1878-47A1-8EFE-0CE0B99566CC}: Georgia-ReBORN v2.3.0 by TT)
newVal.filter is not a function

File: gr-menu.js
Line: 1797, Column: 34
Stack trace:
  detailsOptions/<@gr-menu.js:1797:34
  doCallback@gr-helpers.js:1537:23
  onOptionsMenu@gr-menu.js:87:7
  append_albumCover_context_menu_to/<@Control_ContextMenu.js:565:7
  execute_menu@Control_ContextMenu.js:285:8
  execute_menu@Control_ContextMenu.js:199:17
  execute@Control_ContextMenu.js:419:15
  on_mouse_rbtn_up@gr-callbacks.js:2679:9

I'm refactoring the top menu button code atm, because otherwise other devs would lose their mind how frustrating that shit is ;)

-Tom

regorxxx commented 1 year ago

My bad, obviously try/catch parsing to JSON is not enough, will add more checks and polisishing. Was just for you to test it.

TT-ReBORN commented 1 year ago

Yep I know, just wanted to let you know :)

regorxxx commented 1 year ago

details_grid_04_11_2022.zip

So there it is. Unless I missed something, you have to try to break it on purpose, but the same can be done with the config file so...

TT-ReBORN commented 1 year ago

Thanks, tested and it's working!

TT-ReBORN commented 1 year ago

@regorxxx,

uploaded WIP Beta 10c for us, contains all your additions. Only some small name changes, linted your code and refactored a one liner so ESLint doesn't complain... You should just replace all your javascript files because there were more changes I needed to do when refactored the top menu code...

Also check latest changelog in the zip file for more information.

I think I'm gonna switch to ESLyric and put the Lyric Show 3 Panel to rest, here is the same with ESLyric: Here is the zip.

-Tom

regorxxx commented 1 year ago

Why don't you use foo_openlyrics Lyrics? (just curiosity) https://github.com/jacquesh/foo_openlyrics

fwn0 commented 1 year ago

See this here: https://github.com/jacquesh/foo_openlyrics/issues/177

TT-ReBORN commented 1 year ago

@regorxxx, just released Beta 10c, wanted to let you know we will postpone this for Beta 10d and write it then in the changelog and make it official.

TT-ReBORN commented 1 year ago

Will be available in Beta 11, I've implemented a custom menu for the metadata grid and one other surprise.