@@ -640,6 +640,55 @@ def update_seed_recovered( window, values, details, passphrase=None ):
640640 return f"Recovered Seed { recohex !r} doesn't match expected: { window ['-SEED-' ].get ()!r} "
641641
642642
643+ def user_name_full ():
644+ full_name = None
645+ if sys .platform == 'darwin' :
646+ command = [ '/usr/sbin/scutil' ]
647+ command_input = "show State:/Users/ConsoleUser"
648+ elif sys .platform == 'win32' :
649+ command = [ 'net' , 'user' , os .environ ['USERNAME' ] ]
650+ command_input = None
651+ else : # assume *nix
652+ command = [ 'getent' , 'passwd' , os .environ ['USER' ] ]
653+ command_input = None
654+
655+ subproc = subprocess .run (
656+ command ,
657+ input = command_input ,
658+ capture_output = True ,
659+ encoding = 'UTF-8' ,
660+ )
661+ assert subproc .returncode == 0 and subproc .stdout , \
662+ f"{ ' ' .join ( command )!r} command failed, or no output returned"
663+
664+ if sys .platform == 'darwin' :
665+ for li in subproc .stdout .split ( '\n ' ):
666+ if 'kCGSessionLongUserNameKey' in li :
667+ # eg.: " kCGSessionLongUserNameKey : Perry Kundert"
668+ full_name = li .split ( ':' )[1 ].strip ()
669+ break
670+ elif sys .platform == 'win32' :
671+ for li in subproc .stdout .split ( '\n ' ):
672+ if li .startswith ( 'Full Name' ):
673+ # eg.: "Full Name IEUser"
674+ full_name = li [9 :].strip ()
675+ break
676+ elif li :
677+ # getent="perry:x:1002:1004:Perry Kundert,,,:/home/perry:/bin/bash"
678+ # >>> getent.split(':')
679+ # ['perry', 'x', '1002', '1004', 'Perry Kundert,,,', '/home/perry', '/bin/bash']
680+ pwents = li .split ( ':' )
681+ assert len ( pwents ) > 4 , \
682+ f"Unrecognized passwd entry: { li } "
683+ gecos = pwents [4 ]
684+ full_name = gecos .split ( ',' )[0 ] # Discard ...,building,room,phone,...
685+
686+ assert full_name , \
687+ "User's full name not found"
688+ log .info ( f"Current user's full name: { full_name !r} " )
689+ return full_name
690+
691+
643692def app (
644693 names = None ,
645694 group = None ,
@@ -680,24 +729,9 @@ def app(
680729 #
681730 # If no name(s) supplied, try to get the User's full name.
682731 #
683- if not names and sys . platform == 'darwin' :
732+ if not names :
684733 try :
685- scutil = subprocess .run (
686- [ '/usr/sbin/scutil' ],
687- input = "show State:/Users/ConsoleUser" ,
688- capture_output = True ,
689- encoding = 'UTF-8' ,
690- )
691- print ( repr ( scutil ))
692- assert scutil .returncode == 0 and scutil .stdout , \
693- "'scutil' command failed, or no output returned"
694- for li in scutil .stdout .split ( '\n ' ):
695- if 'kCGSessionLongUserNameKey' in li :
696- # eg.: " kCGSessionLongUserNameKey : Perry Kundert"
697- full_name = li .split ( ':' )[1 ].strip ()
698- log .info ( f"Current user's full name: { full_name !r} " )
699- names = [ full_name ]
700- break
734+ names = [ user_name_full () ]
701735 except Exception as exc :
702736 logging .exception ( f"Failed to discover user full name: { exc } " )
703737
@@ -744,6 +778,7 @@ def app(
744778 window = sg .Window (
745779 f"{ ', ' .join ( names or [ 'SLIP-39' ] )} Mnemonic Cards" , layout ,
746780 grab_anywhere = True ,
781+ no_titlebar = True ,
747782 scaling = scaling ,
748783 )
749784 timeout = 0 # First time through w/ new window, refresh immediately
0 commit comments