From cbf19291b25d6b370c01204e6fa7666371315767 Mon Sep 17 00:00:00 2001 From: phasefx Date: Tue, 20 Apr 2010 15:19:18 +0000 Subject: [PATCH] reduce proliferation of nsISound instances git-svn-id: svn://svn.open-ils.org/ILS/trunk@16280 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/xul/staff_client/chrome/content/main/menu.js | 2 ++ Open-ILS/xul/staff_client/chrome/content/util/sound.js | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu.js b/Open-ILS/xul/staff_client/chrome/content/main/menu.js index e629ae747..a860fe1d8 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu.js @@ -10,6 +10,7 @@ main.menu = function () { offlineStrings = document.getElementById('offlineStrings'); JSAN.use('util.error'); this.error = new util.error(); JSAN.use('util.window'); this.window = new util.window(); + JSAN.use('util.sound'); this.sound = new util.sound(); this.w = window; var x = document.getElementById('network_progress'); @@ -1481,6 +1482,7 @@ main.menu.prototype = { if (e) { e.setAttribute('label',text); } }; content_params.chrome_xulG = xulG; + content_params._sound = xulG._sound; if (params && params.tab_name) content_params.set_tab_name( params.tab_name ); var frame; diff --git a/Open-ILS/xul/staff_client/chrome/content/util/sound.js b/Open-ILS/xul/staff_client/chrome/content/util/sound.js index 0b1bb9ec6..40ef8bb89 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/sound.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/sound.js @@ -4,17 +4,24 @@ if (typeof util == 'undefined') util = {}; util.sound = function () { try { + + /* We're going to turn this guy into a singleton, at least for a given window, and look for it in xulG */ + if (! window.xulG) { window.xulG = {}; } + if (window.xulG._sound) { return window.xulG._sound; } + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var SOUNDContractID = "@mozilla.org/sound;1"; var SOUNDIID = Components.interfaces.nsISound; this.SOUND = Components.classes[SOUNDContractID].createInstance(SOUNDIID); this.SOUND.init(); // not necessary, but helps avoid delays? + window.xulG._sound = this; + return this; + } catch(E) { - dump('util.sound constructor: ' + E + '\n'); + dump('error in util.sound constructor: ' + E + '\n'); + return this; } - - return this; }; util.sound.prototype = { -- 2.11.0