Fixed a few issues and added --update-desktop flag

This commit is contained in:
Tristan Ancelet 2024-11-05 09:21:10 -06:00
parent 77eb648a9a
commit 3be7c31aa5

View File

@ -31,6 +31,8 @@ class Dir
end
end
alias to_s path
## For backwards compat
def chdir(dir = nil, &block)
if dir.nil?
@ -70,18 +72,18 @@ $CONFIG[:discord_version_file] = $CONFIG[:discord_path] / 'resources' / 'build_i
$CONFIG[:action] = 'install'
$CONFIG[:keep_installer] = false
$CONFIG[:debug] = false
DISCORD_DESKTOP_CONTENTS=<<EOF
DISCORD_DESKTOP_TEMPLATE = ERB.new(<<ERB, trim_mode:'-')
[Desktop Entry]
Name=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.
GenericName=Internet Messenger
Exec=#{$CONFIG[:discord_dir]}/Discord
Exec=<%= $CONFIG[:discord_path] %>/Discord
Icon=discord
Type=Application
Categories=Network;InstantMessaging;
Path=#{$CONFIG[:discord_path]}
EOF
Path=<%= $CONFIG[:discord_path] %>
ERB
# END: Variables
@ -116,6 +118,10 @@ OptionParser.new do |parser|
end
end
parser.on('--update-desktop', "Update desktop file"){
$CONFIG[:action] = 'update-desktop'
}
parser.separator ""
parser.separator " General Flags"
parser.separator "------------------------------------------------------------------------"
@ -219,7 +225,7 @@ def update_desktop_file
if File.exist?($CONFIG[:desktop_path])
puts "update_desktop_file: Desktop file exists, checking if it matches template"
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"
file_needs_updating = false
end
@ -229,7 +235,7 @@ def update_desktop_file
if file_needs_updating
File.open($CONFIG[:desktop_path], 'w') do |file|
puts "update_desktop_file: Desktop File was written"
file.write(DISCORD_DESKTOP_CONTENTS)
file.write(DISCORD_DESKTOP_TEMPLATE.result(binding))
end
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
files[:files].each_with_index { |file, i|
puts "make_backup : files : Backing up #{file} (#{i+1}/#{file_count})" if $CONFIG[:debug]
EOF
File.open(file, 'rb') { |file_to_archive|
contents = file_to_archive.read()
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'
make_backup
when 'update-desktop'
update_desktop_file
end
# END: Work