Idle Timeout

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Idle Timeout

Postby jackiezachman » Fri Mar 26, 2010 1:16 pm

Has anyone implemented an Idle Timeout they would be willing to share. I need to detect if my application has been idle for say 15 minutes or more and if so, post a 'locked out' screen where the user must login again to continue working in my application. Any ideas on where to start with this? I don't want to set up a bunch of timers/polling that could negatively impact the normal performance of my application.
jackiezachman
 
Posts: 11
Joined: Tue Nov 06, 2007 6:53 am

Re: Idle Timeout

Postby tc » Sun Mar 28, 2010 9:55 am

Hello,

I'm unaware of any OS call that tells you how long your application has been idle.

If you do it from within ST then you would setup a watchdog timer:
Code: Select all
self timeout: [
   (Delay forSeconds: 1200 ) wait.
   self timeoutFired
] fork

. . . to detect mouse/keyboard activity, add this to a composition editor window for the 'aboutToOpenWindow' event for the main window:
Code: Select all
aboutToOpenWindow: aParm1 with: aParm2

(self subpartNamed: 'Window') primaryWidget allChildren do: [ :c |
   c
      addEventHandler: (PointerMotionMask | KeyPressMask)
      receiver: self
      selector: #mouseOrKeyboardActivity
      clientData: nil ]

. . . when the method 'mouseOrKeyboardActivity' is called, simply do 'self timeout: nil'. When the method 'timeoutFired' is called, if timeout is nil then create a new timer. If it is not nil then lock your application.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Re: Idle Timeout

Postby PhotonDemon » Sun Apr 11, 2010 8:43 am

Hi Jackie,

Sorry for the long delay in posting a reply. Attached (I hope) is a zip of a file out of OSMsgWithTime a sub-class of OSMsg that when used to replace the instance of OSMsg will keep track of the times of OS events. It is my version of code posted in the past by James Foster, Jeff Odell, Raffi Krikorian and others.

To set up for a test execute:

Code: Select all
   (PlatformGlobals::Qmsg isKindOf: OSMsgWithTime) ifFalse: [PlatformGlobals::Qmsg := OSMsgWithTime new fix].


Then execute:

Code: Select all
[
   [OSMsgWithTime msSinceLastEvent < 5000] whileTrue: [(Delay forSeconds: 1) wait].
   Transcript show: 'Hi'; cr.
] fork.


If you move the mouse around or click thinks, nothing will happen, if you wait five seconds, "Hi" will be printed in the Transcript.

To use the class in a program, add PlatformGlobals to the poolDictionaries or use PlatformGlobals::Qmsg to use this class.

Somewhere in your program do this to set up:

(Qmsg isKindOf: OSMsgWithTime) ifFalse: [Qmsg := OSMsgWithTime new fix].

then where ever you want to test for user activity use #OSMsgWithTime>msSinceLastEvent or
#OSMsgWithTime>secondsSinceLastEvent.


Lou

P.S. Note to VA Smalltalk guys, I would have no problem with you adding the pertinent code to OSMsg. Making the sub-class and set up unnecessary.
Attachments
OSMsgWithTime.Zip
(1.11 KiB) Downloaded 11 times
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest