Skip to content

Commit

Permalink
Make the Windows winloggers work without setting current user name in…
Browse files Browse the repository at this point in the history
… parameters or code
  • Loading branch information
LeonidBeynenson committed Jul 8, 2022
1 parent 9741561 commit c9df8c4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 4 additions & 2 deletions run_winlogger.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
call C:\ProgramData\Anaconda3\condabin\conda.bat activate p38
call python C:\cygwin64\home\lbeynens\bin\windows_logger3.py
call C:\ProgramData\Anaconda3\condabin\conda.bat activate p39
FOR /F "tokens=* USEBACKQ" %%F IN (`C:\cygwin64\bin\cygpath.exe -w -a ~/`) DO (SET myhomepath=%%F)
ECHO %myhomepath%
call python %myhomepath%\bin\windows_logger3.py
4 changes: 3 additions & 1 deletion run_winlogger_WRAPPER.bat
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
C:\cygwin64\home\lbeynens\bin\run_winlogger.bat
FOR /F "tokens=* USEBACKQ" %%F IN (`C:\cygwin64\bin\cygpath.exe -w -a ~/`) DO (SET myhomepath=%%F)
ECHO %myhomepath%
%myhomepath%\bin\run_winlogger.bat
16 changes: 11 additions & 5 deletions windows_logger3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import os #, time
#from datetime import datetime
import psutil
import sys

# This var is used for a rude hack with global vars, sorry
USERNAME=os.environ["USERNAME"]

def is_daemon_run():
procs = [p for p in psutil.process_iter() if 'python' in p.name()]
Expand All @@ -23,17 +27,17 @@ def is_daemon_run():


class TaskBarApp(wx.Frame):
def __init__(self, parent, id, title):
def __init__(self, parent, id, title, username="lbeynens"):
wx.Frame.__init__(self, parent, -1, title, size = (1, 1), style=wx.FRAME_NO_TASKBAR|wx.NO_FULL_REPAINT_ON_RESIZE)

self.TIMESTEP = 10000 #ms
self.WAS_ACTIVE = True
self.TIME_OF_SCREENSAVER_START = 0

self.LOG_FILE_FOLDER = "C:/cygwin64/home/lbeynens/worklog/"
self.LOG_FILE_FOLDER = f"C:/cygwin64/home/{username}/worklog/"
self.LOG_FILE_PATH = os.path.join(self.LOG_FILE_FOLDER, "winlog_" + self.CurDate())

self.ICONS_FOLDER = "C:/cygwin64/home/lbeynens/bin/"
self.ICONS_FOLDER = f"C:/cygwin64/home/{username}/bin/"
self.LOGON_ICON_PATH = os.path.join(self.ICONS_FOLDER, 'logon.ico')
self.LOGOFF_ICON_PATH = os.path.join(self.ICONS_FOLDER, 'logoff.ico')

Expand Down Expand Up @@ -153,15 +157,17 @@ class LASTINPUTINFO(Structure):

class MyApp(wx.App):
def OnInit(self):
frame = TaskBarApp(None, -1, ' ')
self.username=USERNAME
print(f"self.username={self.username}")
frame = TaskBarApp(None, -1, ' ', self.username)
frame.Center(wx.BOTH)
frame.Show(False)
return True

def main():
if is_daemon_run():
print('The daemon is already run -- exiting')
sleep(5)
sleep(2)
return 0
app = MyApp(0)
app.MainLoop()
Expand Down

0 comments on commit c9df8c4

Please sign in to comment.