Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Spider Monkey Panel (foo_spider_monkey_panel) (Read 342151 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #100
_.first and _.filter are from lodash.js
_getElementsByTagName is from helpers.js

x.responseText is valid (not x.responsetext)

Thanks so much @zeremy! I was going mad. It works now!
Why wouldn't SMP report an error, though?





I'm late


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #102
From what I gather, the strict mode defined in the panel does not apply to the scripts processed with the include statement. Is this an intended behaviour?
Not sure, gonna test it out with other JS engines to see how they handle it.

BTW, is the strict mode kind of mandatory with SMP or is it just a scrpting suggestion by the developers? or is it merely the common practice with the latest ECMA versions?
`strict mode` is not mandatory by any means, but it helps avoiding mistakes in the code (via stricter error checking) and might also increase it's performance. So, yes, it is a recommended mode of operation. You can read more about it >>here<<

I have been experiencing an error on start up in Foobar related to the JS Smooth Browser sample script  in Spider Monkey Panel v1.1.5. See below:
Could you please try the Nightly build (see the link in the first post of this thread) and see if it produces a more intelligible error message?

PS: @zeremy thanks for all the answers in this thread =)

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #103
Thanks so much @zeremy! I was going mad. It works now!

Seems like I spoke too soon. The script stopped working once again, but I can't tell if I got mistaken when I tested it or if I inadvertently made some changes in foobar2000 that affect SMP's behavior. Whatever is, I fixed it, but I still can't understand why SMP and JSP behave differently.

Here's the script as I'm usinig it now. The patch is marked by a comment:
Code: [Select]
var SettingsPath = fb.ProfilePath + "settings\\";
var library_tracks_only = false;
var folder_tf = fb.TitleFormat("$puts(folder,$trim($replace($lower($directory(%path%)),disc,,cd,)))$replace($directory_path(%path%),$ifequal($strstr($get(folder),$num($get(folder),$len($get(folder)))),1,\\%directoryname%,),)\\");
var filename_tf = fb.TitleFormat("front.jpg");

var panel = new _panel("Last.fm Album Art Downloader", ["metadb", "custom_background"]);
var x = new ActiveXObject("Microsoft.XMLHTTP");
var ini = SettingsPath + "album-art.ini";
_createFolder(SettingsPath);

panel.item_focus_change();

function on_playback_new_track(){   //edit for Spider Monkey Panel
panel.item_focus_change();
}

function on_metadb_changed() {
var np = fb.GetNowPlaying();
console.log("SMP: metadb changed");
console.log("SMP: metadb_func = " + (typeof on_metadb_changed == 'function'));
console.log("SMP: if condition = " + (panel.metadb && np && np.Compare(panel.metadb) && np.RawPath.indexOf("file://") == 0 && (!library_tracks_only || fb.IsMetadbInMediaLibrary(np))));
if (panel.metadb && np && np.Compare(panel.metadb) && np.RawPath.indexOf("file://") == 0 && (!library_tracks_only || fb.IsMetadbInMediaLibrary(np))) {
var ar = panel.tf("$meta_sep(artist,', ',' and ')");
var al = panel.tf("%album%");
var f = folder_tf.EvalWithMetadb(panel.metadb) + _fbSanitise(filename_tf.EvalWithMetadb(panel.metadb));
var tmp = _q(_fbSanitise(ar + al));
var n = _.round(_.now() / 1000);
var t = utils.ReadINI(ini, "Timestamps", tmp, 0);

switch (true) {
case !_tagged(ar):
case !_tagged(al):
case _isFile(f):
case n - t < ONE_DAY:
break;
default:
utils.WriteINI(ini, "Timestamps", tmp, n);
x.open("GET", "https://www.last.fm/music/" + encodeURIComponent(ar) + "/" + encodeURIComponent(al) + "/+images", true);
x.setRequestHeader("If-Modified-Since", "Thu, 01 Jan 1970 00:00:00 GMT");
x.send();
x.onreadystatechange = function () {
if (x.readyState == 4) {
if (x.status == 200) {
var o = _.first(_.filter(_getElementsByTagName(x.responseText, "img"), {"className" : "image-list-image"}));
if (o) {
var u = o.src.replace("avatar170s", "ar0");
_runCmd("cscript //nologo " + _q(fb.ProfilePath + "scripts\\SMP\\download.vbs") + " " + _q(u) + " " + _q(f), false);
window.SetTimeout(function () {
panel.item_focus_change();
}, 3000);
}
} else {
console.log("HTTP error: " + x.status);
}
}
}
break;
}
}
RefreshPSS();
}

