-
Notifications
You must be signed in to change notification settings - Fork 60
/
nix_desktop_environment.rb
93 lines (76 loc) · 2.51 KB
/
nix_desktop_environment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module Launchy::Detect
#
# Detect the current desktop environment for *nix machines
# Currently this is Linux centric. The detection is based upon the detection
# used by xdg-open from http://portland.freedesktop.org/
class NixDesktopEnvironment
class NotFoundError < Launchy::Error; end
extend ::Launchy::DescendantTracker
# Detect the current *nix desktop environment
#
# If the current dekstop environment be detected, the return
# NixDekstopEnvironment::Unknown
def self.detect
found = find_child( :is_current_desktop_environment? )
Launchy.log("Current Desktop environment not found. #{Launchy.bug_report_message}") unless found
return found
end
def self.fallback_browsers
%w[ firefox iceweasel seamonkey opera mozilla netscape galeon links lynx ].map { |x| ::Launchy::Argv.new( x ) }
end
def self.browsers
[ browser, fallback_browsers ].flatten
end
#---------------------------------------
# The list of known desktop environments
#---------------------------------------
class Kde < NixDesktopEnvironment
def self.is_current_desktop_environment?
ENV['KDE_FULL_SESSION'] &&
Launchy::Application.find_executable( 'kde-open' )
end
def self.browser
::Launchy::Argv.new( 'kde-open' )
end
end
class Gnome < NixDesktopEnvironment
def self.is_current_desktop_environment?
ENV['GNOME_DESKTOP_SESSION_ID'] &&
Launchy::Application.find_executable( 'gnome-open' )
end
def self.browser
::Launchy::Argv.new( 'gnome-open' )
end
end
class Xfce < NixDesktopEnvironment
def self.is_current_desktop_environment?
if Launchy::Application.find_executable( 'xprop' ) then
%x[ xprop -root _DT_SAVE_MODE].include?("xfce")
else
false
end
end
def self.browser
::Launchy::Argv.new( %w[ exo-open --launch WebBrowser ] )
end
end
# Fall back environment as the last case
class Xdg < NixDesktopEnvironment
def self.is_current_desktop_environment?
Launchy::Application.find_executable( browser )
end
def self.browser
::Launchy::Argv.new( 'xdg-open' )
end
end
# The one that is found when all else fails. And this must be declared last
class NotFound < NixDesktopEnvironment
def self.is_current_desktop_environment?
true
end
def self.browser
::Launchy::Argv.new
end
end
end
end