-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enhance Gnome Extensions Installer
- Added `enabled?` method to check if the Gnome Shell extension is enabled. - Improved `backend_klass` method to log a warning if the Gnome extension is not enabled. - Updated the installer path handling for better clarity and maintainability. - Added RSpec tests for the new `enabled?` method, covering scenarios for when the extension is enabled and when it is not. - Enhanced existing tests for install and uninstall methods to ensure they correctly reflect the extension management logic. ref: iberianpig/fusuma#332 closes: iberianpig/fusuma#323
- Loading branch information
1 parent
1f34f45
commit 0ca1707
Showing
5 changed files
with
88 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,9 +29,6 @@ def watch_start | |
end | ||
|
||
class Matcher | ||
def initialize | ||
end | ||
|
||
def running_applications | ||
warn | ||
nil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,62 @@ 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 | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters