Move non-dependencies of prefs window from convenience.js into utils.js

Fixes issue with settings panel freezing when opened 2nd time. Maintains similar file structure with Dash-to-Dock following commit 9350417f090ac2a3a253551e6629d634a28a6b2a
This commit is contained in:
Jason DeRose
2018-08-02 11:58:25 -04:00
parent 53fa3c557f
commit 10c11310b5
9 changed files with 195 additions and 174 deletions

View File

@@ -2,7 +2,7 @@
UUID = dash-to-panel@jderose9.github.com
BASE_MODULES = extension.js stylesheet.css metadata.json COPYING README.md
EXTRA_MODULES = appIcons.js convenience.js panel.js intellihide.js panelStyle.js overview.js taskbar.js windowPreview.js prefs.js Settings.ui
EXTRA_MODULES = appIcons.js convenience.js panel.js intellihide.js panelStyle.js overview.js taskbar.js windowPreview.js prefs.js utils.js Settings.ui
EXTRA_IMAGES = highlight_stacked_bg.svg
TOLOCALIZE = prefs.js appIcons.js
MSGSRC = $(wildcard po/*.po)

View File

@@ -47,7 +47,7 @@ const Util = imports.misc.util;
const Workspace = imports.ui.workspace;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Utils = Me.imports.utils;
const WindowPreview = Me.imports.windowPreview;
const Taskbar = Me.imports.taskbar;
@@ -222,7 +222,7 @@ var taskbarAppIcon = new Lang.Class({
this._numberOverlay();
this._signalsHandler = new Convenience.GlobalSignalsHandler();
this._signalsHandler = new Utils.GlobalSignalsHandler();
},
_createWindowPreview: function() {

View File

@@ -25,8 +25,6 @@ const Config = imports.misc.config;
const ExtensionUtils = imports.misc.extensionUtils;
const Gettext = imports.gettext;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
/**
* initTranslations:
@@ -88,160 +86,4 @@ function getSettings(schema) {
return new Gio.Settings({
settings_schema: schemaObj
});
}
// simplify global signals and function injections handling
// abstract class
var BasicHandler = new Lang.Class({
Name: 'DashToPanel.BasicHandler',
_init: function(){
this._storage = new Object();
},
add: function(/*unlimited 3-long array arguments*/){
// convert arguments object to array, concatenate with generic
let args = Array.concat('generic', Array.slice(arguments));
// call addWithLabel with ags as if they were passed arguments
this.addWithLabel.apply(this, args);
},
destroy: function() {
for( let label in this._storage )
this.removeWithLabel(label);
},
addWithLabel: function( label /* plus unlimited 3-long array arguments*/) {
if(this._storage[label] == undefined)
this._storage[label] = new Array();
// skip first element of the arguments
for( let i = 1; i < arguments.length; i++ ) {
let item = this._storage[label];
let handlers = this._create(arguments[i]);
for (let j = 0, l = handlers.length; j < l; ++j) {
item.push(handlers[j]);
}
}
},
removeWithLabel: function(label){
if(this._storage[label]) {
for( let i = 0; i < this._storage[label].length; i++ ) {
this._remove(this._storage[label][i]);
}
delete this._storage[label];
}
},
/* Virtual methods to be implemented by subclass */
// create single element to be stored in the storage structure
_create: function(item){
throw new Error('no implementation of _create in ' + this);
},
// correctly delete single element
_remove: function(item){
throw new Error('no implementation of _remove in ' + this);
}
});
// Manage global signals
var GlobalSignalsHandler = new Lang.Class({
Name: 'DashToPanel.GlobalSignalsHandler',
Extends: BasicHandler,
_create: function(item) {
let handlers = [];
item[1] = [].concat(item[1]);
for (let i = 0, l = item[1].length; i < l; ++i) {
let object = item[0];
let event = item[1][i];
let callback = item[2]
let id = object.connect(event, callback);
handlers.push([object, id]);
}
return handlers;
},
_remove: function(item){
item[0].disconnect(item[1]);
}
});
/**
* Manage function injection: both instances and prototype can be overridden
* and restored
*/
var InjectionsHandler = new Lang.Class({
Name: 'DashToPanel.InjectionsHandler',
Extends: BasicHandler,
_create: function(item) {
let object = item[0];
let name = item[1];
let injectedFunction = item[2];
let original = object[name];
object[name] = injectedFunction;
return [[object, name, injectedFunction, original]];
},
_remove: function(item) {
let object = item[0];
let name = item[1];
let original = item[3];
object[name] = original;
}
});
/**
* Manage timeouts: the added timeouts have their id reset on completion
*/
var TimeoutsHandler = new Lang.Class({
Name: 'DashToPanel.TimeoutsHandler',
Extends: BasicHandler,
_create: function(item) {
let name = item[0];
let delay = item[1];
let timeoutHandler = item[2];
this._remove(item);
this[name] = Mainloop.timeout_add(delay, () => {
this[name] = 0;
timeoutHandler();
});
return [[name]];
},
remove: function(name) {
this._remove([name])
},
_remove: function(item) {
let name = item[0];
if (this[name]) {
Mainloop.source_remove(this[name]);
this[name] = 0;
}
},
getId: function(name) {
return this[name] ? this[name] : 0;
}
});
}

