hide-on-close.js
Go to the documentation of this file.
1 /*
2  * BEGIN NIGHTINGALE GPL
3  *
4  * This file is part of the Nightingale Media Player.
5  *
6  * Copyright(c) 2014
7  * http://www.getnightingale.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the "GPL").
11  *
12  * Software distributed under the License is distributed
13  * on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * END NIGHTINGALE GPL
23  */
24 
25 try {
26  Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
27  Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
28 } catch (error) {alert("Hide on close: module import error\n\n" + error) }
29 
30 if (typeof HideOnClose == 'undefined') {
31  var HideOnClose = {};
32 };
33 
35  xulAppInfo: null,
36  wm: null,
39  mainwindow: null,
40  prefs: null,
41 
42  onLoad: function () {
43  var mainwindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation)
44  .QueryInterface(Components.interfaces.nsIDocShellTreeItem).rootTreeItem
45  .QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);
46 
47  this.xulAppInfo = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo);
48  this.stringConverter = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter);
49  this.wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
50  this.mainwindow = this.wm.getMostRecentWindow("Songbird:Main");
51  this.prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.hide-on-close.");
52  this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
53 
54  HideOnClose.preferencesObserver.register();
55 
56  this.ngHideOnClose = Components.classes["@getnightingale.com/Nightingale/ngHideOnClose;1"].getService(Components.interfaces.ngIHideOnClose);
57 
58  var windowTitle = mainwindow.document.getElementById("mainplayer").getAttribute("title");
59 
60  if (this.xulAppInfo.name == "Nightingale")
61  this.ngHideOnClose.InitializeFor("nightingale.desktop", windowTitle);
62  else {
63  alert("Hide on close failed to initialize")
64  return;
65  }
66 
67  HideOnClose.preferencesObserver.observe(null, "needInit", "enabled");
68 
69  this.observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
70  },
71 
72  onUnLoad: function () {
73  HideOnClose.preferencesObserver.unregister();
74  },
75 
76  registerOnClose: function (force) {
77  if (this.prefs.getBoolPref("enabled")) {
78  var that = this;
79  this.mainwindow.onclose = function () {
80  that.ngHideOnClose.HideWindow();
81  return false;
82  }
83  } else if (force) {
84  this.mainwindow.onclose = "";
85  }
86  },
87 
88  preferencesObserver: {
89  register: function () {
90  HideOnClose.prefs.addObserver("", this, false);
91  },
92 
93  unregister: function () {
94  HideOnClose.prefs.removeObserver("", this);
95  },
96 
97  observe: function (aSubject, aTopic, aData) {
98  if(aTopic != "nsPref:changed" && aTopic != "needInit") return;
99 
100  if (aData == "enabled")
101  HideOnClose.registerOnClose(true);
102  }
103  }
104 };
105 
106 window.addEventListener("load", function(e) { HideOnClose.onLoad(); }, false);
107 window.addEventListener("unload", function(e) { HideOnClose.onUnLoad(); }, false);
static nsCOMPtr< nsIObserverService > observerService
Definition: UnityProxy.cpp:6
let window
void InitializeFor(in string desktopFileName, in string windowTitle)
Lastfm onLoad
Definition: mini.js:36
return null
Definition: FeedWriter.js:1143
HideOnClose
var prefs
Definition: FeedWriter.js:1169
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe