-
-
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.
Merge pull request #15 from iberianpig/improve-gnome-extension-matcher
Improvement of Gnome Extension Detection Logic
- Loading branch information
Showing
7 changed files
with
91 additions
and
178 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 was deleted.
Oops, something went wrong.
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,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 | ||
|
This file was deleted.
Oops, something went wrong.
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