https://hydrogenaud.io/index.php?topic=120394.msg994849#msg994849
Created the first package for SMP and have some questions about the way it works.
try { //May be loaded along other buttons
window.DefinePanel('Top Tracks Button', {author:'xxx'});
include(fb.ProfilePath + 'scripts\\SMP\\xxx-scripts\\helpers\\buttons_xxx.js');
var g_font = gdi.Font('Segoe UI', 12);
var buttonCoordinates = {x: 0, y: 0, w: 98, h: 22};
var buttonOrientation = 'x';
} catch (e) {
buttonCoordinates = {x: 0, y: 0, w: buttonOrientation == 'x' ? 98 : buttonCoordinates.w , h: buttonOrientation == 'y' ? 22 : buttonCoordinates.h}; // Reset
console.log('Top Tracks Button loaded.');
}
I use that code to check if the button file is being loaded within a button bar or as standalone. The idea is the button bar is loaded first so window.DefinePanel has been already called and therefore "try" thows an error. Works great using standard scripts, but in packages window.DefinePanel and window.DefineScript always throw an error... rendering that method obsolete.
A button bar would simply follow the same structure and include the buttons files.
try { //May be loaded along other buttons
window.DefinePanel('Merged Buttons bar', {author:'xxx'});
include(fb.ProfilePath + 'scripts\\SMP\\xxx-scripts\\helpers\\buttons_xxx.js');
var g_font = gdi.Font('Segoe UI', 12);
var buttonCoordinates = {x: 0, y: 0, w: 98, h: 22};
var buttonOrientation = 'x';
} catch (e) {
buttonCoordinates = {x: 0, y: 0, w: buttonOrientation == 'x' ? 98 : buttonCoordinates.w , h: buttonOrientation == 'y' ? 22 : buttonCoordinates.h}; // Reset
console.log('Merged Buttons loaded.');
}
// Global width - Height overrides
buttonCoordinates.w += 40; // Only works for 'y' orientation
buttonCoordinates.h += 0; //For 'x' orientation
// Global toolbar color
bToolbar = true; // Change this on buttons bars files to set the background color
toolbarColor = RGB(211,218,237);
{ // Buttons
let buttonsPath = [ // Add here your buttons path
fb.ProfilePath + 'scripts\\SMP\\xxx-scripts\\buttons\\buttons_search_same_style.js',
fb.ProfilePath + 'scripts\\SMP\\xxx-scripts\\buttons\\buttons_search_same_style_moods.js',
fb.ProfilePath + 'scripts\\SMP\\xxx-scripts\\buttons\\buttons_search_similar_by.js', //+15 w
fb.ProfilePath + 'scripts\\SMP\\xxx-scripts\\buttons\\buttons_search_top_tracks.js',
fb.ProfilePath + 'scripts\\SMP\\xxx-scripts\\buttons\\buttons_remove_duplicates.js', //+25 w
fb.ProfilePath + 'scripts\\SMP\\xxx-scripts\\buttons\\buttons_search_bydistance.js',
fb.ProfilePath + 'scripts\\SMP\\xxx-scripts\\buttons\\buttons_tags_automation.js',
];
for (let i = 0; i < buttonsPath.length; i++) {
if ((isCompatible('1.4.0') ? utils.IsFile(buttonsPath[i]) : utils.FileTest(buttonsPath[i], "e"))) {
include(buttonsPath[i], {always_evaluate: true});
} else {
console.log(buttonsPath[i] +' not loaded');
}
}
/*
OR just add them manually:
include(fb.ProfilePath + 'scripts\\SMP\\xxx-scripts\\buttons\\buttons_search_same_style.js', {always_evaluate: true});
...
*/
}
This way merging buttons becames a matter of editing 1 line. And anyone can create their own bars easily.
How could I do the same within packages?
Is there a universal way to do it? I would prefer to not have 2 versions of the same script, one for packages and other for standard scripts...
Is there a way to check if the script is being loaded within a package?
Could window.DefinePanel or window.DefineScript work within a package?