[sushi/wip/cosimoc/no-clutter: 30/50] Avoid instantiating all renderers at startup
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sushi/wip/cosimoc/no-clutter: 30/50] Avoid instantiating all renderers at startup
- Date: Mon, 17 Jun 2019 18:35:08 +0000 (UTC)
commit aeab5cd4c7895ff79c72a212a0ebaf18cf30164d
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Jun 15 12:18:08 2019 -0700
Avoid instantiating all renderers at startup
This should make the app startup faster and save resources, but
will also allow us to have the renderers be widget subclasses.
src/js/ui/mimeHandler.js | 17 ++++++++---------
src/js/viewers/audio.js | 3 +--
src/js/viewers/evince.js | 5 ++---
src/js/viewers/font.js | 3 +--
src/js/viewers/gst.js | 3 +--
src/js/viewers/html.js | 3 +--
src/js/viewers/image.js | 3 +--
src/js/viewers/text.js | 3 +--
8 files changed, 16 insertions(+), 24 deletions(-)
---
diff --git a/src/js/ui/mimeHandler.js b/src/js/ui/mimeHandler.js
index cac836c..f82264d 100644
--- a/src/js/ui/mimeHandler.js
+++ b/src/js/ui/mimeHandler.js
@@ -45,25 +45,24 @@ function init() {
MimeHandler.prototype = {
_init: function() {
this._mimeTypes = [];
+ },
- this._fallbackRenderer = new FallbackRenderer.FallbackRenderer();
- },
-
- registerMime: function(mime, obj) {
- this._mimeTypes[mime] = obj;
+ registerMime: function(mime, klass) {
+ this._mimeTypes[mime] = klass;
log ('Register mimetype ' + mime);
},
- registerMimeTypes: function(mimeTypes, obj) {
+ registerMimeTypes: function(mimeTypes, klass) {
for (let idx in mimeTypes)
- this.registerMime(mimeTypes[idx], obj);
+ this.registerMime(mimeTypes[idx], klass);
},
getObject: function(mime) {
if (this._mimeTypes[mime]) {
/* first, try a direct match with the mimetype itself */
- return this._mimeTypes[mime];
+ let klass = this._mimeTypes[mime];
+ return new klass();
} else {
/* if this fails, try to see if we have any handlers
* registered for a parent type.
@@ -74,7 +73,7 @@ MimeHandler.prototype = {
}
/* finally, resort to the fallback renderer */
- return this._fallbackRenderer;
+ return new FallbackRenderer.FallbackRenderer();
}
}
}
diff --git a/src/js/viewers/audio.js b/src/js/viewers/audio.js
index b3071f0..b84d058 100644
--- a/src/js/viewers/audio.js
+++ b/src/js/viewers/audio.js
@@ -307,6 +307,5 @@ const AudioRenderer = new Lang.Class({
});
let handler = new MimeHandler.MimeHandler();
-let renderer = new AudioRenderer();
-handler.registerMimeTypes(TotemMimeTypes.audioTypes, renderer);
+handler.registerMimeTypes(TotemMimeTypes.audioTypes, AudioRenderer);
diff --git a/src/js/viewers/evince.js b/src/js/viewers/evince.js
index 8ea35ce..1c5ed9f 100644
--- a/src/js/viewers/evince.js
+++ b/src/js/viewers/evince.js
@@ -141,10 +141,9 @@ const EvinceRenderer = new Lang.Class({
});
let handler = new MimeHandler.MimeHandler();
-let renderer = new EvinceRenderer();
let mimeTypes = Sushi.query_supported_document_types();
-handler.registerMimeTypes(mimeTypes, renderer);
+handler.registerMimeTypes(mimeTypes, EvinceRenderer);
let officeTypes = [
'application/vnd.oasis.opendocument.text',
@@ -159,4 +158,4 @@ let officeTypes = [
'application/rtf'
];
-handler.registerMimeTypes(officeTypes, renderer);
+handler.registerMimeTypes(officeTypes, EvinceRenderer);
diff --git a/src/js/viewers/font.js b/src/js/viewers/font.js
index 8f89311..666d9ac 100644
--- a/src/js/viewers/font.js
+++ b/src/js/viewers/font.js
@@ -63,7 +63,6 @@ const FontRenderer = new Lang.Class({
});
let handler = new MimeHandler.MimeHandler();
-let renderer = new FontRenderer();
let mimeTypes = [
'application/x-font-ttf',
@@ -72,4 +71,4 @@ let mimeTypes = [
'application/x-font-type1'
];
-handler.registerMimeTypes(mimeTypes, renderer);
+handler.registerMimeTypes(mimeTypes, FontRenderer);
diff --git a/src/js/viewers/gst.js b/src/js/viewers/gst.js
index 6296902..c6f65fe 100644
--- a/src/js/viewers/gst.js
+++ b/src/js/viewers/gst.js
@@ -72,6 +72,5 @@ const GstRenderer = new Lang.Class({
});
let handler = new MimeHandler.MimeHandler();
-let renderer = new GstRenderer();
-handler.registerMimeTypes(TotemMimeTypes.videoTypes, renderer);
+handler.registerMimeTypes(TotemMimeTypes.videoTypes, GstRenderer);
diff --git a/src/js/viewers/html.js b/src/js/viewers/html.js
index adcba85..6360b9d 100644
--- a/src/js/viewers/html.js
+++ b/src/js/viewers/html.js
@@ -74,10 +74,9 @@ const HTMLRenderer = new Lang.Class({
});
let handler = new MimeHandler.MimeHandler();
-let renderer = new HTMLRenderer();
let mimeTypes = [
'text/html'
];
-handler.registerMimeTypes(mimeTypes, renderer);
+handler.registerMimeTypes(mimeTypes, HTMLRenderer);
diff --git a/src/js/viewers/image.js b/src/js/viewers/image.js
index ae44761..f3d24b5 100644
--- a/src/js/viewers/image.js
+++ b/src/js/viewers/image.js
@@ -222,10 +222,9 @@ const ImageRenderer = new Lang.Class({
});
let handler = new MimeHandler.MimeHandler();
-let renderer = new ImageRenderer();
let formats = GdkPixbuf.Pixbuf.get_formats();
for (let idx in formats) {
let mimeTypes = formats[idx].get_mime_types();
- handler.registerMimeTypes(mimeTypes, renderer);
+ handler.registerMimeTypes(mimeTypes, ImageRenderer);
}
diff --git a/src/js/viewers/text.js b/src/js/viewers/text.js
index 0f3d13d..5e47029 100644
--- a/src/js/viewers/text.js
+++ b/src/js/viewers/text.js
@@ -110,7 +110,6 @@ const TextRenderer = new Lang.Class({
});
let handler = new MimeHandler.MimeHandler();
-let renderer = new TextRenderer();
/* register for text/plain and let the mime handler call us
* for child types.
@@ -119,4 +118,4 @@ let mimeTypes = [
'text/plain'
];
-handler.registerMimeTypes(mimeTypes, renderer);
+handler.registerMimeTypes(mimeTypes, TextRenderer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]