Fixed a few issues and added --update-desktop flag
This commit is contained in:
parent
77eb648a9a
commit
3be7c31aa5
@ -31,6 +31,8 @@ class Dir
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias to_s path
|
||||||
|
|
||||||
## For backwards compat
|
## For backwards compat
|
||||||
def chdir(dir = nil, &block)
|
def chdir(dir = nil, &block)
|
||||||
if dir.nil?
|
if dir.nil?
|
||||||
@ -70,18 +72,18 @@ $CONFIG[:discord_version_file] = $CONFIG[:discord_path] / 'resources' / 'build_i
|
|||||||
$CONFIG[:action] = 'install'
|
$CONFIG[:action] = 'install'
|
||||||
$CONFIG[:keep_installer] = false
|
$CONFIG[:keep_installer] = false
|
||||||
$CONFIG[:debug] = false
|
$CONFIG[:debug] = false
|
||||||
DISCORD_DESKTOP_CONTENTS=<<EOF
|
DISCORD_DESKTOP_TEMPLATE = ERB.new(<<ERB, trim_mode:'-')
|
||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
Name=Discord
|
Name=Discord
|
||||||
StartupWMClass=discord
|
StartupWMClass=discord
|
||||||
Comment=All-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone.
|
Comment=All-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone.
|
||||||
GenericName=Internet Messenger
|
GenericName=Internet Messenger
|
||||||
Exec=#{$CONFIG[:discord_dir]}/Discord
|
Exec=<%= $CONFIG[:discord_path] %>/Discord
|
||||||
Icon=discord
|
Icon=discord
|
||||||
Type=Application
|
Type=Application
|
||||||
Categories=Network;InstantMessaging;
|
Categories=Network;InstantMessaging;
|
||||||
Path=#{$CONFIG[:discord_path]}
|
Path=<%= $CONFIG[:discord_path] %>
|
||||||
EOF
|
ERB
|
||||||
# END: Variables
|
# END: Variables
|
||||||
|
|
||||||
|
|
||||||
@ -116,6 +118,10 @@ OptionParser.new do |parser|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
parser.on('--update-desktop', "Update desktop file"){
|
||||||
|
$CONFIG[:action] = 'update-desktop'
|
||||||
|
}
|
||||||
|
|
||||||
parser.separator ""
|
parser.separator ""
|
||||||
parser.separator " General Flags"
|
parser.separator " General Flags"
|
||||||
parser.separator "------------------------------------------------------------------------"
|
parser.separator "------------------------------------------------------------------------"
|
||||||
@ -219,7 +225,7 @@ def update_desktop_file
|
|||||||
if File.exist?($CONFIG[:desktop_path])
|
if File.exist?($CONFIG[:desktop_path])
|
||||||
puts "update_desktop_file: Desktop file exists, checking if it matches template"
|
puts "update_desktop_file: Desktop file exists, checking if it matches template"
|
||||||
File.open($CONFIG[:desktop_path], 'r') do |file|
|
File.open($CONFIG[:desktop_path], 'r') do |file|
|
||||||
if file.read() == DISCORD_DESKTOP_CONTENTS
|
if file.read() == DISCORD_DESKTOP_TEMPLATE.result(binding)
|
||||||
puts "update_desktop_file: Desktop file matches template. Not updating"
|
puts "update_desktop_file: Desktop file matches template. Not updating"
|
||||||
file_needs_updating = false
|
file_needs_updating = false
|
||||||
end
|
end
|
||||||
@ -229,7 +235,7 @@ def update_desktop_file
|
|||||||
if file_needs_updating
|
if file_needs_updating
|
||||||
File.open($CONFIG[:desktop_path], 'w') do |file|
|
File.open($CONFIG[:desktop_path], 'w') do |file|
|
||||||
puts "update_desktop_file: Desktop File was written"
|
puts "update_desktop_file: Desktop File was written"
|
||||||
file.write(DISCORD_DESKTOP_CONTENTS)
|
file.write(DISCORD_DESKTOP_TEMPLATE.result(binding))
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "update_desktop_file: Triggering desktop to install new desktop entry and refresh entries"
|
puts "update_desktop_file: Triggering desktop to install new desktop entry and refresh entries"
|
||||||
@ -271,6 +277,7 @@ def make_backup
|
|||||||
file_count = files[:files].count
|
file_count = files[:files].count
|
||||||
files[:files].each_with_index { |file, i|
|
files[:files].each_with_index { |file, i|
|
||||||
puts "make_backup : files : Backing up #{file} (#{i+1}/#{file_count})" if $CONFIG[:debug]
|
puts "make_backup : files : Backing up #{file} (#{i+1}/#{file_count})" if $CONFIG[:debug]
|
||||||
|
EOF
|
||||||
File.open(file, 'rb') { |file_to_archive|
|
File.open(file, 'rb') { |file_to_archive|
|
||||||
contents = file_to_archive.read()
|
contents = file_to_archive.read()
|
||||||
tar.add_file_simple(file_to_archive.path.sub("#{Dir.home}/",''), file_to_archive.stat.mode, contents.length) { |io|
|
tar.add_file_simple(file_to_archive.path.sub("#{Dir.home}/",''), file_to_archive.stat.mode, contents.length) { |io|
|
||||||
@ -331,6 +338,9 @@ case $CONFIG[:action]
|
|||||||
when 'backup'
|
when 'backup'
|
||||||
make_backup
|
make_backup
|
||||||
|
|
||||||
|
when 'update-desktop'
|
||||||
|
update_desktop_file
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# END: Work
|
# END: Work
|
||||||
|
Loading…
Reference in New Issue
Block a user