| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  | module OS | 
					
						
							|  |  |  |   module Mac | 
					
						
							| 
									
										
										
										
											2020-09-15 13:39:06 +01:00
										 |  |  |     # Helper module for querying XQuartz information. | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  |     # @api private | 
					
						
							|  |  |  |     module XQuartz | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 20:11:54 +02:00
										 |  |  |       module_function | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 14:24:16 +01:00
										 |  |  |       DEFAULT_BUNDLE_PATH = Pathname("/Applications/Utilities/XQuartz.app").freeze | 
					
						
							|  |  |  |       NEW_BUNDLE_PKG_ID = "org.xquartz.X11" | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  |       FORGE_BUNDLE_ID = "org.macosforge.xquartz.X11" | 
					
						
							|  |  |  |       FORGE_PKG_ID = "org.macosforge.xquartz.pkg" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       PKGINFO_VERSION_MAP = { | 
					
						
							| 
									
										
										
										
											2018-11-02 17:18:07 +00:00
										 |  |  |         "2.6.34"  => "2.6.3", | 
					
						
							|  |  |  |         "2.7.4"   => "2.7.0", | 
					
						
							|  |  |  |         "2.7.14"  => "2.7.1", | 
					
						
							|  |  |  |         "2.7.28"  => "2.7.2", | 
					
						
							|  |  |  |         "2.7.32"  => "2.7.3", | 
					
						
							|  |  |  |         "2.7.43"  => "2.7.4", | 
					
						
							|  |  |  |         "2.7.50"  => "2.7.5_rc1", | 
					
						
							|  |  |  |         "2.7.51"  => "2.7.5_rc2", | 
					
						
							|  |  |  |         "2.7.52"  => "2.7.5_rc3", | 
					
						
							|  |  |  |         "2.7.53"  => "2.7.5_rc4", | 
					
						
							|  |  |  |         "2.7.54"  => "2.7.5", | 
					
						
							|  |  |  |         "2.7.61"  => "2.7.6", | 
					
						
							|  |  |  |         "2.7.73"  => "2.7.7", | 
					
						
							|  |  |  |         "2.7.86"  => "2.7.8", | 
					
						
							|  |  |  |         "2.7.94"  => "2.7.9", | 
					
						
							| 
									
										
										
										
											2017-10-31 16:20:47 +00:00
										 |  |  |         "2.7.108" => "2.7.10", | 
					
						
							|  |  |  |         "2.7.112" => "2.7.11", | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       }.freeze | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # This returns the version number of XQuartz, not of the upstream X.org. | 
					
						
							|  |  |  |       # The X11.app distributed by Apple is also XQuartz, and therefore covered | 
					
						
							|  |  |  |       # by this method. | 
					
						
							|  |  |  |       def version | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:31 +00:00
										 |  |  |         if @version ||= detect_version | 
					
						
							|  |  |  |           ::Version.new @version | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           ::Version::NULL | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def detect_version | 
					
						
							|  |  |  |         if (path = bundle_path) && path.exist? && (version = version_from_mdls(path)) | 
					
						
							|  |  |  |           version | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           version_from_pkgutil | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2017-12-03 13:33:16 +00:00
										 |  |  |       def minimum_version | 
					
						
							|  |  |  |         # Update this a little later than latest_version to give people | 
					
						
							|  |  |  |         # time to upgrade. | 
					
						
							|  |  |  |         "2.7.11" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-03 12:39:26 -05:00
										 |  |  |       # @see https://www.xquartz.org/releases/index.html | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def latest_version | 
					
						
							| 
									
										
										
										
											2019-01-26 17:13:14 +00:00
										 |  |  |         "2.7.11" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def bundle_path | 
					
						
							| 
									
										
										
										
											2017-01-09 21:30:41 +00:00
										 |  |  |         # Use the default location if it exists. | 
					
						
							|  |  |  |         return DEFAULT_BUNDLE_PATH if DEFAULT_BUNDLE_PATH.exist? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Ask Spotlight where XQuartz is. If the user didn't install XQuartz | 
					
						
							|  |  |  |         # in the conventional place, this is our only option. | 
					
						
							| 
									
										
										
										
											2021-09-23 14:24:16 +01:00
										 |  |  |         MacOS.app_with_bundle_id(NEW_BUNDLE_PKG_ID, FORGE_BUNDLE_ID) | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def version_from_mdls(path) | 
					
						
							| 
									
										
										
										
											2014-07-11 15:29:26 -05:00
										 |  |  |         version = Utils.popen_read( | 
					
						
							| 
									
										
										
										
											2014-07-11 15:51:19 -05:00
										 |  |  |           "/usr/bin/mdls", "-raw", "-nullMarker", "", "-name", "kMDItemVersion", path.to_s | 
					
						
							| 
									
										
										
										
											2014-07-11 15:29:26 -05:00
										 |  |  |         ).strip | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |         version unless version.empty? | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Upstream XQuartz *does* have a pkg-info entry, so if we can't get it | 
					
						
							|  |  |  |       # from mdls, we can try pkgutil. This is very slow. | 
					
						
							|  |  |  |       def version_from_pkgutil | 
					
						
							| 
									
										
										
										
											2021-09-23 14:24:16 +01:00
										 |  |  |         [NEW_BUNDLE_PKG_ID, FORGE_PKG_ID].each do |id| | 
					
						
							|  |  |  |           str = MacOS.pkgutil_info(id)[/version: (\d\.\d\.\d+)$/, 1] | 
					
						
							|  |  |  |           return PKGINFO_VERSION_MAP.fetch(str, str) if str | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         nil | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def prefix | 
					
						
							| 
									
										
										
										
											2019-02-19 13:11:32 +00:00
										 |  |  |         @prefix ||= Pathname.new("/opt/X11") if Pathname.new("/opt/X11/lib/libpng.dylib").exist? | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def installed? | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:31 +00:00
										 |  |  |         !version.null? && !prefix.nil? | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def outdated? | 
					
						
							|  |  |  |         return false unless installed? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:31 +00:00
										 |  |  |         version < latest_version | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def bin | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:52 -05:00
										 |  |  |         prefix/"bin" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def include | 
					
						
							| 
									
										
										
										
											2019-01-26 17:13:14 +00:00
										 |  |  |         prefix/"include" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def lib | 
					
						
							| 
									
										
										
										
											2019-01-26 17:13:14 +00:00
										 |  |  |         prefix/"lib" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def share | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:52 -05:00
										 |  |  |         prefix/"share" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-07-25 15:04:46 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |