Sha256: b62dcbb24237fdeb41948a97e3920c3b7fbf175572dd53c222d5727492df5c2f

Contents?: true

Size: 1.73 KB

Versions: 4

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

require_relative "../user_switcher"
require "fileutils"

module Fusuma
  module Plugin
    module Appmatcher
      module GnomeExtensions
        # Install Gnome Extension
        class Installer
          EXTENSION = "./appmatcher@iberianpig.dev"

          def install
            pid = UserSwitcher.new.as_user do |user|
              FileUtils.cp_r(source_path, user_extension_dir(user.username))
              puts "Installed Appmatcher Gnome Shell Extension to #{user_extension_dir(user.username)}"
              puts "Restart your session, then activate Appmatcher on gnome-extensions-app"
            end
            Process.waitpid(pid)
          end

          def uninstall
            return puts "Appmatcher Gnome Shell Extension is not installed in #{user_extension_dir}/" unless installed?

            pid = UserSwitcher.new.as_user do |user|
              FileUtils.rm_r(install_path(user.username))
              puts "Uninstalled Appmatcher Gnome Shell Extension from #{install_path(user.username)}"
            end
            Process.waitpid(pid)
          end

          def installed?
            File.exist?(install_path)
          end

          private

          def user_extension_dir(username = login_username)
            File.expand_path("#{Dir.home(username)}/.local/share/gnome-shell/extensions/")
          end

          def install_path(username = login_username)
            File.expand_path("#{Dir.home(username)}/.local/share/gnome-shell/extensions/#{EXTENSION}")
          end

          def source_path
            File.expand_path(EXTENSION, __dir__)
          end

          def login_username
            UserSwitcher.new.login_user.username
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fusuma-plugin-appmatcher-0.2.3 lib/fusuma/plugin/appmatcher/gnome_extensions/installer.rb
fusuma-plugin-appmatcher-0.2.2 lib/fusuma/plugin/appmatcher/gnome_extensions/installer.rb
fusuma-plugin-appmatcher-0.2.1 lib/fusuma/plugin/appmatcher/gnome_extensions/installer.rb
fusuma-plugin-appmatcher-0.2.0 lib/fusuma/plugin/appmatcher/gnome_extensions/installer.rb