View File

@@ -27,7 +27,7 @@ const PointerWatcher = imports.ui.pointerWatcher;
const Tweener = imports.ui.tweener;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Utils = Me.imports.utils;
//timeout intervals
const CHECK_POINTER_MS = 200;
@@ -48,8 +48,8 @@ var Intellihide = new Lang.Class({
this._dtpSettings = dtpPanel._dtpSettings;
this._panelBox = dtpPanel.panelBox;
this._signalsHandler = new Convenience.GlobalSignalsHandler();
this._timeoutsHandler = new Convenience.TimeoutsHandler();
this._signalsHandler = new Utils.GlobalSignalsHandler();
this._timeoutsHandler = new Utils.TimeoutsHandler();
this._dtpSettings.connect('changed::intellihide', Lang.bind(this, this._changeEnabledStatus));

View File

@@ -21,7 +21,7 @@
*/
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Utils = Me.imports.utils;
const Lang = imports.lang;
const Main = imports.ui.main;
const Shell = imports.gi.Shell;
@@ -44,8 +44,8 @@ var dtpOverview = new Lang.Class({
this._panel = panel;
this.taskbar = panel.taskbar;
this._injectionsHandler = new Convenience.InjectionsHandler();
this._signalsHandler = new Convenience.GlobalSignalsHandler();
this._injectionsHandler = new Utils.InjectionsHandler();
this._signalsHandler = new Utils.GlobalSignalsHandler();
// Hide usual Dash
Main.overview._controls.dash.actor.hide();

View File

@@ -30,7 +30,7 @@
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Clutter = imports.gi.Clutter;
const Gtk = imports.gi.Gtk;
const Convenience = Me.imports.convenience;
const Utils = Me.imports.utils;
const Taskbar = Me.imports.taskbar;
const PanelStyle = Me.imports.panelStyle;
const Lang = imports.lang;
@@ -175,7 +175,7 @@ var dtpPanel = new Lang.Class({
this.intellihide = new Intellihide.Intellihide(this);
});
this._signalsHandler = new Convenience.GlobalSignalsHandler();
this._signalsHandler = new Utils.GlobalSignalsHandler();
this._signalsHandler.add(
// Keep dragged icon consistent in size with this dash
[
@@ -234,7 +234,7 @@ var dtpPanel = new Lang.Class({
// Dynamic transparency is available on Gnome 3.26
if (this.panel._updateSolidStyle) {
this._injectionsHandler = new Convenience.InjectionsHandler();
this._injectionsHandler = new Utils.InjectionsHandler();
this.panel._dtpPosition = this._dtpSettings.get_string('panel-position');
this.panel._dtpRemoveSolidStyleId = 0;
this._injectionsHandler.addWithLabel('transparency', [

View File

@@ -45,7 +45,7 @@ const Util = imports.misc.util;
const Workspace = imports.ui.workspace;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Utils = Me.imports.utils;
const WindowPreview = Me.imports.windowPreview;
const AppIcons = Me.imports.appIcons;
@@ -184,7 +184,7 @@ var taskbar = new Lang.Class({
this._shownInitially = false;
this._position = getPosition();
this._signalsHandler = new Convenience.GlobalSignalsHandler();
this._signalsHandler = new Utils.GlobalSignalsHandler();
this._dragPlaceholder = null;
this._dragPlaceholderPos = -1;

180
utils.js Normal file
View File

@@ -0,0 +1,180 @@
/*
* This file is part of the Dash-To-Panel extension for Gnome 3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* Credits:
* This file is based on code from the Dash to Dock extension by micheleg
* and code from the Taskbar extension by Zorin OS
* Some code was also adapted from the upstream Gnome Shell source code.
*/
const Lang = imports.lang;
const Mainloop = imports.mainloop;
// simplify global signals and function injections handling
// abstract class
var BasicHandler = new Lang.Class({
Name: 'DashToPanel.BasicHandler',
_init: function(){
this._storage = new Object();
},
add: function(/*unlimited 3-long array arguments*/){
// convert arguments object to array, concatenate with generic
let args = Array.concat('generic', Array.slice(arguments));
// call addWithLabel with ags as if they were passed arguments
this.addWithLabel.apply(this, args);
},
destroy: function() {
for( let label in this._storage )
this.removeWithLabel(label);
},
addWithLabel: function( label /* plus unlimited 3-long array arguments*/) {
if(this._storage[label] == undefined)
this._storage[label] = new Array();
// skip first element of the arguments
for( let i = 1; i < arguments.length; i++ ) {
let item = this._storage[label];
let handlers = this._create(arguments[i]);
for (let j = 0, l = handlers.length; j < l; ++j) {
item.push(handlers[j]);
}
}
},
removeWithLabel: function(label){
if(this._storage[label]) {
for( let i = 0; i < this._storage[label].length; i++ ) {
this._remove(this._storage[label][i]);
}
delete this._storage[label];
}
},
/* Virtual methods to be implemented by subclass */
// create single element to be stored in the storage structure
_create: function(item){
throw new Error('no implementation of _create in ' + this);
},
// correctly delete single element
_remove: function(item){
throw new Error('no implementation of _remove in ' + this);
}
});
// Manage global signals
var GlobalSignalsHandler = new Lang.Class({
Name: 'DashToPanel.GlobalSignalsHandler',
Extends: BasicHandler,
_create: function(item) {
let handlers = [];
item[1] = [].concat(item[1]);
for (let i = 0, l = item[1].length; i < l; ++i) {
let object = item[0];
let event = item[1][i];
let callback = item[2]
let id = object.connect(event, callback);
handlers.push([object, id]);
}
return handlers;
},
_remove: function(item){
item[0].disconnect(item[1]);
}
});
/**
* Manage function injection: both instances and prototype can be overridden
* and restored
*/
var InjectionsHandler = new Lang.Class({
Name: 'DashToPanel.InjectionsHandler',
Extends: BasicHandler,
_create: function(item) {
let object = item[0];
let name = item[1];
let injectedFunction = item[2];
let original = object[name];
object[name] = injectedFunction;
return [[object, name, injectedFunction, original]];
},
_remove: function(item) {
let object = item[0];
let name = item[1];
let original = item[3];
object[name] = original;
}
});
/**
* Manage timeouts: the added timeouts have their id reset on completion
*/
var TimeoutsHandler = new Lang.Class({
Name: 'DashToPanel.TimeoutsHandler',
Extends: BasicHandler,
_create: function(item) {
let name = item[0];
let delay = item[1];
let timeoutHandler = item[2];
this._remove(item);
this[name] = Mainloop.timeout_add(delay, () => {
this[name] = 0;
timeoutHandler();
});
return [[name]];
},
remove: function(name) {
this._remove([name])
},
_remove: function(item) {
let name = item[0];
if (this[name]) {
Mainloop.source_remove(this[name]);
this[name] = 0;
}
},
getId: function(name) {
return this[name] ? this[name] : 0;
}
});

View File

@@ -41,7 +41,6 @@ const Workspace = imports.ui.workspace;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Taskbar = Me.imports.taskbar;
const Convenience = Me.imports.convenience;
const AppIcons = Me.imports.appIcons;
let HOVER_APP_BLACKLIST = [