What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Request] Idle Lock

[Request] Idle Lock
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: [Request] Idle Lock
quote:
Originally posted by markee
Thanks to NanaFreak yet again for the interface too.
The tooltips of the OK and Cancel button are not entirly correct.

for the OK button it should be: "Save settings and close the window" instead of just "Save settings" since that is for an Apply button.

for the Cancel button it should be "Discard the settings and close the window" since "Don't save settings" doesn't say if you're going to close the window too and can also be interpreted as the new made settings will be used but not saved.

;)

--------------------------------------------------------------------

comments on the script (BUGS, improvements, etc):

1)
code:
try{
    var idle = new ActiveXObject("WScript.Shell").RegRead(MsgPlus.ScriptRegPath+Messenger.MyUserId);
}catch( e ){
    var idle = "";
}
Will _always_ fail because Messenger.MyUserId is _always_ undefined here, unless the script is restarted when the user is signed in (aka: never, unless the user has signed in while he modified something in the script and re-saved it, or when the script is enabled for the first time).

Thus, never use such code in the global scope of the script. Instead put all this in the OnEvent_Signin() event.


2)
code:
MsgPlus.CancelTimer(Messenger.MyUserId);
MsgPlus.AddTimer(Messenger.MyUserId,idle);
If you're going to add/start a timer you do not need to cancel it first. Any timer you re-create will be reset already.

3)
code:
function OnEvent_Timer(ID){
    if(ID==Messenger.MyUserId){
        MsgPlus.LockMessenger(true)
    }
}
This indeed takes in account that the user can sign out and another user signing in when the timers are still running. BUT, you also have:
code:
function OnEvent_Signout( M ){
    MsgPlus.CancelTimer(Messenger.MyUserId);
}
which makes that one of the two is useless (that is: the check in
OnEvent_Timer or the whole OnEvent_Signout event).

In other scripts I would recommend to remove the OnEvent_Signout event and keep the check in OnEvent_Timer. Because if you do that, a user who temporarly signed out, to let someone else on MSN, can afterwards still sign in and the timers of his will still be running for him.
But for this particular script I would remove the check in OnEvent_Timer, since the timer ID will always be the one of the user who set it since you remove the timer in the signout event.

4)
code:
if (/^\/idlelock\s*(.*)$/i.exec(Mess) != null){
If you aren't going to use parameters or whatever, you don't need to check and catch them using a regular expression, simply use:
code:
if (Mess.toLowerCase() === "/idlelock"){
which doesn't need the resources of a regular expression.

Or if you still want to use a regular expression and/or also react on the command when the user has typed something after it, simply remove the parenthesis "(" and ")" (and "$" is also not needed, since you already use ".*").

5)
code:
function OnEvent_MenuClicked(ID,Loc,Orig){
    MsgPlus.CancelTimer(Messenger.MyUserId);
    if(ID=="Pref"){
        var Wnd = MsgPlus.CreateWnd("UI.xml","WndConfig");
        Wnd.SetControlText("EdtMin",Math.floor(idle/60000));
        Wnd.SetControlText("EdtSec",Math.floor(idle%60000/1000));
    }else{
        MsgPlus.AddTimer(Messenger.MyUserId,idle);
    }
}
Cancelling the timer here will produce two bugs/unwanted behaviour:
The messenger will not be locked when the user has openend the preferences and forgot about it (and went to the toilet for 30 minutes :p). And when the user discards the preferences and closes the window, messenger will not be locked anymore after a while.

Second, the 'else' part is useless since there isn't another menu item.

6)
code:
function OnWndConfigEvent_Destroyed(Wnd,C){
    notidle();
}
function OnEvent_Initialize( M ){
    notidle();
}
....
With stuff like this you don't need those parameters, so you might as well just write
code:
function OnWndConfigEvent_Destroyed(){
....
Goes for the rest of those events too.

7)
code:
function OnEvent_ChatWndCreated(Wnd){
    notidle();
}
Remove this event, since a chat window will also be created when a contact messages you. When this happens, the timer must not be cancelled since someone can still message the user while he is away. When that happens, messenger may never go into lock as long as contacts start messaging (Idle means no user interaction, not no interaction at all).
PS: you have this event three times in your script by the way.

Same goes for the events OnEvent_SigninReady() and OnEvent_Initialize because Messenger can signout the user at any time and sign him back in automatically without any user interaction.

On the opposite, there is a notidle() mssing in the OnEvent_MenuClicked() event, since only a user interaction can click on a menu. So replace the cancelling of the timer (see point 5) with notidle().

8)
code:
function OnEvent_MessengerUnlock(Wnd){
    MsgPlus.AddTimer(Messenger.MyUserId,idle);
}
This should contain a notidle() instead (thus with the check on the variable 'idle').



Though, as you said also, this is not a good way to detect being 'idle' as a whole. It has many flaws (not speaking about the above bugs, but about limitations you can't do anything about it by using such a script). Also, what is not implemented is unlocking messenger when the user starts interacting again (major bug too). To overcome all this you should indeed just detect a status change to and from 'Idle' (also because it is way more consistant with the normal flow of things).

;)

This post was edited on 12-18-2006 at 07:38 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
12-18-2006 06:39 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[Request] Idle Lock - by Eddie on 12-18-2006 at 02:43 PM
RE: [Request] Idle Lock - by ins4ne on 12-18-2006 at 02:44 PM
RE: [Request] Idle Lock - by markee on 12-18-2006 at 02:47 PM
RE: [Request] Idle Lock - by Eddie on 12-18-2006 at 02:48 PM
RE: [Request] Idle Lock - by ins4ne on 12-18-2006 at 02:50 PM
RE: [Request] Idle Lock - by markee on 12-18-2006 at 03:49 PM
RE: RE: [Request] Idle Lock - by CookieRevised on 12-18-2006 at 06:39 PM
RE: [Request] Idle Lock - by ins4ne on 12-18-2006 at 03:51 PM
RE: RE: [Request] Idle Lock - by markee on 12-18-2006 at 03:56 PM
RE: [Request] Idle Lock - by Plik on 12-18-2006 at 03:57 PM
RE: RE: [Request] Idle Lock - by markee on 12-18-2006 at 04:02 PM
RE: [Request] Idle Lock - by ins4ne on 12-18-2006 at 03:57 PM
RE: [Request] Idle Lock - by foaly on 12-18-2006 at 03:59 PM
RE: [Request] Idle Lock - by ins4ne on 12-18-2006 at 04:04 PM
RE: [Request] Idle Lock - by ins4ne on 12-18-2006 at 09:24 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On