function RefreshPSS() {
var Refresh_sys = window.GetProperty("Refresh_sys",true);
 if (Refresh_sys < true) {
if (fb.IsPlaying || fb.IsPaused) { 
fb.RunMainMenuCommand("View/Show status bar");
fb.RunMainMenuCommand("View/Show status bar");
} else {
fb.RunMainMenuCommand("View/Show status bar");
fb.RunMainMenuCommand("View/Show status bar");
}
} else {
if (fb.IsPlaying || fb.IsPaused) { 
fb.RunMainMenuCommand("Playback/Play or Pause");
fb.RunMainMenuCommand("Playback/Play or Pause");
} else {
fb.RunMainMenuCommand("Playback/Play");
fb.RunMainMenuCommand("Playback/Stop");
}
}

}

From what I can understand of marc2003's original script, the code responsible for the download is all in the on_metadb_changed function, but because we want the code to be executed also when a new track is played, the on_metadb_changed function is invoked by the item_focus_change method of the panel object, on line 11. As far as I know this part of the code should be read only on panel start up, but with the console I was able to see that the item_focus_change method is executed on playback of a new track by JSP. So, is this one of those incorrect behaviors tolerated by JSP, but not by SMP? Or is the item_focus_change method triggered by some other event, I thought maybe it could be related to the built-in playcount, which is set differently by default in JSP and SMP?
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #104
@davideleo

The difference is that JSP panel.js is different from SMP panel.js

Compare the two files and you will see that in JSP panel.js

Code: [Select]
function on_playback_new_track() {
panel.item_focus_change();
}
is defined

In SMP panel.js  it is not defined
Your edit added the missing function.

TIL : When migrating a custom JSP script we should also check its include files.


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #105
Compare the two files and you will see that in JSP panel.js

Code: [Select]
function on_playback_new_track() {
panel.item_focus_change();
}
is defined

In SMP panel.js  it is not defined
Your edit added the missing function.

Can you please point me to the relevant code lines? I've been comparing the two panel.js versions for the last two days, but I couldn't find it. I must say the whole panel script is pretty hard for me to read, because of the many cross-references and the use of activex objects that I'm not familiar with.

I'm late


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #107
JSP
https://github.com/marc2k3/foo_jscript_panel/blob/master/foo_jscript_panel/samples/complete/js/panel.js#L15

SMP
https://github.com/marc2k3/smp_2003/blob/a0e578ec06211b1d4b01f529962142bf50a75da5/js/panel.js


OMG! I can't believe I totally ignored those callabacks  :-[  I was concentrating on the panel object only.
Thanks.
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #108



I have been experiencing an error on start up in Foobar related to the JS Smooth Browser sample script  in Spider Monkey Panel v1.1.5. See below:
Could you please try the Nightly build (see the link in the first post of this thread) and see if it produces a more intelligible error message?

PS: @zeremy thanks for all the answers in this thread =)



 The error is pretty much the same with the nightly build:

Error: Spider Monkey Panel v1.1.6-beta+0191969 (JS Smooth Browser by Br3tt aka Falstaff)
Resize failed:
Failed to create GdiPlus object (0X0): No error

File:
Line: 3500, Column: 24

