IdleLogout.rbbas 6.93 KB
Newer Older
Rusty Myers's avatar
Rusty Myers committed
1
#tag Class
Protected Class IdleLogout
Inherits Application
	#tag Event
		Sub Open()
		  Dim debugFileName as string
		  Dim theDate as date
		  dim mXMLtreeToFollow(-1) as string
		  dim mPrefKeyFoundData(-1) as string
		  dim mTempFoundPlistData as string = "" // Local variable to use for gathering plist settings
		  theDate = new Date
		  
		  Globals.gAppFolderItem = GetFolderItem("/Users/Shared/", FolderItem.PathTypeShell)
		  
		  // Set the name of the log
		  debugFileName = "psuIdleLogout.RUN" + MiscMethods.PadData("0",2,str(theDate.Year),Globals.kLogToFileDisable) _
		  + "-" + MiscMethods.PadData("0",2,str(theDate.Month),Globals.kLogToFileDisable) + "-"
		  debugFileName = debugFileName + MiscMethods.PadData("0",2,str(theDate.Day),Globals.kLogToFileDisable) + _
		  "-" + MiscMethods.PadData("0",2,str(theDate.Hour),Globals.kLogToFileDisable) + "-"
		  debugFileName = debugFileName + MiscMethods.PadData("0",2,str(theDate.Minute),Globals.kLogToFileDisable) + _
		  "-" + MiscMethods.PadData("0",2,str(theDate.Second),Globals.kLogToFileDisable) + ".log"
		  
		  // Initilize the log, quit if we can't create the log
		  if not (LogToFile.Initialize(debugFileName,Globals.gAppFolderItem)) then
		    beep
		    MsgBox "Error creating run log file! Exiting..."
		    quit
		  end if
		  
		  // Keep only the last 5 logs
		  if ( LogToFile.DeleteOldLogs(5) ) then
		    LogToFile("Deleted Old Logs")
		  end if
		  
		  
		  // Are there any users that we should ignore running for?
		  if ( PlistHelper.readPlist(LogoutWarning.pDefaultPrefsFSPath, LogoutWarning.pDefaultPrefsFileName, "IgnoreUser", mTempFoundPlistData ) ) then
		    
		    LogoutWarning.pIgnoreUser = mTempFoundPlistData
		    
		    LogToFile(CurrentMethodName + ": Found the default key data, = " + str(LogoutWarning.pIgnoreUser) )
		    
		  else // Failed!
		    
		    LogToFile(CurrentMethodName + ": Warning! Failed to find the default key 'IgnoreUser', using default of "+ str (LogoutWarning.pIgnoreUser) )
		    
		  end if
		  
		  // Are there any groups that we should ignore running for?
		  if ( PlistHelper.readPlist(LogoutWarning.pDefaultPrefsFSPath, LogoutWarning.pDefaultPrefsFileName, "IgnoreGroup", mTempFoundPlistData ) ) then
		    
		    LogoutWarning.pIgnoreGroup = mTempFoundPlistData
		    
		    LogToFile(CurrentMethodName + ": Found the default key data, = " + str(LogoutWarning.pIgnoreGroup) )
		    
		  else // Failed!
		    
		    LogToFile(CurrentMethodName + ": Warning! Failed to find the default key 'IgnoreGroup', using default of "+ str (LogoutWarning.pIgnoreGroup) )
		    
		  end if
		  
		  
		  // Is this user macadmin?
		  if ( MiscMethods.CurrentUsername(LogoutWarning.pIgnoreUser) ) then
		    // It is macadmin, quit the app
		    LogToFile("Current user is " + LogoutWarning.pIgnoreUser + ", quiting app")
		    quit
		  else
		    LogToFile("User is not " + LogoutWarning.pIgnoreUser + ", continuing")
		  end if
		  
		  // Is this user an admin?
		  if ( MiscMethods.CurrentGroup(LogoutWarning.pIgnoreGroup) ) then
		    // It is macadmin, quit the app
		    LogToFile("Current user is an " + LogoutWarning.pIgnoreGroup + ", quiting app")
		    quit
		  else
		    LogToFile("User is not an " + LogoutWarning.pIgnoreGroup + ", continuing")
		  end if
		  
		  
		  // How long should we wait before considering the Mac is idle too long?
		  if ( PlistHelper.readPlist(LogoutWarning.pDefaultPrefsFSPath, LogoutWarning.pDefaultPrefsFileName, "ComputerIdleAfterNumSeconds", mTempFoundPlistData ) ) then
		    
		    LogoutWarning.pComputerIdleAfterNumSeconds = val( mTempFoundPlistData )
		    
		    LogToFile(CurrentMethodName + ": Found the default key data, = " + str(LogoutWarning.pComputerIdleAfterNumSeconds) )
		    
		  else // Failed!
		    
		    LogToFile(CurrentMethodName + ": Warning! Failed to find the default key 'ComputerIdleAfterNumSeconds', using default of "+ str (LogoutWarning.pComputerIdleAfterNumSeconds) )
		    
		  end if
		  
		  // How often should we check to see how long the Mac has been idle?
		  if ( PlistHelper.readPlist(LogoutWarning.pDefaultPrefsFSPath, LogoutWarning.pDefaultPrefsFileName, "IdleLoopDelaySeconds", mTempFoundPlistData ) ) then
		    
		    LogoutWarning.pIdleLoopDelaySeconds = val( mTempFoundPlistData )
		    
		    LogToFile(CurrentMethodName + ": Found the default key data, = " + str(LogoutWarning.pIdleLoopDelaySeconds) )
		    
		  else // Failed!
		    
		    LogToFile(CurrentMethodName + ": Warning! Failed to find the default key 'IdleLoopDelaySeconds', using default of "+ str (LogoutWarning.pIdleLoopDelaySeconds) )
		    
		  end if
		  
		  
		  // How long should we wait for the user to respond for More Time or to Log Out?
		  if ( PlistHelper.readPlist(LogoutWarning.pDefaultPrefsFSPath, LogoutWarning.pDefaultPrefsFileName, "WaitForUserPromptSeconds", mTempFoundPlistData ) ) then
		    
		    LogoutWarning.pWaitForUserPromptSeconds = val( mTempFoundPlistData )
		    
		    LogToFile(CurrentMethodName + ": Found the default key data, = " + str(LogoutWarning.pWaitForUserPromptSeconds) )
		    
		  else // Failed!
		    
		    LogToFile(CurrentMethodName + ": Warning! Failed to find the default key 'WaitForUserPromptSeconds', using default of "+ str (LogoutWarning.pWaitForUserPromptSeconds) )
		    
		  end if
		  
		  // Set default
		  LogToFile(CurrentMethodName + ": Setting pMoreTimeAskedFor as True")
		  Dim pMoreTimeAskedFor as Boolean = true
		  LogoutWarning.Hide()
		  LogToFile(CurrentMethodName + ": Running IdleThread")
		  LogoutWarning.IdleThread.Run
		  
		  LogToFile(CurrentMethodName + ": <---")
		  
		  
		  
		  //Can't do loops in App Open event, won't give focus to window.
		  'do
		  'LogToFile("Waiting for idle time")
		  'LogToFile("pMoreTimeAskedFor: " + str(pMoreTimeAskedFor))
		  'LogoutWarning.Show
		  'loop until not (LogoutWarning.pMoreTimeAskedFor)
		  // Log the user out here or quit!
		  
		  // Check to see if LogoutCountdown is running
		  
		  
		End Sub
	#tag EndEvent


	#tag Note, Name = Icon
		Application Icon use with CC license:
		From http://www.flickr.com/photos/23453447@N02/5107438855/sizes/o/in/photostream/
		By zyrquel
		http://www.flickr.com/photos/23453447@N02/
	#tag EndNote


	#tag Constant, Name = kEditClear, Type = String, Dynamic = False, Default = \"&Delete", Scope = Public
		#Tag Instance, Platform = Windows, Language = Default, Definition  = \"&Delete"
		#Tag Instance, Platform = Linux, Language = Default, Definition  = \"&Delete"
	#tag EndConstant

	#tag Constant, Name = kFileQuit, Type = String, Dynamic = False, Default = \"&Quit", Scope = Public
		#Tag Instance, Platform = Windows, Language = Default, Definition  = \"E&xit"
	#tag EndConstant

	#tag Constant, Name = kFileQuitShortcut, Type = String, Dynamic = False, Default = \"", Scope = Public
		#Tag Instance, Platform = Mac OS, Language = Default, Definition  = \"Cmd+Q"
		#Tag Instance, Platform = Linux, Language = Default, Definition  = \"Ctrl+Q"
	#tag EndConstant


	#tag ViewBehavior
	#tag EndViewBehavior
End Class
#tag EndClass