44
44
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
45
45
Cu.import("resource://gre/modules/FileUtils.jsm");
46
46
Cu.import("resource://gre/modules/ctypes.jsm");
47
Cu.import("resource://ubufox/modules/utils.jsm");
48
Cu.import("resource://ubufox/libs/gio.jsm");
49
Cu.import("resource://ubufox/libs/gobject.jsm");
47
50
Cu.import("resource://ubufox/libs/glib.jsm");
48
Cu.import("resource://ubufox/libs/gobject.jsm");
49
Cu.import("resource://ubufox/libs/gio.jsm");
51
52
const NS_XPCOM_CURRENT_PROCESS_DIR = "XCurProcD";
52
53
const NS_GRE_DIR = "GreD";
57
58
const XRE_SYS_SHARE_EXTENSION_PARENT_DIR = "XRESysSExtPD";
58
59
const XRE_EXTENSIONS_DIR_LIST = "XREExtDL";
60
["LOG", "WARN", "ERROR"].forEach(function(aName) {
61
this.__defineGetter__(aName, function() {
62
Components.utils.import("resource://gre/modules/AddonLogging.jsm");
64
LogManager.getLogger("ubufox.urn", this);
61
addLogger(this, "update-notifier");
69
63
function UpdateNotifier() {
274
268
function handler(aFile, aEventType, aIsDir) {
275
let cpath = new ctypes.char.ptr;
277
if (aEventType == gio.G_FILE_MONITOR_EVENT_CHANGED ||
278
aEventType == gio.G_FILE_MONITOR_EVENT_DELETED ||
279
aEventType == gio.G_FILE_MONITOR_EVENT_CREATED ||
280
aEventType == gio.G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED) {
281
cpath = gio.g_file_get_path(aFile);
282
path = cpath.readString();
284
if (!(path in watches) && aIsDir) {
285
type = watches[(new FileUtils.File(path)).parent.path].type;
287
type = watches[path].type;
291
Cu.reportError("Got event for a path not in our watch list: " +
296
// Wait for the location to settle before dispatching the notification
297
if (!(type in timers)) {
298
timers[type] = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
299
timers[type].initWithCallback(function() {
301
((new Object({"app" : handleAppUpdated,
302
"plugins": handlePluginsChanged,
303
"addons" : handleAddonsChanged}))[type])();
304
}, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
306
timers[type].delay = 10000;
269
if (aEventType == gio.GFileMonitorEventEnums.G_FILE_MONITOR_EVENT_CHANGED ||
270
aEventType == gio.GFileMonitorEventEnums.G_FILE_MONITOR_EVENT_DELETED ||
271
aEventType == gio.GFileMonitorEventEnums.G_FILE_MONITOR_EVENT_CREATED ||
272
aEventType == gio.GFileMonitorEventEnums.G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED) {
273
let path = gio.g_file_get_path(aFile);
275
if (!(path in watches) && aIsDir) {
276
type = watches[(new FileUtils.File(path)).parent.path].type;
278
type = watches[path].type;
282
ERROR("Got event for a path not in our watch list: " + path);
286
// Wait for the location to settle before dispatching the notification
287
if (!(type in timers)) {
288
timers[type] = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
289
timers[type].initWithCallback(function() {
291
((new Object({"app" : handleAppUpdated,
292
"plugins": handlePluginsChanged,
293
"addons" : handleAddonsChanged}))[type])();
294
}, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
296
timers[type].delay = 10000;
321
308
let file = gio.g_file_new_for_path(aFile.path);
322
309
if (file.isNull()) {
323
Cu.reportError("OOM: Failed to get GFile for path " + aFile.path);
310
ERROR("OOM: Failed to get GFile for path " + aFile.path);
327
let mon = gio.g_file_monitor_file(file, gio.G_FILE_MONITOR_NONE,
314
let mon = gio.g_file_monitor_file(file,
315
gio.GFileMonitorFlagsFlags.G_FILE_MONITOR_NONE,
329
317
gobject.g_object_unref(file);
330
318
if (mon.isNull()) {
331
Cu.reportError("Failed to create monitor for path " + aFile.path);
319
ERROR("Failed to create monitor for path " + aFile.path);
335
let id = gobject.GSignalConnect(mon, "changed", function(aMonitor,
323
let id = gobject.g_signal_connect(mon, "changed",
324
function(aMonitor, aFile, aOtherFile,
340
326
handler(aFile, aEventType, false);
341
}, ctypes.void_t, [gio.GFileMonitor.ptr, gio.GFile.ptr, gio.GFile.ptr,
342
gio.GFileMonitorEvent, glib.gpointer]);
343
328
watches[aFile.path] = {monitor: mon, sig_id: id, type: aType};
344
329
LOG("Watching " + aFile.path);
367
352
let file = gio.g_file_new_for_path(nsifile.path);
368
353
if (file.isNull()) {
369
Cu.reportError("OOM: Failed to get GFile for path " + nsifile.path);
354
ERROR("OOM: Failed to get GFile for path " + nsifile.path);
373
let mon = gio.g_file_monitor_directory(file, gio.G_FILE_MONITOR_NONE,
358
let mon = gio.g_file_monitor_directory(file,
359
gio.GFileMonitorFlagsFlags.G_FILE_MONITOR_NONE,
375
361
gobject.g_object_unref(file);
376
362
if (mon.isNull()) {
377
Cu.reportError("Failed to create monitor for path " + nsifile.path);
363
ERROR("Failed to create monitor for path " + nsifile.path);
381
let id = gobject.GSignalConnect(mon, "changed", function(aMonitor,
367
let id = gobject.g_signal_connect(mon, "changed",
368
function(aMonitor, aFile, aOtherFile,
386
370
handler(aFile, aEventType, true);
387
}, ctypes.void_t, [gio.GFileMonitor.ptr, gio.GFile.ptr, gio.GFile.ptr,
388
gio.GFileMonitorEvent, glib.gpointer]);
389
372
watches[nsifile.path] = {monitor: mon, sig_id: id, type: aType};
390
373
LOG("Watching " + nsifile.path);
424
407
if (aSubject == "xpcom-shutdown") {
425
408
Services.obs.removeObserver(arguments.callee, "xpcom-shutdown", false);
426
409
for (let path in watches) {
427
gobject.GSignalHandlerDisconnect(watches[path].monitor,
428
watches[path].sig_id);
410
gobject.g_signal_handler_disconnect(watches[path].monitor,
411
watches[path].sig_id);
429
412
gobject.g_object_unref(watches[path].monitor);