Stack trace:
  get_images@:3500:24
  oBrowser/this.update@:1526:3
  oBrowser/this.setSize@:1548:3
  on_size@:3120:3


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #110
The error is pretty much the same with the nightly build:
Could you try again with the latest Nightly? It should produce a proper error message now.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #111
@TheQwertiest

You can reproduce @philodoxxx error if you select Display > Album Art Grid



Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #113
I noticed on one of my scripts that the on_paint() function always increases memory usage, without releasing it, until eventually foobar2000 has no alternative, but crash. I can't tell if this was happening before switching to SMP, because I never really analysed my scripts in this connection, but the flaw is likely in something I ignore about memory allocation and garbage collection.
I'm posting here the on_paint() code, only, because the complete script is quite long, but if it helps I can post the rest of it. For reference: it's a playlist manager script.

Code: [Select]
function on_paint(gr) {
var PlaylistVisible = (fso.FileExists(SettingsPath + "PlaylistVisible"));
var MenuVisible = fso.FileExists(SettingsPath + "MenuVisible");
VisibleItemsCount = (wh / row_height);
ScrollerHeight = Math.max(wh * VisibleItemsCount / UserPlaylistsCount, 30);
    ScrollerExtension = ScrollerHeight - (wh * VisibleItemsCount / UserPlaylistsCount);
    scrollbar_w = MenuVisible?17:0;
idxStart = Math.max(idxStart, SysPlaylistsCount); 
idxEnd = Math.min(TotalPlaylistsCount, idxStart + Math.ceil(VisibleItemsCount));
var x = gr.CalcTextWidth(" ", font);
    var w = ww - x - scrollbar_w;
var h = row_height;
    for (i = idxStart; i < idxEnd; i++) {       
        var y = row_height*(i - idxStart);
        var MouseHover = (x <= mouse_x) && (mouse_x <= x + w) && (y <= mouse_y) && (mouse_y < y + h);
var ActiveVisible = PlaylistVisible && plman.ActivePlaylist == i;
        var icon = plman.PlayingPlaylist == i && fb.IsPlaying?String.fromCharCode(57369):String.fromCharCode(57368);
        var text = "  " + icon + (MenuVisible?"   " + plman.GetPlaylistName(i):"") + (SHOW_COUNT?" [" + plman.PlaylistItemCount(i) + "]":"");
        var textColor = ActiveVisible?colours.White:offcolour;
        var bgColor = MouseHover?setAlpha(colours.Gray, 60):setAlpha(colours.Black, 0);
        if (!dragging && !scrolling) gr.FillSolidRect(x, y, w, h, bgColor);
        if (ActiveVisible) gr.FillSolidRect(x/2, y, x/2, h, RGBA(255,255,255,255));
gr.GdiDrawText(text, font, textColor, x, y, w, h, IFormat);
        if (dragging && MouseHover) gr.FillSolidRect(x, y + drag_down*row_height, w, 1, offcolour);
        }
       
    scrollbar_y = (idxStart - SysPlaylistsCount) * (wh - ScrollerExtension) / UserPlaylistsCount;   
   
    gr.SetSmoothingMode(1);
    if (MenuVisible && (scrollbar || (SCROLLBAR_MODE == 0))) gr.FillRoundRect(ww - scrollbar_w, scrollbar_y, scrollbar_w, ScrollerHeight, 1, 1, RGBA(255,255,255,100));
    gr.SetSmoothingMode(0);  
}

I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #114
@philodoxxx Thanks for the bug report! It will be fixed in the next release, in the meantime you can apply the following fix manually - https://github.com/TheQwertiest/foo_spider_monkey_panel/pull/62/files

I noticed on one of my scripts that the on_paint() function always increases memory usage, without releasing it...
Doesn't look like there is anything that could cause a memory leak in your code. To diagnose the issue I need the full (i.e. working) sample. Ideally it should be stripped down as much as possible =)


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #116
To diagnose the issue I need the full (i.e. working) sample. Ideally it should be stripped down as much as possible =)

If you mean the whole script, here it is:
Code: [Select]
'use strict';

window.DefinePanel('YouFy Playlist Manager', {author:'davideleo'});
include(fb.ComponentPath + 'docs\\Flags.js');
include(fb.ComponentPath + 'docs\\Helpers.js');
include(fb.ProfilePath + 'scripts\\SMP\\YouFy common.js');

var i = 0;
var SysPlaylistsCount = 0;
var UserPlaylistsCount = 0;
var TotalPlaylistsCount = 0
var idxStart = 0;
var idxEnd = 0;
var idxFrom = -1;
var idxTo = -1;
var mouse_x = -1;
var mouse_y = -1;
var dragging = false;
var scrollbar = false;
var scrolling = false;
var SCROLLBAR_MODE = window.GetProperty("Scrollbar Mode", 2); //0=always, 1=never, 2=auto hide
var SHOW_COUNT = window.GetProperty("Show TrackCount", true);
var row_height = Number(ReadSettingsValue("RowHeight", 45));
var DPI = ReadSettingsValue("DPI", 96);
var iconfont = ReadSettingsValue("iconfont","youfy mdl2 assets");
var font_size = 16;
var font_height = font_size * DPI / 72;   
var font = gdi.Font(iconfont, font_height, 0);
var IFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX;
count_playlists();


function on_size() {
    ww = window.Width;
    wh = window.Height;
}


function on_paint(gr) {
var PlaylistVisible = (fso.FileExists(SettingsPath + "PlaylistVisible"));
var MenuVisible = fso.FileExists(SettingsPath + "MenuVisible");
VisibleItemsCount = (wh / row_height);
ScrollerHeight = Math.max(wh * VisibleItemsCount / UserPlaylistsCount, 30);
    ScrollerExtension = ScrollerHeight - (wh * VisibleItemsCount / UserPlaylistsCount);
    scrollbar_w = MenuVisible?17:0;
idxStart = Math.max(idxStart, SysPlaylistsCount); 
idxEnd = Math.min(TotalPlaylistsCount, idxStart + Math.ceil(VisibleItemsCount));
var x = gr.CalcTextWidth(" ", font);
    var w = ww - x - scrollbar_w;
var h = row_height;
    for (i = idxStart; i < idxEnd; i++) {       
        var y = row_height*(i - idxStart);
        var MouseHover = (x <= mouse_x) && (mouse_x <= x + w) && (y <= mouse_y) && (mouse_y < y + h);
var ActiveVisible = PlaylistVisible && plman.ActivePlaylist == i;
        var icon = plman.PlayingPlaylist == i && fb.IsPlaying?String.fromCharCode(57369):String.fromCharCode(57368);
        var text = "  " + icon + (MenuVisible?"   " + plman.GetPlaylistName(i):"") + (SHOW_COUNT?" [" + plman.PlaylistItemCount(i) + "]":"");
        var textColor = ActiveVisible?colours.White:offcolour;
        var bgColor = MouseHover?setAlpha(colours.Gray, 60):setAlpha(colours.Black, 0);
        if (!dragging && !scrolling) gr.FillSolidRect(x, y, w, h, bgColor);
        if (ActiveVisible) gr.FillSolidRect(x/2, y, x/2, h, RGBA(255,255,255,255));
gr.GdiDrawText(text, font, textColor, x, y, w, h, IFormat);
        if (dragging && MouseHover) gr.FillSolidRect(x, y + drag_down*row_height, w, 1, offcolour);
        }
       
    scrollbar_y = (idxStart - SysPlaylistsCount) * (wh - ScrollerExtension) / UserPlaylistsCount;   
   
    gr.SetSmoothingMode(1);
    if (MenuVisible && (scrollbar || (SCROLLBAR_MODE == 0))) gr.FillRoundRect(ww - scrollbar_w, scrollbar_y, scrollbar_w, ScrollerHeight, 1, 1, RGBA(255,255,255,100));
    gr.SetSmoothingMode(0);  
}


function on_mouse_move(x, y) {
drag_down = y >= mouse_y;
    mouse_x = x;
    mouse_y = y;
    scrollbar = (UserPlaylistsCount > VisibleItemsCount && SCROLLBAR_MODE != 1);   
    if(scrolling){
        scrollbar_y = Math.max(exScrollbar_y + y - lbtn_down_y, 0);
        if(scrollbar_y + ScrollerHeight > wh) scrollbar_y = wh - ScrollerHeight;
        idxStart = Math.floor(scrollbar_y * UserPlaylistsCount  / (wh - ScrollerExtension)) + SysPlaylistsCount;
        if(idxStart > TotalPlaylistsCount - VisibleItemsCount) idxStart = TotalPlaylistsCount - VisibleItemsCount;
    }
window.Repaint();   
}
 

function on_mouse_lbtn_down(x, y){  
    if(x > ww - scrollbar_w) {
        if(y > scrollbar_y && y < scrollbar_y + ScrollerHeight) {
            exScrollbar_y = scrollbar_y;
            lbtn_down_y = y;
            scrolling = true;
        } else {
            if (y < scrollbar_y) idxStart = Math.max(idxStart - VisibleItemsCount,0);
            if (y > scrollbar_y + ScrollerHeight) idxStart = Math.min(idxStart + VisibleItemsCount, TotalPlaylistsCount - VisibleItemsCount);
        }
    } else {
        idxFrom = GetPlaylistIdx(y);
        plman.ActivePlaylist = idxFrom;
        fso.CreateTextFile(SettingsPath + "PlaylistVisible").Close();
        if (plman.GetPlaylistName(plman.ActivePlaylist)){
            WriteSettingsValue("ActivePlaylist",plman.GetPlaylistName(plman.ActivePlaylist));
            WriteSettingsValue("PlaylistType",plman.IsAutoPlaylist(plman.ActivePlaylist)?"Autoplaylist":"Playlist");
        }
        RefreshPSS();
        dragging = true;
mouse_y = y;
    }
    window.Repaint();
}


function on_mouse_leave() {
    mouse_x = -1;
    mouse_y = -1;
    scrollbar = false;
    window.Repaint();
}


function on_mouse_lbtn_up(x, y){
    idxTo = GetPlaylistIdx(y);
    if (dragging) plman.MovePlaylist(idxFrom,idxTo);
    dragging = false;
    scrolling = false;
    window.Repaint();
    RefreshPSS();
}


function on_mouse_lbtn_dblclk(x, y){
    if(x < ww - scrollbar_w){
plman.PlayingPlaylist = GetPlaylistIdx(y);
fb.Play();
window.Repaint();
    }
}


