1
0
mirror of https://github.com/moparisthebest/FireTray synced 2024-11-10 11:05:07 -05:00

* dropped mozt.Debug in favour of AddonLogging.jsm

* start l10n
This commit is contained in:
foudfou 2011-09-02 22:16:44 +02:00
parent 7c30cd4714
commit 4d19bb51d3
6 changed files with 49 additions and 191 deletions

3
TODO
View File

@ -2,6 +2,9 @@
* convert to a https://developer.mozilla.org/en/Extensions/Bootstrapped_extensions
see ../restartless-restart-ffext/ and
http://erikvold.com/blog/index.cfm/2010/10/28/restartless-firefox-addons-part-1-giving-your-addon-the-bootstrap
WONTFIX:
* ability to hide windows individually/globally

View File

@ -35,7 +35,7 @@ mozt.Main = {
// NOTE: each new window gets a new mozt.Main, and hence listens to pref
// changes
mozt.Debug.debug('Moztray LOADED: ' + init);
LOG('Moztray LOADED: ' + init);
return true;
},
@ -43,7 +43,7 @@ mozt.Main = {
// Remove observer
let that = this;
mozt.Utils.prefService.removeObserver("", that);
mozt.Debug.debug('Moztray UNLOADED !');
LOG('Moztray UNLOADED !');
/*
* NOTE: don't mozt.Handler.initialized=false here, otherwise after a
* window close, a new window will create a new handler (and hence, a new
@ -54,9 +54,9 @@ mozt.Main = {
// TODO: prevent preceding warning about closing multiple tabs
// (browser.tabs.warnOnClose)
onClose: function(event) {
mozt.Debug.debug('Moztray CLOSE');
LOG('Moztray CLOSE');
let close_hides = mozt.Utils.prefService.getBoolPref('close_hides');
mozt.Debug.debug('close_hides: '+close_hides);
LOG('close_hides: '+close_hides);
if (close_hides) {
mozt.Handler.showHideToTray();
event && event.preventDefault(); // no event when called directly (xul)
@ -66,7 +66,7 @@ mozt.Main = {
observe: function(subject, topic, data) {
// Observer for pref changes
if (topic != "nsPref:changed") return;
mozt.Debug.debug('Pref changed: '+data);
LOG('Pref changed: '+data);
// switch(data) { ...
}

View File

@ -1,14 +1,3 @@
extensions.moztray@foudil.fr.description=A system tray extension for linux.
exceptionAdded=A %1$S was added by Moztray for %2$S
exceptionNotAdded=An exception could not be added by Moztray: %1$S
temporaryException=temporary exception
permanentException=permanent exception
NOT_VERIFIED_UNKNOWN=not verified unknown
CERT_REVOKED=cert revoked
CERT_EXPIRED=cert expired
CERT_NOT_TRUSTED=cert not trusted
ISSUER_NOT_TRUSTED=issuer not trusted
ISSUER_UNKNOWN=issuer unknown
INVALID_CA=invalid ca
USAGE_NOT_ALLOWED=usage not allowed
CERT_SELF_SIGNED=cert self signed
popupMenu.itemLabel.View=Foudil
popupMenu.itemLabel.Exit=Exit

View File

@ -1,104 +0,0 @@
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
var EXPORTED_SYMBOLS = ["LibC"];
const LIB_C = "libc.so.6";
const Cu = Components.utils;
const Cc = Components.classes;
const Ci = Components.interfaces;
Cu.import("resource://gre/modules/ctypes.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyGetter(this, "libc", function() {
var libc = ctypes.open(LIB_C);
if (!libc)
throw "libc is unavailable";
return libc;
});
XPCOMUtils.defineLazyGetter(this, "FILE", function() {
return ctypes.StructType("FILE");
});
XPCOMUtils.defineLazyGetter(this, "pid_t", function() {
return ctypes.int;
});
XPCOMUtils.defineLazyGetter(this, "fdopen", function() {
var fdopen = libc.declare(
"fdopen", ctypes.default_abi, FILE.ptr,
ctypes.int,
ctypes.char.ptr
);
if (!fdopen)
throw "fdopen is unavailable";
return fdopen;
});
XPCOMUtils.defineLazyGetter(this, "puts", function() {
var puts = libc.declare(
"puts", ctypes.default_abi, ctypes.int32_t,
ctypes.char.ptr
);
if (!puts)
throw "puts is unavailable";
return puts;
});
XPCOMUtils.defineLazyGetter(this, "fputs", function() {
var fputs = libc.declare(
"fputs", ctypes.default_abi, ctypes.int32_t,
ctypes.char.ptr,
FILE.ptr
);
if (!fputs)
throw "fputs is unavailable";
return fputs;
});
XPCOMUtils.defineLazyGetter(this, "fflush", function() {
var fflush = libc.declare(
"fflush", ctypes.default_abi, ctypes.int32_t,
FILE.ptr
);
if (!fflush)
throw "fflush is unavailable";
return fflush;
});
// pid_t getpid(void);
XPCOMUtils.defineLazyGetter(this, "getpid", function() {
var getpid = libc.declare(
"getpid", ctypes.default_abi, pid_t
);
if (!getpid)
throw "getpid is unavailable";
return getpid;
});
var LibC = {
stderr: this.fdopen(2, "a"),
FILE: FILE,
pid_t: pid_t,
fdopen: fdopen,
puts: puts,
fputs: fputs,
fflush: fflush,
getpid: getpid,
}

View File

@ -8,7 +8,6 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/ctypes.jsm");
/* Cu.import("resource://moztray/LibC.jsm"); */
Cu.import("resource://moztray/LibGObject.jsm");
Cu.import("resource://moztray/LibGtkStatusIcon.jsm");
Cu.import("resource://moztray/commons.js");
@ -50,7 +49,7 @@ mozt.Handler = {
.QueryInterface(Ci.nsIInterfaceRequestor);
} catch (ex) {
// ignore no-interface exception
mozt.Debug.debug(ex);
LOG(ex);
Components.utils.reportError(ex);
return null;
}
@ -75,7 +74,7 @@ mozt.Handler = {
* time...
*/
_updateHandledDOMWindows: function() {
mozt.Debug.debug("_updateHandledDOMWindows");
LOG("_updateHandledDOMWindows");
this._handledDOMWindows = [];
var windowsEnumerator = Services.wm.getEnumerator(null); // returns a nsIDOMWindow
while (windowsEnumerator.hasMoreElements()) {
@ -84,8 +83,9 @@ mozt.Handler = {
}
},
// FIXME: parameters may not be needed !! see LibGObject.GCallback_t
showHideToTray: function(a1, a2, a3) {
mozt.Debug.debug("showHideToTray");
LOG("showHideToTray");
/*
* we update _handledDOMWindows only when hiding, because remembered{X,Y}
@ -97,21 +97,21 @@ mozt.Handler = {
*/
if (!this._windowsHidden) // hide
this._updateHandledDOMWindows();
mozt.Debug.debug("nb Windows: " + this._handledDOMWindows.length);
LOG("nb Windows: " + this._handledDOMWindows.length);
for(let i=0; i<this._handledDOMWindows.length; i++) {
let bw = this._getBaseOrXULWindowFromDOMWindow(
this._handledDOMWindows[i], "BaseWindow");
mozt.Debug.debug('isHidden: ' + this._windowsHidden);
mozt.Debug.debug("bw.visibility: " + bw.visibility);
LOG('isHidden: ' + this._windowsHidden);
LOG("bw.visibility: " + bw.visibility);
try {
if (this._windowsHidden) { // show
// correct position
let x = this._handledDOMWindows[i].rememberedX;
let y = this._handledDOMWindows[i].rememberedY;
mozt.Debug.debug("set bw.position: " + x + ", " + y);
LOG("set bw.position: " + x + ", " + y);
bw.setPosition(x, y);
bw.visibility = true;
@ -121,7 +121,7 @@ mozt.Handler = {
// remember position
let x = {}, y = {};
bw.getPosition(x, y);
mozt.Debug.debug("remember bw.position: " + x.value + ", " + y.value);
LOG("remember bw.position: " + x.value + ", " + y.value);
this._handledDOMWindows[i].rememberedX = x.value;
this._handledDOMWindows[i].rememberedY = y.value;
// var windowID = win.QueryInterface(Ci.nsIInterfaceRequestor)
@ -131,10 +131,10 @@ mozt.Handler = {
}
} catch (x) {
mozt.Debug.debug(x);
LOG(x);
}
mozt.Debug.debug("bw.visibility: " + bw.visibility);
mozt.Debug.debug("bw.title: " + bw.title);
LOG("bw.visibility: " + bw.visibility);
LOG("bw.title: " + bw.title);
}
if (this._windowsHidden) {
@ -146,9 +146,8 @@ mozt.Handler = {
}, // showHideToTray
popupMenu: function(icon, button, activateTime, menu) {
// GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data
mozt.Debug.debug("MENU POPUP");
mozt.Debug.debug("ARGS="+icon+", "+button+", "+activateTime+", "+menu);
LOG("MENU POPUP");
LOG("ARGS="+icon+", "+button+", "+activateTime+", "+menu);
try {
LibGtkStatusIcon.init(); // before anything !!!
@ -159,17 +158,24 @@ mozt.Handler = {
iconGpointer, button, activateTime);
LibGtkStatusIcon.shutdown();
} catch (x) {
mozt.Debug.debug(x);
LOG(x);
}
},
/*
* @param strings l10n Strings passed from the XUL overlay
*/
init: function() { // creates icon
// initialize l10n
this.strings = Services.strings
.createBundle("chrome://moztray/locale/overlay.properties");
// platform checks
let runtimeOS = Services.appinfo.OS; // "WINNT", "Linux", "Darwin"
// version checked during install, so we shouldn't need to care
let xulVer = Services.appinfo.platformVersion; // Services.vc.compare(xulVer,"2.0a")>=0
mozt.Debug.debug("OS=" + runtimeOS + ", XULrunner=" + xulVer);
LOG("OS=" + runtimeOS + ", XULrunner=" + xulVer);
if (runtimeOS != "Linux") {
Components.utils.reportError("MOZTRAY: only Linux platform supported at this time. Moztray not loaded");
return false;
@ -193,13 +199,17 @@ mozt.Handler = {
this.menu = LibGtkStatusIcon.gtk_menu_new();
// TODO: intl labels,
// gtk_image_menu_item_new_with_label ?
var menuItemView = LibGtkStatusIcon.gtk_image_menu_item_new_with_label("View");
var menuItemViewLabel = this.strings.GetStringFromName("popupMenu.itemLabel.View");
var menuItemView = LibGtkStatusIcon.gtk_image_menu_item_new_with_label(
menuItemViewLabel);
/*
let image = gtk_image_new_from_file("");
let image = LibGtkStatusIcon.gtk_image_new_from_file("myfile.png");
LibGtkStatusIcon.gtk_image_set_pixel_size( GTK_IMAGE ( image ), GTK_ICON_SIZE_MENU );
LibGtkStatusIcon.gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ), image );
*/
var menuItemExit = LibGtkStatusIcon.gtk_image_menu_item_new_with_label("Exit");
var menuItemViewExit = this.strings.GetStringFromName("popupMenu.itemLabel.Exit");
var menuItemExit = LibGtkStatusIcon.gtk_image_menu_item_new_with_label(
menuItemViewExit);
var menuShell = ctypes.cast(this.menu, LibGtkStatusIcon.GtkMenuShell.ptr);
LibGtkStatusIcon.gtk_menu_shell_append(menuShell, menuItemView);
LibGtkStatusIcon.gtk_menu_shell_append(menuShell, menuItemExit);

View File

@ -1,13 +1,12 @@
/* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
var EXPORTED_SYMBOLS = [ "mozt", "Cc", "Ci", "Cu" ];
var EXPORTED_SYMBOLS = [ "mozt", "Cc", "Ci", "Cu", "LOG", "WARN", "ERROR" ];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://moztray/LibC.jsm");
const FIREFOX_ID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";
const THUNDERBIRD_ID = "{3550f703-e582-4d05-9a08-453d09bdfdc6}";
@ -23,53 +22,14 @@ if ("undefined" == typeof(mozt)) {
var mozt = {};
};
mozt.Debug = {
DEBUG_MODE: true,
_initialized: false,
/**
* Object constructor.
*/
init: function() {
if (this._initialized) return;
this._consoleService = Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService);
this.dump("Moztray Debug initialized");
this._initialized = true;
},
/* Console logging functions */
/* NOTE: Web Console inappropriates: doesn't catch all messages */
/*
* CAUTION: dump() dumpObj() may be stripped from .js files during xpi build.
* IT'S IMPORTANT THAT DEBUG CALLS ARE WRITTEN ON A SINGLE LINE !
*/
dump: function(message) { // Debuging function -- prints to javascript console
if(!this.DEBUG_MODE) return;
this._consoleService.logStringMessage(message);
},
dumpObj: function(obj) {
if(!this.DEBUG_MODE) return;
var str = "";
for(i in obj) {
try {
str += "obj["+i+"]: " + obj[i] + "\n";
} catch(e) {
str += "obj["+i+"]: Unavailable\n";
}
}
this.dump(str);
},
// dump to terminal (stderr)
debug: function(str) {
LibC.fputs(str + "\n", LibC.stderr);
LibC.fflush(LibC.stderr);
},
};
// build it !
mozt.Debug.init();
// about:config extensions.logging.enabled
["LOG", "WARN", "ERROR"].forEach(function(aName) {
this.__defineGetter__(aName, function() {
Components.utils.import("resource://gre/modules/AddonLogging.jsm");
LogManager.getLogger("moztray", this);
return this[aName];
});
}, this);
mozt.Utils = {
prefService: Services.prefs.getBranch("extensions.moztray.")