Window1.rbfrm 10.4 KB
Newer Older
Rusty Myers's avatar
Rusty Myers committed
1
#tag Window
Begin Window Window1
   BackColor       =   16777215
   Backdrop        =   ""
   CloseButton     =   True
   Composite       =   False
   Frame           =   0
   FullScreen      =   False
   HasBackColor    =   False
   Height          =   237
   ImplicitInstance=   True
   LiveResize      =   True
   MacProcID       =   0
   MaxHeight       =   32000
   MaximizeButton  =   False
   MaxWidth        =   32000
   MenuBar         =   1665256176
   MenuBarVisible  =   True
   MinHeight       =   64
   MinimizeButton  =   False
   MinWidth        =   64
   Placement       =   2
   Resizeable      =   False
   Title           =   "Idle Logout"
   Visible         =   True
   Width           =   600
   Begin PushButton BLogOut
      AutoDeactivate  =   True
      Bold            =   ""
      ButtonStyle     =   0
      Cancel          =   ""
      Caption         =   "Log Out"
      Default         =   False
      Enabled         =   True
      Height          =   20
      HelpTag         =   ""
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   ""
      Left            =   337
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      Scope           =   0
      TabIndex        =   1
      TabPanelIndex   =   0
      TabStop         =   True
      TextFont        =   "System"
      TextSize        =   0
      TextUnit        =   0
      Top             =   197
      Underline       =   ""
      Visible         =   True
      Width           =   80
   End
   Begin PushButton BMoreTime
      AutoDeactivate  =   False
      Bold            =   ""
      ButtonStyle     =   0
      Cancel          =   ""
      Caption         =   "More time"
      Default         =   True
      Enabled         =   True
      Height          =   20
      HelpTag         =   ""
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   ""
      Left            =   191
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      Scope           =   0
      TabIndex        =   2
      TabPanelIndex   =   0
      TabStop         =   True
      TextFont        =   "System"
      TextSize        =   0
      TextUnit        =   0
      Top             =   197
      Underline       =   ""
      Visible         =   True
      Width           =   80
   End
   Begin Label WarningTitle
      AutoDeactivate  =   True
      Bold            =   ""
      DataField       =   ""
      DataSource      =   ""
      Enabled         =   True
      Height          =   54
      HelpTag         =   ""
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   ""
      Left            =   112
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      Multiline       =   ""
      Scope           =   0
      Selectable      =   False
      TabIndex        =   3
      TabPanelIndex   =   0
      Text            =   "PSU Idle Logout"
      TextAlign       =   1
      TextColor       =   0
      TextFont        =   "System"
      TextSize        =   30
      TextUnit        =   0
      Top             =   14
      Transparent     =   False
      Underline       =   ""
      Visible         =   True
      Width           =   377
   End
   Begin Label WarningMessage
      AutoDeactivate  =   True
      Bold            =   ""
      DataField       =   ""
      DataSource      =   ""
      Enabled         =   True
      Height          =   41
      HelpTag         =   ""
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   ""
      Left            =   57
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      Multiline       =   ""
      Scope           =   0
      Selectable      =   False
      TabIndex        =   4
      TabPanelIndex   =   0
      Text            =   "The computer will log out out and close any unsaved work in:"
      TextAlign       =   1
      TextColor       =   &h000000
      TextFont        =   "System"
      TextSize        =   0
      TextUnit        =   0
      Top             =   70
      Transparent     =   False
      Underline       =   ""
      Visible         =   True
      Width           =   486
   End
   Begin Label TimeLabel
      AutoDeactivate  =   True
      Bold            =   ""
      DataField       =   ""
      DataSource      =   ""
      Enabled         =   True
      Height          =   51
      HelpTag         =   ""
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   ""
      Left            =   268
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      Multiline       =   ""
      Scope           =   0
      Selectable      =   False
      TabIndex        =   5
      TabPanelIndex   =   0
      Text            =   ""
      TextAlign       =   1
      TextColor       =   &h000000
      TextFont        =   "System"
      TextSize        =   30
      TextUnit        =   0
      Top             =   121
      Transparent     =   False
      Underline       =   ""
      Visible         =   True
      Width           =   64
   End
   Begin Label Seconds
      AutoDeactivate  =   True
      Bold            =   ""
      DataField       =   ""
      DataSource      =   ""
      Enabled         =   True
      Height          =   14
      HelpTag         =   ""
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   ""
      Left            =   331
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      Multiline       =   ""
      Scope           =   0
      Selectable      =   False
      TabIndex        =   6
      TabPanelIndex   =   0
      Text            =   "seconds..."
      TextAlign       =   0
      TextColor       =   &h000000
      TextFont        =   "System"
      TextSize        =   0
      TextUnit        =   0
      Top             =   146
      Transparent     =   False
      Underline       =   ""
      Visible         =   True
      Width           =   104
   End
   Begin Thread IdleThread
      Height          =   32
      Index           =   -2147483648
      Left            =   13
      LockedInPosition=   False
      Priority        =   5
      Scope           =   0
      StackSize       =   0
      TabPanelIndex   =   0
      Top             =   268
      Width           =   32
   End
   Begin Thread CountdownThread
      Height          =   32
      Index           =   -2147483648
      Left            =   57
      LockedInPosition=   False
      Priority        =   5
      Scope           =   0
      StackSize       =   0
      TabPanelIndex   =   0
      Top             =   268
      Width           =   32
   End