function on_mouse_rbtn_down(x, y, mask){
    var idx = GetPlaylistIdx(y);
    var ContextMenu = window.CreatePopupMenu();
    var _ScrollbarOption = window.CreatePopupMenu();
    ContextMenu.AppendMenuItem(MF_STRING, 1, "Rename...");
    ContextMenu.AppendMenuItem(MF_STRING, 2, "Remove");
    ContextMenu.AppendMenuItem(MF_STRING, 3, "Save...");
    ContextMenu.AppendMenuItem(MF_STRING, 11, "Move to top");
    ContextMenu.AppendMenuItem(MF_STRING, 12, "Move to bottom");
    ContextMenu.AppendMenuSeparator();
    if (plman.IsAutoPlaylist(idx)){
        ContextMenu.AppendMenuItem(MF_STRING, 4, "AutoPlaylist Format");
        ContextMenu.AppendMenuSeparator();
    }
    ContextMenu.AppendMenuItem(MF_STRING, 5, "Show Track Count");
    ContextMenu.CheckMenuItem(5, SHOW_COUNT?1:0);
    _ScrollbarOption.AppendTo(ContextMenu,0, "Show Scrollbar");
    _ScrollbarOption.AppendMenuItem(MF_STRING, 6, "Always");
    _ScrollbarOption.AppendMenuItem(MF_STRING, 7, "Never");
    _ScrollbarOption.AppendMenuItem(MF_STRING, 8, "Auto Hide");  
    _ScrollbarOption.CheckMenuRadioItem(6,8,SCROLLBAR_MODE + 6);
    if (mask == 6||mask == 14){
        ContextMenu.AppendMenuSeparator();
        ContextMenu.AppendMenuItem(MF_STRING, 9, "Properties");
        ContextMenu.AppendMenuItem(MF_STRING, 10, "Configure...");
    }
   
    if(idx != null){
        switch(ContextMenu.TrackPopupMenu(x, y, 0)){
            case 1:
            plman.ActivePlaylist = idx;
            fb.RunMainMenuCommand("File/Rename Playlist") ;
            break;
           
            case 2:
            plman.RemovePlaylist(idx);
UserPlaylistsCount = TotalPlaylistsCount - SysPlaylistsCount;
            plman.ActivePlaylist = Math.min(idx, UserPlaylistsCount - 1);
            window.Repaint();
            break;
           
            case 3:
            plman.ActivePlaylist = idx;
            fb.SavePlaylist();
            break;
           
            case 4:
            plman.ShowAutoPlaylistUI(idx);
            break;
           
            case 5:
            SHOW_COUNT = !SHOW_COUNT;
            window.SetProperty("Show TrackCount", SHOW_COUNT);
            ContextMenu.CheckMenuItem(5, SHOW_COUNT);
            window.Repaint();
            break;
           
            case 6:
            SCROLLBAR_MODE = 0;
            window.SetProperty("Scrollbar Mode", 0);
            _ScrollbarOption.CheckMenuRadioItem(6,8,6);               
            break;
           
            case 7:
            SCROLLBAR_MODE = 1;
            window.SetProperty("Scrollbar Mode", 1);
            _ScrollbarOption.CheckMenuRadioItem(6,8,7);
            break;
           
            case 8:
            SCROLLBAR_MODE = 2;
            window.SetProperty("Scrollbar Mode", 2);
            _ScrollbarOption.CheckMenuRadioItem(6,8,8);
            break;
           
            case 9:
            window.ShowProperties()
            break;
           
            case 10:
            window.ShowConfigure();
            break;
           
            case 11:
            plman.MovePlaylist(idx, SysPlaylistsCount);
            window.Repaint();
            break;
           
            case 12:
            plman.MovePlaylist(idx, TotalPlaylistsCount - 1);
            window.Repaint();
            break;
           
            default:     
            break;
        }
    }
}


function on_drag_over(action, x, y, mask){
    mouse_x = x;
    mouse_y = y;
window.Repaint(); 
}


function on_drag_drop(action, x, y) {
var idx = GetPlaylistIdx(y);
action.Playlist = idx;
action.ToSelect = false;
plman.ActivePlaylist = idx;
}


function on_playlists_changed() {
count_playlists();
window.Repaint();
}


function on_notify_data(name, info) {
    switch(name) {
        case "refresh":
        window.Repaint();
RefreshPSS();
        break;
        case "row height":
        row_height = info;
        window.Repaint();
        break;
    }
}


function GetPlaylistIdx(y) {
    return Math.floor(y / row_height) + idxStart;
}


function count_playlists(){         //system playlists are prefixed with a "#" and must be hidden from the playlist manager.
TotalPlaylistsCount = plman.PlaylistCount;
SysPlaylistsCount = 0;
for (i = 0; i < TotalPlaylistsCount; i++) {              
if (plman.GetPlaylistName(i).search("#") == 0) {
if (i > SysPlaylistsCount) plman.MovePlaylist(i, SysPlaylistsCount);
SysPlaylistsCount = SysPlaylistsCount + 1;
}
}
UserPlaylistsCount = TotalPlaylistsCount - SysPlaylistsCount;
}

