| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-01 12:29:21 +02:00
										 |  |  | require "delegate" | 
					
						
							|  |  |  | require "etc" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "system_command" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class User < DelegateClass(String) | 
					
						
							|  |  |  |   def gui? | 
					
						
							|  |  |  |     out, _, status = system_command "who" | 
					
						
							|  |  |  |     return false unless status.success? | 
					
						
							| 
									
										
										
										
											2019-02-19 13:12:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-01 12:29:21 +02:00
										 |  |  |     out.lines | 
					
						
							|  |  |  |        .map(&:split) | 
					
						
							|  |  |  |        .any? { |user, type,| user == self && type == "console" } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def self.current | 
					
						
							| 
									
										
										
										
											2020-07-09 01:35:39 +05:30
										 |  |  |     return @current if defined?(@current) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pwuid = Etc.getpwuid(Process.euid) | 
					
						
							|  |  |  |     return if pwuid.nil? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @current = new(pwuid.name) | 
					
						
							| 
									
										
										
										
											2018-10-01 12:29:21 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | end |