Skip to content

Commit

Permalink
Merge pull request #103 from elvetemedve/feature/add-gnome-47-compati…
Browse files Browse the repository at this point in the history
…bility-fixes

Feature/add gnome 47 compatibility fixes
  • Loading branch information
elvetemedve authored Oct 14, 2024
2 parents ee1bbea + 1f872d9 commit 574a885
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@v1.161.0
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
- name: Run tests
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ task :uninstall, [:target] do |t, args|
raise "Unknown option for target '#{args.target}'."
end

if File.exists? "#{target_dir}/#{PACKAGE_NAME}"
if File.exist? "#{target_dir}/#{PACKAGE_NAME}"
rm_r "#{target_dir}/#{PACKAGE_NAME}"
puts message
end
Expand All @@ -75,7 +75,7 @@ end

desc "Clean up build artifacts"
task :cleanup do
if File.exists? BUILD_DIRECTORY
if File.exist? BUILD_DIRECTORY
rm_r BUILD_DIRECTORY
end
puts "Project is clean"
Expand Down
10 changes: 5 additions & 5 deletions [email protected]/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ IconFactory.prototype.create = function(type, options, can_show_activity, extens
throw new RangeError('Unknown indicator type "' + type + '" given.');
}

let range = [
{ red:190, green: 190, blue: 190 },
{ red:255, green: 204, blue: 0 },
{ red:255, green: 0, blue: 0 }
let color_range = [
new Util.Color(190, 190, 190),
new Util.Color(255, 204, 0),
new Util.Color(255, 0, 0)
];
let caution_class = 'indicator-caution';

return new IconFactory.prototype.concreteClass(constructor_options, range, caution_class, can_show_activity);
return new IconFactory.prototype.concreteClass(constructor_options, color_range, caution_class, can_show_activity);
};

AbstractFactory.registerObject('icon', IconFactory);
Expand Down
36 changes: 11 additions & 25 deletions [email protected]/indicator.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
"use strict";

import Clutter from 'gi://Clutter';
import * as Util from './util.js';

import GObject from 'gi://GObject';
import St from 'gi://St';

export const Icon = GObject.registerClass(
class Icon extends St.Icon {
_init(options, colors, caution_class, can_show_activity) {
_init(options, color_range, caution_class, can_show_activity) {
super._init(options);
this.initColorRange(colors);
this.color_range = color_range;
this.initCautionClass(caution_class);
this.initCanShowActivity(can_show_activity);
}
});

// Take an array of color defined by RGB components and set it static.
Icon.prototype.initColorRange = function(colors) {
if (!this.color_range) {
this.color_range = [];
}
if (this.color_range.length == 0) {
for (let i in colors) {
this.color_range.push(new Clutter.Color(colors[i]));
}
}
}

// Set static CSS class name.
Icon.prototype.initCautionClass = function(name) {
this.caution_class = name;
Expand All @@ -47,20 +36,17 @@ Icon.prototype.setProgress = function(percent) {
return this;
}

var split_value = (this.color_range.length - 1) * percent / 100;
var progress = split_value == this.color_range.length -1 ? 1 : split_value % 1;
let ratio = percent / 100;
let split_value = (this.color_range.length - 1) * ratio;
let progress = split_value == this.color_range.length -1 ? 1 : split_value % 1;
if (split_value == Math.round(split_value)) {
split_value += split_value + 0.1 < this.color_range.length - 1 ? 0.1 : -0.1;
}
var initial_color = this.color_range[Math.floor(split_value)];
var final_color = this.color_range[Math.ceil(split_value)];
var color = initial_color.interpolate(final_color, progress);
let initial_color = this.color_range[Math.floor(split_value)];
let final_color = this.color_range[Math.ceil(split_value)];
let color = initial_color.interpolate(final_color, ratio);

this.style = 'color: rgb(' +
color.red + ',' +
color.green + ',' +
color.blue +
');';
this.style = `color: ${color.toString()}`;

return this;
};
Expand Down
4 changes: 2 additions & 2 deletions [email protected]/metadata.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"shell-version": ["45","46"],
"shell-version": ["45","46","47"],
"uuid": "[email protected]",
"name": "System Monitor",
"description": "Display resource usage.\n\nLinux distribution specific installation instructions can be found in the wiki at https://github.com/elvetemedve/gnome-shell-extension-system-monitor/wiki/Installation.\n\nPlease report bugs here: https://github.com/elvetemedve/gnome-shell-extension-system-monitor/issues",
"settings-schema": "org.gnome.shell.extensions.system-monitor",
"gettext-domain": "[email protected]",
"url": "https://github.com/elvetemedve/gnome-shell-extension-system-monitor",
"version": "36"
"version": "37"
}
28 changes: 28 additions & 0 deletions [email protected]/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ import * as Util from 'resource:///org/gnome/shell/misc/util.js';
import * as FactoryModule from './factory.js';
import * as AsyncModule from './helpers/async.js';

export class Color {
#r;
#g;
#b;

constructor (red, green, blue) {
this.#r = red;
this.#g = green;
this.#b = blue;
}

interpolate(color, ratio) {
// Ensure the ratio is between 0 and 1
ratio = Math.max(0, Math.min(1, ratio));

// Interpolate each color channel
let r = Math.round(this.#r + ratio * (color.#r - this.#r));
let g = Math.round(this.#g + ratio * (color.#g - this.#g));
let b = Math.round(this.#b + ratio * (color.#b - this.#b));

return new Color(r, g, b);
}

toString() {
return `rgb(${this.#r},${this.#g},${this.#b})`;
}
}

export class Process {
constructor(id) {
this._id = id;
Expand Down

0 comments on commit 574a885

Please sign in to comment.