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 121572 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #800
I hope that this is a good place for a general js question. I've modified the samples/complete/playback buttons.js file to create a toolbar, and there are two toggling buttons on it that are related to one another. I would like to enable or disable the second of them depending on the state of the first.

The buttons themselves are defined thusly:
Code: [Select]
buttons.update = () => {
    // other buttons omitted
    buttons.buttons.editor = new _button(bs * 8, 0, bs, bs,
        {normal : window.GetProperty('editorshown', fso.FileExists(filepath))
        ? bp + 'player_cool.png' : bp + 'editor_cool.png',
        hover : window.GetProperty('editorshown') ? bp + 'player_hot.png'
        : bp + 'editor_hot.png'},
        (x, y) => { toggle_editor(); }, 'Editor/player');
    buttons.buttons.showgroups = new _button(bs * 9, 0, bs, bs,
        {normal : window.GetProperty('groupsshown')
        ? bp + 'grouphide_cool.png' : bp + 'groupshow_cool.png',
        hover : window.GetProperty('groupsshown')
        ? bp + 'grouphide_hot.png' : bp + 'groupshow_hot.png'},
        (x, y) => { toggle_groups(); }, 'Show/hide groups (editor)');

That toggle_editor function is as follows and is where I'd like to put the enabling/disabling of the showgroups button. At the moment, it toggles a window property to set the editor button's images and creates/deletes an empty file in order to tell a panel stack splitter to hide some elements and show others.

Code: [Select]
function toggle_editor() {
    if (window.GetProperty('editorshown')) {
        window.SetProperty('editorshown', false);
        fso.DeleteFile(filepath);
    } else {
        window.SetProperty('editorshown', true);
        fso.CreateTextFile(filepath).Close();
    }
    buttons.update();
    window.Repaint();
}

So how can a javascript neophyte enable or disable a button like this? My searches turn up various ways of using javascript to interact with HTML buttons or what have you, but I can't tell if I've found anything dealing with a pure js setting. Would graphic actions like producing the "grayed out" effect happen automatically, or would I need to make another png for that?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #801
There are multiple ways, but adding a simple boolean would do.

Code: [Select]
let bEnable = true;  // note this is outside the function, global var
function toggle_editor() {
   bEnable = !bEnable; // Just changes true -> false, false -> true
    if (window.GetProperty('editorshown')) {
        window.SetProperty('editorshown', false);
        fso.DeleteFile(filepath);
    } else {
        window.SetProperty('editorshown', true);
        fso.CreateTextFile(filepath).Close();
    }
    buttons.update();
    window.Repaint();
}

Then you add that check on the button you want to change. I'm not really sure if you want to delete the button, left it there but doing nothing, changing its appearance to reflect the change, but...

Code: [Select]
    buttons.buttons.showgroups = new _button(bs * 9, 0, bs, bs,
        {normal : window.GetProperty('groupsshown')
        ? bp + 'grouphide_cool.png' : bp + 'groupshow_cool.png',
        hover : window.GetProperty('groupsshown')
        ? bp + 'grouphide_hot.png' : bp + 'groupshow_hot.png'},
        (x, y) => {
                if (!bEnable) {return;} // Don't do anything if it's false
                toggle_groups();
        }, 'Show/hide groups (editor)');

Finally, adjust the initial state of bEnable according to how you want it to work.  You should be able to expand the idea to change the other parts (like using a different png according to the boolean, etc.)

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #802
Hello,

does anyone know how to fix the ActiveX htmlfile error?:

ActiveXObject_Constructor failed:
Failed to create ActiveXObject object via CLSID: htmlfile
const doc = new ActiveXObject('htmlfile');

Is there a fix or workaround?
I am using the latest Spider Monkey Panel v1.4.1 with foobar 1.6.5...

Thank you

- TT

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #803
There was a long discussion in another thread about slow performance of FSM scripts at startup. Seems that some of us, in certain conditions, have very poor performance (15-30sec startup times). This was immediately apparent to me when switching Georgia from jscript_panel, but I thought I was the only one. That wasn't the case, and an argument about the root cause and what happens at startup got me thinking.

I forked the current FSM codebase and made some changes to how FSM itself starts up, essentially delaying initialization of several required services to the component's on_init() which is when foobar says "it's okay" to start loading stuff. In most instances this has improved my foobar startup time 3-5x. Results may vary and if you weren't experiencing slow startup with FSM scripts, then this may not do anything for you.

This is a dev (unreleased) build from Feb so it was has a few things in it post the last 1.4.1 release, plus my code of course. Should be safe to use. Hopefully we can get a few more eyes on this to see if others see improvements on startup time and make sure there are no unintended consequences.

Pull request can be found here.

Edit: Dev component removed due to crashes.


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #805
Hello,

does anyone know how to fix the ActiveX htmlfile error?:

ActiveXObject_Constructor failed:
Failed to create ActiveXObject object via CLSID: htmlfile
const doc = new ActiveXObject('htmlfile');

Is there a fix or workaround?
I am using the latest Spider Monkey Panel v1.4.1 with foobar 1.6.5...

Thank you

- TT

You need to install the Gecko support in Wine to have basic HTML controls, and even then, it's not guaranteed to be compatible with Windows.

For anyone else that has the same problem running foobar in Wine, installing Gecko solved the problem.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #806
Does anyone know if utils.CheckFont and gdi.Font are working correctly under Wine?

I've put custom ttf fonts in /usr/share/wine/fonts and ~/.wine/drive_c/Windows/fonts
and it seems are not initialized with utils.CheckFont and loaded via gdi.Font in SMP...

If I change for example the font in Preferences -> Columns UI -> Colors and fonts, the font to the custom font changes and is displayed correctly!


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #808
@snotlicker can you try with the following version and see if you still get crashes?

This test did not show any improvements. Removing custom build.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #809
Try a .fonts folder inside your linux HOME folder.

Didn't work :( ,

I also tried from etc/fonts/fonts.conf
/usr/share/fonts and /usr/local/share/fonts

without luck...

@TheQwertiest Do you know what's up with https://hydrogenaud.io/index.php?topic=116669.msg997682#msg997682 ?


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #811
Try a .fonts folder inside your linux HOME folder.

Didn't work :( ,

I also tried from etc/fonts/fonts.conf
/usr/share/fonts and /usr/local/share/fonts

without luck...

@TheQwertiest Do you know what's up with https://hydrogenaud.io/index.php?topic=116669.msg997682#msg997682 ?

What I said was the right folder. You probably need to install gdiplus via winetricks.

In this screenshot, the buttons on the bottom right require FontAwesome....




Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #813
FYI: I will try to make some time this month (as in next 30 days), though I don't think there will be a lot of new features in SMP (if any), but it should contain some API and package handling fixes.

My current plan is the following:
- SMP: fix reported bugs. Focus on package support.
- foo_spotify: fix all the reported bugs.
- CaTRoX theme: release SMP version.
- foo_discord_rich: implement the `last` feature (it will be probably the last feature release, since Discord doesn't develop their API much).
- SMP: work on new features.
- foo_spotify: work on new features.

It should be said, that even if I'm not answering here, it doesn't mean that your messages are being ignored or forgotten (or not appreciated), most of them were stored in my `to_do.txt` (that I'm too lazy to transfer to GH properly)...

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #814
@TheQwertiest
Great to know you still intend to develop SMP. With all the new stuff going into JScript panel I was wondering about changing back.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #815
Have found a weird behaviour while working on the playlist manager, because I have just set the shift key as a shorcut to delete files and it was not working...

Lets say I have this recycle function
Code: [Select]
function _recycleFile(file) {
if (_isFile(file)) {
try {
app.NameSpace(10).MoveHere(file);
} catch (e) {
return false;
}
return !(_isFile(file));
}
return false;
}

If I'm pressing SHIFT while the panel run this part, then the file is deleted without being sent to the recycle bin. Which is pretty weird since I'm using a moveHere function on the end... (I suppose's it's related to the shift+delete behaviour of win, but this is not a "delete" operation)
Code: [Select]
_recycleFile(newPath);

But this is even worse:
Code: [Select]
if (utils.IsKeyPressed(VK_SHIFT)) {
const debouncedRecycle = debounce(() => {
if (utils.IsKeyPressed(VK_SHIFT)) {
debouncedRecycle(newPath);
return;
} else {_recycleFile(newPath);}  // It "magically" works after some ms even if the key is still pressed
}, 100);
debouncedRecycle();
} else {_recycleFile(newPath);}

// Where debounce is:
const debounce = (func, delay, immediate) => {
let timerId;
return (...args) => {
const boundFunc = func.bind(this, ...args);
clearTimeout(timerId);
if (immediate && !timerId) {
boundFunc();
}
const calleeFunc = immediate ? () => {timerId = null;} : boundFunc;
timerId = setTimeout(calleeFunc, delay);
};
};

So the last code sends the file to the recycle bin even if I'm pressing shift indefinitely (?). Which is good since that's what I want in the end, but not what I expected at all hahaha

utils.IsKeyPressed(VK_SHIFT) returns false at the third or fourth try. even if I'm pressing the key. Am I missing something? (like a timer for pressed keys)

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #816
Instead of using a debounce, what if you just do a simple busy wait?

Code: [Select]
while(utils.IsKeyPressed(0x10)) {}
_recycleFunc(file);

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #817
If isKeyPressed worked as it was supposed to do, that would hang execution of the rest of the code indefinitely while you maintain the key pressed.  I don't care when the file is deleted, so I don't need at all to do it in a synchronous way. I can tolerate deletion being post-poned, not the other code.
Anyway, that's not the point (?).  It seems it's a tradition of this forum to give answers not related to the questions hahaha

The question: Why "isKeyPressed" returns false at some point while pressing the key without releasing it?


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #819
If you want to do something when the key is released, use on_key_up. I would have thought that was obvious.
That's obvious, but that doesn't explain why isKeyPressed returns false when the key is still pressed.

Or we should name that function "maybeIsKeyPressedOrMaybeNot"? Cmon...

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #820
IsKeyPressed is provided by the foobar2000 SDK.

Code: [Select]
bool IsKeyPressed(unsigned vk) {
return (GetKeyState(vk) & 0x8000) ? true : false;
}

GetKeyState is a Windows API method and you can read more about it here.

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getkeystate

Don't like it? Don't use it.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #821
If isKeyPressed worked as it was supposed to do, that would hang execution of the rest of the code indefinitely while you maintain the key pressed.  I don't care when the file is deleted, so I don't need at all to do it in a synchronous way. I can tolerate deletion being post-poned, not the other code.
Anyway, that's not the point (?).  It seems it's a tradition of this forum to give answers not related to the questions hahaha

The question: Why "isKeyPressed" returns false at some point while pressing the key without releasing it?
It was related to your question, as I was wondering if your debounce implementation was doing something weird, especially because you have your debounce just implementing a set timeout essentially (maybe it makes sense in broader context). Regardless, it seems like it's doing something funny because I can't replicate your issue (the busy wait hangs foobar interestingly). This works perfectly fine:
Code: [Select]
function on_key_down(vkey) {
let count = 0;
const test = setInterval(() => {
if (!utils.IsKeyPressed(VK_SHIFT)) {
console.log('shift is not down');
clearInterval(test);
}
count++;
if (count > 100) {
console.log('stopped waiting')
clearInterval(test);
}
},25);
}
It also works perfectly fine in on_key_up it will wait forever until I let go of shift if I increase the max count... which it certainly sounds like what you want.

Could be an issue with your keyboard or something in the OS (stickykeys/filterkeys maybe? I know those are related to holding shift)

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #822
Well I tested it on win 10 and the same code does what it's supposed to do. i.e. it always returns true while the key is pressed, and as result my file is never deleted (while pressing shift). Also tried with multiple variants... loops, intervals, etc. All are fine.

Yesterday I was working on win 7. So I think that we got another function (like utils.FileTest() ) behaving different in win 7 and win 10.
Will check all tests again on the other PC asap, but if it's another SO behavior mismatch the func is totally broken on win 7.

Quote
Could be an issue with your keyboard or something in the OS (stickykeys/filterkeys maybe? I know those are related to holding shift)

I don't use any of that. But I will check it since I have access to multiple PCs with win 7.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #823
So this is gonna be an odd question and I fully realize off the bat that I am probably not using FSM as intended. That said, let's talk about complex animations!

In Georgia 2.0.2 I added spinning cdArt. Uses a ton of memory and some CPU but looks pretty cool. For 2.0.3 that's about to release I added a bunch of different options to control # of images cached and how quickly those images refresh. I've done a TON of optimization on this front to ensure that my on_paint's happen as quickly as possible. My screen refresh rate is 60Hz, but obviously 16.6ms is too fast to do anything complex and for rotation the max speed I even attempt is 75ms or roughly 13fps. Because I'm caching the cdArt (drawing rotated images is way too slow) each on_paint for the cd image takes around 7-10ms on a 4k monitor at full screen -- 1080p monitor we're talking 3-6ms. This should be really easy to do smoothly. However, it appears that FSM is somehow dropping frames at times. Rotation of the image jerks and skips every 4-5 images as images are skipped.

Now you might think this is just judder related to refreshes happening every 4 or 5 frames (sometimes 6 if things slow down), but frames are actually being dropped. If you open this youtube video and slow it down to .25x it's easy to see that some numbers are skipped meaning that even though the on_paint is happening (console logs show every image being drawn) the screen never gets updated.

@TheQwertiest is there any possible solution for this?

Nevermind. Seems nVidia has changed my desktop refresh rate back to 23Hz after watching a movie. Setting it back to 60Hz and animation is smooth like butter. I feel dumb.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #824
Quote
utils.WriteTextFile(fn, text, bom)
"bum" - Help. I can't understand what it means.
I.m. UR5EQF

 
SimplePortal 1.0.0 RC1 © 2008-2021