If you really are willing to review my script (in which case I'd be eternally grateful), for completeness here's also the preprocessed "YouFy common" script:
Code: [Select]
// *****************************************************************************************************************************************
// Additional functions & flags for the YouFy skin
// *****************************************************************************************************************************************

var fso = new ActiveXObject("Scripting.FileSystemObject");
var SettingsPath = fb.ProfilePath + "settings\\";
var SkinPath = fb.ProfilePath + "skins\\YouFy\\";
var ImagesPath = fb.TitleFormat("%images_path%").Eval(true) + "\\";
var ThumbsPath = ImagesPath + "thumbs\\";
var BackgroundPath = ImagesPath + "background\\";
var offcolour = RGB(120,120,120);


function ReadSettingsValue(folder,default_value) {
   if (!fso.FolderExists(SettingsPath)) fso.CreateFolder(SettingsPath);
   var FolderPath = SettingsPath + folder +"\\";
   if(!fso.FolderExists(FolderPath)) {
      WriteSettingsValue(folder,default_value);
      return default_value;  
   } else {
      var FolderObj = fso.GetFolder(FolderPath);
      var FolderEnumerator = new Enumerator(FolderObj.Files);
      if(fso.FileExists(FolderEnumerator.item(1))) {
          return FolderEnumerator.item(1).Name;
        } else {
WriteSettingsValue(folder,default_value);
return default_value
        }
   }
}


function WriteSettingsValue(folder,value) {
   if (!fso.FolderExists(SettingsPath)) fso.CreateFolder(SettingsPath);
   var FolderPath = SettingsPath + folder;  
   if(fso.FolderExists(FolderPath)) {
       var FolderObj = fso.GetFolder(FolderPath);
       var FolderEnumerator = new Enumerator(FolderObj.Files);
       for (var i = 1; i < FolderObj.Files.Count + 1; i++) {
           fso.DeleteFile(FolderEnumerator.item(i));
       }
   } else {
       fso.CreateFolder(FolderPath);
   }
   fso.CreateTextFile(FolderPath + "\\" + value).Close();
}


function RefreshPSS() {
var Refresh_sys = window.GetProperty("Refresh_sys",true);
 if (Refresh_sys < true) {
if (fb.IsPlaying || fb.IsPaused) { 
fb.RunMainMenuCommand("View/Show status bar");
fb.RunMainMenuCommand("View/Show status bar");
} else {
fb.RunMainMenuCommand("View/Show status bar");
fb.RunMainMenuCommand("View/Show status bar");
}
} else {
if (fb.IsPlaying || fb.IsPaused) { 
fb.RunMainMenuCommand("Playback/Play or Pause");
fb.RunMainMenuCommand("Playback/Play or Pause");
} else {
fb.RunMainMenuCommand("Playback/Play");
fb.RunMainMenuCommand("Playback/Stop");
}
}

}


function Get_taskbar_colour() {
    var Shell = new ActiveXObject("WScript.Shell");
    if (Shell.RegRead("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize\\ColourPrevalence")) {
        if (Shell.RegRead("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize\\EnableTransparency")) {
            return AccentPalette(7);
            } else {
            return AccentPalette(6);
        }  
        } else {
        if (Shell.RegRead("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize\\EnableTransparency")) {
            return "0-0-0";
            } else {
            return "16-16-16";
        }
    }
}


function AccentPalette(item) {
    var Shell = new ActiveXObject("WScript.Shell");
    item = item -1;
    AccentPaletteArray = Shell.RegRead("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent\\AccentPalette");
//  return AccentPaletteArray[4*item] + "-" + AccentPaletteArray[1+4*item] + "-" + AccentPaletteArray[2+4*item];
    return RGB(AccentPaletteArray[4*item], AccentPaletteArray[1+4*item], AccentPaletteArray[2+4*item]);
}


function Get_dpi() {
    var Shell = new ActiveXObject("WScript.Shell");
return Shell.RegRead("HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics\\AppliedDPI");
}

var library_items = fb.GetLibraryItems();


function list_values(tag, handle_list = library_items, query = tag + " PRESENT", split = true){
var tags = [];
var items = fb.GetQueryItems(handle_list, query)
for (var i = 0; i < items.Count; i++) {
var handle = items[i];
var meta_num = fb.TitleFormat("$meta_num(" + tag + ")").EvalWithMetadb(handle);
for (var j = 0; j < meta_num; j++) {
tags.push(fb.TitleFormat("$meta(" + tag + "," + j + ")").EvalWithMetadb(handle));
}
}
fb.ShowPopupMessage(_.uniq(tags.sort(), true).join("\n"));
}



All in all the script works fluently and the on_paint routine doesn't actually use much memory. What leaves me perplexed is that it is never released. Why would that even happen, unless something's not working properly with the GC?


P.S.
I also wanted to explain that I realized the issue was with the on_paint function because the on_mouse_move function always triggers a repaint. By simply moving the mouse over the panel, the memory increases. After commenting out the repaint instruction, moving the mouse over the panel doesn't increase memory usage by one byte.
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #117
I also wanted to explain that I realized the issue was with the on_paint function because the on_mouse_move function always triggers a repaint. By simply moving the mouse over the panel, the memory increases. After commenting out the repaint instruction, moving the mouse over the panel doesn't increase memory usage by one byte.

I uploaded a short video to show what I mean (and maybe it is also of help to who is willing to take a look at my script).
I'm late


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #119
@davideleo your script looks like this for me
Spoiler (click to show/hide)
And there were no apparent memory leaks :\

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #120
@davideleo your script looks like this for me
Yes, that's because you are missing the "Youfy MDL2 assets" font, which is a collage-font I put together for this skin. Actually there are also a few variables which take their value from text files created by another script.


And there were no apparent memory leaks :\
So, that's a clue, isn't it? Doesn't it close in on the interaction with other scripts or components? I actually already tested it without the black sheep of foobar2000's plug-ins, foo_customdb, but nothing changed.
What about the GC settings in the advanced preferences? Should I  mess around with them?
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #121
I tested all of my scripts and it turned out it's a general problem. Every on_paint() function seems to increase memory and never release it. Even worse is that there is likely an on_playback_newtrack() function with the same problem, but I still didn't find out which one. That means my foobar2000 is bound to crash sooner or later at every session, even if I don't touch it.
What really put me down is that I also tested the only script I have by another author (marc2003's Last.fm Bio) and guess what? No memory leak at all. This is the proof that the problem is in my scripting.

@TheQwertiest when you write that there were no apparent memory leaks, do you mean that triggering the on_mouse_move() doesn't increase memory usage or that the memory increase is then released? BTW thanks a lot for taking a look.
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #122
Anyone knows a quick way to remove or move the now playing arrow on j smooth?

 

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #123
Uh, this 'Edit' menu problem drives me nuts )) I don't get it, why this happens (this only affects 'Edit' submenu, others work just fine):



but if I use default Menu everything works just fine =>



I'm using snippet from MainMenuManager All-In-One.js

Speaking of which: I got couple of questions:
1)
Code: [Select]
contextman.InitNowPlaying(); 
this is getting called twice for some reason

2)
Am I MisSinG SoMetHing wItH thE CasE herE?
Code: [Select]
    menuman1.Init('file');
    menuman2.Init('edit');
    menuman3.Init('View');
    menuman4.Init('playback');
    menuman5.Init('library');
    menuman6.Init('help');

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #124
Nevermind, guh... I've spent so much time trying to figure it out, but the problem was with panel settings... just unchecked 'grab focus' and it's working as intended.

My god, that's so silly...