End
#tag EndWindow

#tag WindowCode
	#tag Method, Flags = &h0
		Sub Untitled()
		  
		End Sub
	#tag EndMethod


	#tag Property, Flags = &h0
		gLogoutDelay As Integer
	#tag EndProperty

	#tag Property, Flags = &h0
		mIdleResult As Double
	#tag EndProperty


#tag EndWindowCode

#tag Events BLogOut
	#tag Event
		Sub Action()
		  // Testing code
		  Dim s As Shell
		  s=New Shell
		  s.Mode = 0
		  s.execute "say logout"
		  
		  // Log out the user
		  Quit
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events BMoreTime
	#tag Event
		Sub Action()
		  
		  // Testing code
		  Dim s As Shell
		  s=New Shell
		  s.Mode = 0
		  s.execute "say More Time"
		  
		  // Reset time user has been idel to 0
		  Dim idleTime as Integer = 0
		  // Stop the current countdown
		  CountdownThread.Kill
		  // Get rid of the window
		  Window1.Hide
		  // Start the idle thread again
		  IdleThread.Run
		  
		  
		  
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events IdleThread
	#tag Event
		Sub Run()
		  // User has been idle 0 seconds so far
		  Dim idleTime as Integer = 0
		  // How long to wait between checking idle time
		  Dim gLoopDelay as Integer = 30
		  // How long to wait before considering computer abandonded
		  Dim gIdleTooLong as Integer = 5
		  
		  // Set up variables for idle time
		  // Shell result
		  Dim mIdleResult As String
		  // Shell exit code
		  Dim mIdleError As  Integer
		  // Set up shell
		  Dim s As Shell
		  s=New Shell
		  s.Mode = 0
		  
		  Do
		    // Check idle time
		    //s.Execute code to check idle time from USB input devices
		    s.Execute "echo $((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000))"
		    // Set results to mIdleResult
		    mIdleResult = s.Result
		    // Set error code to mIdleError
		    mIdleError = s.ErrorCode
		    // Log mIdleResult for debugging
		    // System.Log(System.LogLevelError, mIdleResult)
		    
		    // Create a value that holds the current "time" (Ticks) and add the time in gLoopDelay you want to wait.
		    Dim waitUntil As Integer = Ticks + gLoopDelay
		    // Wait until Ticks has reached the new value
		    While Ticks < waitUntil
		    Wend
		    // Keep looping until you're considered abandonded.
		  Loop Until val(mIdleResult) >= gIdleTooLong
		  
		  // Show Window1 and start the countdown to logout.
		  Window1.Show()
		  CountdownThread.Run
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events CountdownThread
	#tag Event
		Sub Run()
		  // Set how long to wait before logging out user
		  Dim gLogoutDelay as Integer = 20
		  
		  // Stop the idle thread
		  IdleThread.Kill
		  
		  // While we're waiting for the countdown to finish...
		  While gLogoutDelay >= 0
		    // Set label to the time left
		    TimeLabel.setString(str(gLogoutDelay))
		    // Refresh it
		    TimeLabel.Refresh
		    // take a second away from the time left
		    gLogoutDelay = gLogoutDelay - 1
		    // do nothing for 1 second
		    Dim waitUntil As Integer = Ticks + 60
		    While Ticks < waitUntil
		    Wend
		  Wend
		  // If we're here, the user didn't cancel or log out manaully
		  
		  // Testing mode, use say instead of logout
		  Dim s As Shell
		  s=New Shell
		  s.Mode = 0
		  s.Execute "say Logging Out"
		  
		  // Quit app
		  Quit
		End Sub
	#tag EndEvent
#tag EndEvents