Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement of Gnome Extension Detection Logic #15

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/fusuma/plugin/appmatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require "fusuma/plugin/appmatcher/version"

require "fusuma/plugin/appmatcher/x11"
require "fusuma/plugin/appmatcher/gnome"
require "fusuma/plugin/appmatcher/gnome_extension"
require "fusuma/plugin/appmatcher/gnome_extensions/installer"
require "fusuma/plugin/appmatcher/unsupported_backend"
Expand All @@ -22,12 +21,19 @@ def backend_klass
when /wayland/
case xdg_current_desktop
when /GNOME/
return GnomeExtension if GnomeExtensions::Installer.new.installed?

return Gnome
if GnomeExtensions::Installer.new.enabled?
return GnomeExtension
else
MultiLogger.warn "Appmatcher Gnome Shell Extension is NOT enabled"
MultiLogger.warn "Please enable it by running the following command:"
MultiLogger.warn ""
MultiLogger.warn "$ fusuma-appmatcher --install-gnome-extension"
MultiLogger.warn ""
end
end
end

MultiLogger.warn "appmatcher doesn't support"
UnsupportedBackend
end

Expand Down
125 changes: 0 additions & 125 deletions lib/fusuma/plugin/appmatcher/gnome.rb

This file was deleted.

43 changes: 24 additions & 19 deletions lib/fusuma/plugin/appmatcher/gnome_extensions/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ module GnomeExtensions
class Installer
include UserSwitcher

EXTENSION = "./[email protected]"

def gnome_shell_extension_path
output = `gnome-shell --version`
version = output.match(/GNOME Shell (\d+\.\d+)/)

if version
version_number = version[1].to_f
if version_number >= 45.0
"./[email protected]"
else
"./[email protected]"
end
else
"./[email protected]"
end
end

def install
pid = as_user(proctitle: self.class.name.underscore) do |user|
FileUtils.cp_r(source_path, install_path(user.username))
Expand All @@ -52,18 +34,41 @@ def installed?
File.exist?(install_path)
end

def enabled?
enabled_extensions = `gsettings get org.gnome.shell enabled-extensions`.strip
enabled_extensions.include?(EXTENSION)
end

private

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

EXTENSION = "[email protected]"
EXTENSION45 = "[email protected]"
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(gnome_shell_extension_path, __dir__)
File.expand_path(gnome_shell_extension_filename, __dir__)
end

def gnome_shell_extension_filename
output = `gnome-shell --version`
version = output.match(/GNOME Shell (\d+\.\d+)/)

if version
version_number = version[1].to_f
if version_number >= 45.0
EXTENSION45
else
EXTENSION
end
else
EXTENSION
end
end

def login_username
Expand Down
3 changes: 0 additions & 3 deletions lib/fusuma/plugin/appmatcher/unsupported_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ def watch_start
end

class Matcher
def initialize
end

def running_applications
warn
nil
Expand Down
58 changes: 52 additions & 6 deletions spec/fusuma/plugin/appmatcher/gnome_extensions/installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,65 @@ module Plugin
module Appmatcher
module GnomeExtensions
RSpec.describe Installer do
let(:installer) { described_class.new }
let(:user) { UserSwitcher::User.new("user") }

describe "#install" do
it "should copy file to users dir"
before do
allow(Process).to receive(:waitpid)
allow(installer).to receive(:as_user).and_yield(user) do |block_context|
allow(block_context).to receive(:source_path).and_return("source_path")
allow(block_context).to receive(:install_path).with(user.username).and_return("install_path")
allow(block_context).to receive(:user_extension_dir).with(user.username)
end
end
it "should copy file to user's dir" do
expect(FileUtils).to receive(:cp_r).with(any_args)
installer.install
end
end

describe "#uninstall" do
context "when extension is NOT installed" do
it "should remove file to users dir"
before do
allow(Process).to receive(:waitpid)
allow(installer).to receive(:as_user).and_yield(user) do |block_context|
allow(block_context).to receive(:source_path).and_return("source_path")
allow(block_context).to receive(:install_path).with(user.username).and_return("install_path")
allow(block_context).to receive(:user_extension_dir).with(user.username)
end
end

context "when extension is installed" do
before do
allow(installer).to receive(:installed?).and_return(true)
end
it "should remove file to user's dir" do
expect(FileUtils).to receive(:rm_r).with(any_args)
installer.uninstall
end
end

context "when extension is NOT installed" do
it "should NOT execute"
before do
allow(installer).to receive(:installed?).and_return(false)
end
it "should NOT execute" do
expect(installer).not_to receive(:as_user)
installer.uninstall
end
end
end
describe "#installed?" do
it "check extension is in the installed path"

describe "#enabled?" do
it "returns true if the gnome extension is enabled" do
allow(installer).to receive(:`).with("gsettings get org.gnome.shell enabled-extensions").and_return("['[email protected]']")
expect(installer.enabled?).to be true
end

it "returns false if the gnome extension is not enabled" do
allow(installer).to receive(:`).with("gsettings get org.gnome.shell enabled-extensions").and_return("[]")
expect(installer.enabled?).to be false
end
end
end
end
Expand Down
16 changes: 0 additions & 16 deletions spec/fusuma/plugin/appmatcher/gnome_spec.rb

This file was deleted.

10 changes: 5 additions & 5 deletions spec/fusuma/plugin/appmatcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ module Plugin
context "when XDG_CURRENT_DESKTOP is ubuntu:GNOME" do
before { allow(Appmatcher).to receive(:xdg_current_desktop).and_return("ubuntu:GNOME") }

context "when gnome-extension is installed" do
context "when gnome-extension is enabled" do
before do
allow_any_instance_of(Appmatcher::GnomeExtensions::Installer).to receive(:installed?).and_return(true)
allow_any_instance_of(Appmatcher::GnomeExtensions::Installer).to receive(:enabled?).and_return(true)
end
it { is_expected.to eq Appmatcher::GnomeExtension }
end

context "when gnome-extension is NOT installed" do
context "when gnome-extension is NOT enabled" do
before do
allow_any_instance_of(Appmatcher::GnomeExtensions::Installer).to receive(:installed?).and_return(false)
allow_any_instance_of(Appmatcher::GnomeExtensions::Installer).to receive(:enabled?).and_return(false)
end
it { is_expected.to eq Appmatcher::Gnome }
it { is_expected.to eq Appmatcher::UnsupportedBackend }
end
end

Expand Down
Loading