Clean-up globals and eliminate warnings on Gnome-3.26

This commit is contained in:
Olaf Leidinger 2017-11-21 21:33:14 +01:00
parent 5a58727a67
commit ce26373bd7
4 changed files with 69 additions and 60 deletions

View File

@ -1,18 +1,15 @@
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: t -*- */
/* Olaf Leidinger <oleid@mescharet.de>
Thomas Liebetraut <thomas@tommie-lie.de>
*/
const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const Mainloop = imports.mainloop; // timer
const Shell = imports.gi.Shell;
const St = imports.gi.St;
const Clutter = imports.gi.Clutter;
const Layout = imports.ui.layout;
const FileUtils = imports.misc.fileUtils;
const Main = imports.ui.main;
const MessageTray = imports.ui.messageTray;
@ -25,8 +22,6 @@ const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
const Icon = Me.imports.icon;
const bUseGnome34Workarounds = imports.misc.extensionUtils.versionCheck(["3.4"], imports.misc.config.PACKAGE_VERSION);
const _ = Utils.getTranslationFunc();
const N_ = function (e) {
return e;
@ -194,9 +189,9 @@ const TeaTime = new Lang.Class({
},
_createMenu: function () {
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this._settings.connect("changed::" + Utils.TEATIME_STEEP_TIMES_KEY,
this._settings.connect("changed::" + this.config_keys.steep_times,
Lang.bind(this, this._updateTeaList));
this._settings.connect("changed::" + Utils.TEATIME_GRAPHICAL_COUNTDOWN_KEY,
this._settings.connect("changed::" + this.config_keys.graphical_countdown,
Lang.bind(this, this._updateCountdownType));
this.teaItemCont = new PopupMenu.PopupMenuSection();
@ -236,7 +231,7 @@ const TeaTime = new Lang.Class({
this.teaItemCont.removeAll();
// fill with new teas
let list = this._settings.get_value(Utils.TEATIME_STEEP_TIMES_KEY).unpack();
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
for (let teaname in list) {
let time = list[teaname].get_uint32();
@ -248,7 +243,7 @@ const TeaTime = new Lang.Class({
}
},
_updateCountdownType: function (config, output) {
let bWantGraphicalCountdown = this._settings.get_boolean(Utils.TEATIME_GRAPHICAL_COUNTDOWN_KEY);
let bWantGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
if (bWantGraphicalCountdown != this._bGraphicalCountdown) {
if (this._idleTimeout != null) {
@ -286,11 +281,11 @@ const TeaTime = new Lang.Class({
}
},
_showNotification: function (subject, text) {
let source = (bUseGnome34Workarounds) ?
let source = (Utils.isGnome34()) ?
new MessageTray.Source(_("TeaTime applet")) :
new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime');
if (bUseGnome34Workarounds) {
if (Utils.isGnome34()) {
source.createNotificationIcon =
function () {
let iconBox = new St.Bin();
@ -315,7 +310,7 @@ const TeaTime = new Lang.Class({
this._stopTime = new Date();
this._cntdownStart = time;
this._bGraphicalCountdown = this._settings.get_boolean(Utils.TEATIME_GRAPHICAL_COUNTDOWN_KEY);
this._bGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
let dt = this._bGraphicalCountdown ?
Math.max(1.0, time / 90) // set time step to fit animation
@ -355,7 +350,7 @@ const TeaTime = new Lang.Class({
this.actor.add_actor(this._logo);
this._playSound();
if (!bUseGnome34Workarounds && this._settings.get_boolean(Utils.TEATIME_FULLSCREEN_NOTIFICATION_KEY)) {
if (!Utils.isGnome34() && this._settings.get_boolean(this.config_keys.fullscreen_notification)) {
this.dialog = new TeaTimeFullscreenNotification();
this.dialog.show();
} else {
@ -371,9 +366,9 @@ const TeaTime = new Lang.Class({
}
},
_playSound: function () {
let bPlayAlarmSound = this._settings.get_boolean(Utils.TEATIME_USE_ALARM_SOUND_KEY);
let bPlayAlarmSound = this._settings.get_boolean(this.config_keys.use_alarm_sound);
if (bPlayAlarmSound) {
Utils.playSound(this._settings.get_string(Utils.TEATIME_ALARM_SOUND_KEY));
Utils.playSound(this._settings.get_string(this.config_keys.alarm_sound));
}
},
_showPreferences: function () {
@ -404,7 +399,8 @@ const TeaTime = new Lang.Class({
let scaling = Utils.getGlobalDisplayScaleFactor();
this._logo.setScaling(scaling);
this._graphicalTimer.setScaling(scaling);
}
},
config_keys: Utils.GetConfigKeys()
});
function init(metadata) {

View File

@ -17,7 +17,7 @@ const ExUt = imports.misc.extensionUtils;
const Me = ExUt.getCurrentExtension();
const Utils = Me.imports.utils;
const TwoColorIcon = new Lang.Class({
var TwoColorIcon = new Lang.Class({
Name: 'TwoColorIcon',
Extends: St.DrawingArea,
@ -86,7 +86,7 @@ const TwoColorIcon = new Lang.Class({
});
const TeaPot = {
var TeaPot = {
width: 484,
height: 295,
draw: function (cr, stat, primary, secundary) {
@ -130,7 +130,7 @@ const TeaPot = {
}; // TeaPot
const Pie = {
var Pie = {
width: 1,
height: 1,
draw: function (cr, stat, primary, secundary) {

View File

@ -1,14 +1,8 @@
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: t -*- */
/* Olaf Leidinger <oleid@mescharet.de>
Thomas Liebetraut <thomas@tommie-lie.de>
*/
const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Mainloop = imports.mainloop; // timer
const Clutter = imports.gi.Clutter;
const Lang = imports.lang;
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;
@ -17,15 +11,12 @@ const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
const bUseGnome34Workarounds = imports.misc.extensionUtils.versionCheck(["3.4"], imports.misc.config.PACKAGE_VERSION);
const _ = Utils.getTranslationFunc();
const N_ = function (e) {
return e;
};
const Columns = {
TEA_NAME: 0,
STEEP_TIME: 1,
@ -104,7 +95,7 @@ const TeaTimePrefsWidget = new Lang.Class({
this.alarmSoundFile.connect("selection_changed", Lang.bind(this, this._saveSoundFile));
if (!bUseGnome34Workarounds) {
if (!Utils.isGnome34()) {
// Full screen notifications currently not working on GNOME 3.4, thus don't show the switch
this.attach(labelFN, 0 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
this.attach(this.fullscreenNotificationSwitch, 2, curRow, 1, 1);
@ -191,12 +182,13 @@ const TeaTimePrefsWidget = new Lang.Class({
if (this._inhibitUpdate)
return;
this.fullscreenNotificationSwitch.active = this._settings.get_boolean(Utils.TEATIME_FULLSCREEN_NOTIFICATION_KEY)
this.fullscreenNotificationSwitch.active = this._settings.get_boolean(this.config_keys.fullscreen_notification)
this.graphicalCountdownSwitch.active = this._settings.get_boolean(Utils.TEATIME_GRAPHICAL_COUNTDOWN_KEY)
this.alarmSoundSwitch.active = this._settings.get_boolean(Utils.TEATIME_USE_ALARM_SOUND_KEY)
let list = this._settings.get_value(Utils.TEATIME_STEEP_TIMES_KEY).unpack();
this.alarmSoundFile.set_uri(this._settings.get_string(Utils.TEATIME_ALARM_SOUND_KEY));
this.graphicalCountdownSwitch.active = this._settings.get_boolean(this.config_keys.graphical_countdown)
this.alarmSoundSwitch.active = this._settings.get_boolean(this.config_keys.use_alarm_sound)
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
let file_name = this._settings.get_string(this.config_keys.alarm_sound);
this.alarmSoundFile.set_uri(file_name);
// stop everyone from reacting to the changes we are about to produce
// in the model
@ -251,7 +243,7 @@ const TeaTimePrefsWidget = new Lang.Class({
if (this._inhibitUpdate)
return;
this._inhibitUpdate = true;
this._settings.set_boolean(Utils.TEATIME_FULLSCREEN_NOTIFICATION_KEY,
this._settings.set_boolean(this.config_keys.fullscreen_notification,
sw.active);
this._inhibitUpdate = false;
},
@ -260,7 +252,7 @@ const TeaTimePrefsWidget = new Lang.Class({
if (this._inhibitUpdate)
return;
this._inhibitUpdate = true;
this._settings.set_boolean(Utils.TEATIME_GRAPHICAL_COUNTDOWN_KEY,
this._settings.set_boolean(this.config_keys.graphical_countdown,
sw.active);
this._inhibitUpdate = false;
},
@ -269,7 +261,7 @@ const TeaTimePrefsWidget = new Lang.Class({
if (this._inhibitUpdate)
return;
this._inhibitUpdate = true;
this._settings.set_boolean(Utils.TEATIME_USE_ALARM_SOUND_KEY,
this._settings.set_boolean(this.config_keys.use_alarm_sound,
sw.active);
this._inhibitUpdate = false;
},
@ -277,17 +269,23 @@ const TeaTimePrefsWidget = new Lang.Class({
// don't update the backend if someone else is messing with the model
if (this._inhibitUpdate)
return;
if (this._settings.get_string(Utils.TEATIME_ALARM_SOUND_KEY) != this.alarmSoundFile.get_uri()) {
let alarm_sound = this.alarmSoundFile.get_uri();
Utils.debug(this._settings.get_string(this.config_keys.alarm_sound) + "-->" + alarm_sound);
let have_value = Utils.isType(alarm_sound, "string");
let setting_is_different =
this._settings.get_string(this.config_keys.alarm_sound) != alarm_sound;
if (have_value && setting_is_different) {
this._inhibitUpdate = true;
let uri = this.alarmSoundFile.get_uri();
Utils.playSound(uri);
this._settings.set_string(Utils.TEATIME_ALARM_SOUND_KEY, uri);
Utils.playSound(alarm_sound);
this._settings.set_string(this.config_keys.alarm_sound, alarm_sound);
this._inhibitUpdate = false;
}
},
_save: function (store, path_, iter_) {
const GLib = imports.gi.GLib;
// don't update the backend if someone else is messing with the model
if (this._inhibitUpdate)
return;
@ -304,10 +302,11 @@ const TeaTimePrefsWidget = new Lang.Class({
// disable updating it here to avoid an infinite loop
this._inhibitUpdate = true;
this._settings.set_value(Utils.TEATIME_STEEP_TIMES_KEY, settingsValue);
this._settings.set_value(this.config_keys.steep_times, settingsValue);
this._inhibitUpdate = false;
}
},
config_keys: Utils.GetConfigKeys()
});

View File

@ -1,20 +1,9 @@
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: t -*- */
/* Olaf Leidinger <oleid@mescharet.de>
Thomas Liebetraut <thomas@tommie-lie.de>
*/
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Config = imports.misc.config;
const Gst = imports.gi.Gst;
const TEATIME_STEEP_TIMES_KEY = 'steep-times';
const TEATIME_FULLSCREEN_NOTIFICATION_KEY = 'fullscreen-notification';
const TEATIME_GRAPHICAL_COUNTDOWN_KEY = 'graphical-countdown';
const TEATIME_USE_ALARM_SOUND_KEY = 'use-alarm-sound';
const TEATIME_ALARM_SOUND_KEY = 'alarm-sound-file';
const ENABLE_LOGGING = false;
@ -23,6 +12,16 @@ function debug(text) {
log("**TeaTime >: " + text);
}
function GetConfigKeys() {
return {
steep_times: 'steep-times',
fullscreen_notification: 'fullscreen-notification',
graphical_countdown: 'graphical-countdown',
use_alarm_sound: 'use-alarm-sound',
alarm_sound: 'alarm-sound-file'
};
}
function getExtensionLocaleDir() {
// check if this extension was built with "make zip-file", and thus
// has the locale files in a subfolder
@ -31,7 +30,7 @@ function getExtensionLocaleDir() {
let localLocaleDir = ExtensionUtils.getCurrentExtension().dir.get_child('locale');
let selectedDir = (localLocaleDir.query_exists(null)) ?
localLocaleDir.get_path() :
Config.LOCALEDIR;
imports.misc.config.LOCALEDIR;
debug("Using locale dir: " + selectedDir);
@ -58,6 +57,8 @@ function getTranslationFunc() {
}
function getSettings(schema) {
const Gio = imports.gi.Gio;
let extension = ExtensionUtils.getCurrentExtension();
schema = schema || extension.metadata['settings-schema'];
@ -114,8 +115,13 @@ function formatTime(sec_num) {
}
function playSound(uri) {
const Gst = imports.gi.Gst;
const Lang = imports.lang;
debug("Playing " + uri);
if (typeof this.player == 'undefined') {
Gst.init(null, 0);
Gst.init(null);
this.player = Gst.ElementFactory.make("playbin", "player");
this.playBus = this.player.get_bus();
this.playBus.add_signal_watch();
@ -143,3 +149,11 @@ function getGlobalDisplayScaleFactor() {
const St = imports.gi.St;
return St.ThemeContext.get_for_stage(global.stage).scale_factor;
}
function isType(value, typename) {
return typeof value == typename;
}
function isGnome34() {
return imports.misc.extensionUtils.versionCheck(["3.4"], imports.misc.config.PACKAGE_VERSION);
}