Fix some problems, rename objects

This commit is contained in:
UshakovVasilii
2014-06-12 15:42:11 +04:00
parent 469d6d24f2
commit f5055c948f
7 changed files with 78 additions and 55 deletions

View File

@@ -1,8 +1,32 @@
/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
Copyright (c) 2011-2012, Giovanni Campagna <scampa.giovanni@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the GNOME nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
const Gettext = imports.gettext;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Config = imports.misc.config;
const ExtensionUtils = imports.misc.extensionUtils;
@@ -30,20 +54,6 @@ function initTranslations(domain) {
Gettext.bindtextdomain(domain, Config.LOCALEDIR);
}
/**
* initIcons:
*
* Initialize Gtk to load icons from extensionsdir/icons.
*/
function initIcons() {
let extension = ExtensionUtils.getCurrentExtension();
let theme = Gtk.IconTheme.get_default();
let iconDir = extension.dir.get_child('icons');
if(iconDir.query_exists(null))
theme.append_search_path(iconDir.get_path());
}
/**
* getSettings:
* @schema: (optional): the GSettings schema id

View File

@@ -5,22 +5,23 @@ const PopupMenu = imports.ui.popupMenu;
const Main = imports.ui.main;
const Util = imports.misc.util;
const Mainloop = imports.mainloop;
const Shell = imports.gi.Shell;
const Clutter = imports.gi.Clutter;
const Gio = imports.gi.Gio;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Shell = imports.gi.Shell;
const Utilities = Me.imports.utilities;
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
const _ = Gettext.gettext;
const Clutter = imports.gi.Clutter;
let settings;
let metadata = Me.metadata;
const SensorsItem = new Lang.Class({
Name: 'SensorsItem',
const FreonItem = new Lang.Class({
Name: 'FreonItem',
Extends: PopupMenu.PopupBaseMenuItem,
_init: function(type, label, value) {
_init: function(gIcon, label, value) {
this.parent();
this.connect('activate', function () {
settings.set_string('main-sensor', label);
@@ -28,7 +29,7 @@ const SensorsItem = new Lang.Class({
this._label = label;
this._value = value;
this.actor.add(new St.Icon({ style_class: 'system-status-icon', icon_name: 'sensors-'+type+'-symbolic' }));
this.actor.add(new St.Icon({ style_class: 'system-status-icon', gicon : gIcon}));
this.actor.add(new St.Label({text: label}));
this.actor.add(new St.Label({text: value}), {align: St.Align.END});
},
@@ -49,8 +50,8 @@ const SensorsItem = new Lang.Class({
},
});
const SensorsMenuButton = new Lang.Class({
Name: 'SensorsMenuButton',
const FreonMenuButton = new Lang.Class({
Name: 'FreonMenuButton',
Extends: PanelMenu.Button,
@@ -60,6 +61,10 @@ const SensorsMenuButton = new Lang.Class({
this._sensorsOutput = '';
this._hddtempOutput = '';
this._temperatureGIcon = Gio.icon_new_for_string(Me.path + '/icons/sensors-temperature-symbolic.svg');
this._voltageGIcon = Gio.icon_new_for_string(Me.path + '/icons/sensors-voltage-symbolic.svg');
this._fanGIcon = Gio.icon_new_for_string(Me.path + '/icons/sensors-fan-symbolic.svg');
this.statusLabel = new St.Label({ text: '\u2026', y_expand: true, y_align: Clutter.ActorAlign.CENTER });
this.menu.removeAll();
@@ -91,6 +96,15 @@ const SensorsMenuButton = new Lang.Class({
},
_onDestroy: function(){
for each (let proxy in this.udisksProxies){
if(proxy.drive){
proxy.drive.run_dispose();
}
if(proxy.ata){
proxy.ata.run_dispose();
}
}
Mainloop.source_remove(this._eventLoop);
this.menu.removeAll();
settings.disconnect(this._settingsChanged);
@@ -152,33 +166,33 @@ const SensorsMenuButton = new Lang.Class({
if (temp['temp'] > max)
max = temp['temp'];
sensorsList.push(new SensorsItem('temperature', temp['label'], this._formatTemp(temp['temp'])));
sensorsList.push(new FreonItem(this._temperatureGIcon, temp['label'], this._formatTemp(temp['temp'])));
}
if (tempInfo.length > 0){
sensorsList.push(new PopupMenu.PopupSeparatorMenuItem());
// Add average and maximum entries
sensorsList.push(new SensorsItem('temperature', _("Average"), this._formatTemp(sum/tempInfo.length)));
sensorsList.push(new SensorsItem('temperature', _("Maximum"), this._formatTemp(max)));
sensorsList.push(new FreonItem(this._temperatureGIcon, _("Average"), this._formatTemp(sum/tempInfo.length)));
sensorsList.push(new FreonItem(this._temperatureGIcon, _("Maximum"), this._formatTemp(max)));
if(fanInfo.length > 0 || voltageInfo.length > 0)
sensorsList.push(new PopupMenu.PopupSeparatorMenuItem());
}
for each (let fan in fanInfo){
sensorsList.push(new SensorsItem('fan', fan['label'], _("%drpm").format(fan['rpm'])));
sensorsList.push(new FreonItem(this._fanGIcon, fan['label'], _("%drpm").format(fan['rpm'])));
}
if (fanInfo.length > 0 && voltageInfo.length > 0){
sensorsList.push(new PopupMenu.PopupSeparatorMenuItem());
}
for each (let voltage in voltageInfo){
sensorsList.push(new SensorsItem('voltage', voltage['label'], _("%s%.2fV").format(((voltage['volt'] >= 0) ? '+' : '-'), voltage['volt'])));
sensorsList.push(new FreonItem(this._voltageGIcon, voltage['label'], _("%s%.2fV").format(((voltage['volt'] >= 0) ? '+' : '-'), voltage['volt'])));
}
this.statusLabel.set_text(_("N/A")); // Just in case
for each (let item in sensorsList) {
if(item instanceof SensorsItem) {
if(item instanceof FreonItem) {
if (settings.get_string('main-sensor') == item.getLabel()) {
// Configure as main sensor and set panel string
@@ -199,11 +213,11 @@ const SensorsMenuButton = new Lang.Class({
item.actor.add(new St.Label({ text: _("Sensors Settings") }));
item.connect('activate', function () {
Util.spawn(["gnome-shell-extension-prefs", metadata.uuid]);
Util.spawn(["gnome-shell-extension-prefs", Me.metadata.uuid]);
});
section.addMenuItem(item);
}else{
} else {
this.statusLabel.set_text(_("Error"));
let item = new PopupMenu.PopupMenuItem(
@@ -212,7 +226,7 @@ const SensorsMenuButton = new Lang.Class({
: _("Please install lm_sensors.")) + "\n" + _("If this doesn\'t help, click here to report with your sensors output!")
);
item.connect('activate',function() {
Util.spawn(["xdg-open", "http://github.com/xtranophilist/gnome-shell-extension-sensors/issues/"]);
Util.spawn(["xdg-open", "https://github.com/UshakovVasilii/gnome-shell-extension-freon/issues"]);
});
section.addMenuItem(item);
}
@@ -240,20 +254,19 @@ const SensorsMenuButton = new Lang.Class({
}
});
let sensorsMenu;
let freonMenu;
function init(extensionMeta) {
Convenience.initTranslations();
Convenience.initIcons();
settings = Convenience.getSettings();
}
function enable() {
sensorsMenu = new SensorsMenuButton();
Main.panel.addToStatusArea('sensorsMenu', sensorsMenu, 1, 'right');
freonMenu = new FreonMenuButton();
Main.panel.addToStatusArea('freonMenu', freonMenu, 1, 'right');
}
function disable() {
sensorsMenu.destroy();
sensorsMenu = null;
freonMenu.destroy();
freonMenu = null;
}

View File

@@ -1,5 +1,5 @@
{
"shell-version": ["3.10","3.12"],
"shell-version": ["3.12"],
"uuid": "freon@UshakovVasilii_Github.yahoo.com",
"name": "Freon",
"description": "Shows CPU temperature, HDD temperature, voltage and fan RPM (forked from xtranophilist/gnome-shell-extension-sensors)",

View File

@@ -19,9 +19,9 @@ function init() {
Convenience.initTranslations();
}
const SensorsPrefsWidget = new GObject.Class({
Name: 'Sensors.Prefs.Widget',
GTypeName: 'SensorsPrefsWidget',
const FreonPrefsWidget = new GObject.Class({
Name: 'Freon.Prefs.Widget',
GTypeName: 'FreonPrefsWidget',
Extends: Gtk.Grid,
_init: function(params) {
@@ -239,7 +239,7 @@ const SensorsPrefsWidget = new GObject.Class({
});
function buildPrefsWidget() {
let widget = new SensorsPrefsWidget();
let widget = new FreonPrefsWidget();
widget.show_all();
return widget;
}

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="gse-sensors">
<schema id="org.gnome.shell.extensions.freon" path="/org/gnome/shell/extensions/">
<schema id="org.gnome.shell.extensions.freon" path="/org/gnome/shell/extensions/freon/">
<key type="i" name="update-time">
<default>15</default>

View File

@@ -7,18 +7,18 @@ const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
const _ = Gettext.gettext;
const UDisksDriveProxy = Gio.DBusProxy.makeProxyWrapper(
'<node>'\
' <interface name="org.freedesktop.UDisks2.Drive">'\
' <property type="s" name="Model" access="read"/>'\
' </interface>'\
'</node>');
'<node> \
<interface name="org.freedesktop.UDisks2.Drive"> \
<property type="s" name="Model" access="read"/> \
</interface> \
</node>');
const UDisksDriveAtaProxy = Gio.DBusProxy.makeProxyWrapper(
'<node>'\
' <interface name="org.freedesktop.UDisks2.Drive.Ata">'\
' <property type="d" name="SmartTemperature" access="read"/>'\
' </interface>'\
'</node>');
'<node> \
<interface name="org.freedesktop.UDisks2.Drive.Ata"> \
<property type="d" name="SmartTemperature" access="read"/> \
</interface> \
</node>');
function detectSensors() {
let path = GLib.find_program_in_path('sensors');