Ejemplo n.º 1
0
	require("version").getInfo(function(v) {
		try {
			let lastVersion = Preferences.getExt('version', '0');
			if (0 === v.compareVersion(v.BASE_VERSION, lastVersion)) {
				return;
			}
			if (v.compareVersion(lastVersion, "1.0.1") < 0) {
				fn1_0.forEach(fn => fn());
			}
			Preferences.setExt('version', v.BASE_VERSION);

			v.showAbout = true;
			obs.notify(null, v.TOPIC_SHOWABOUT, null);

			// Need to extract icons
			require("support/iconcheat").loadWindow(null);
		}
		catch (ex) {
			log(LOG_ERROR, "MigrationManager", ex);
			try {
				Preferences.resetExt("version");
			}
			catch (iex) {
				// XXX
			}
		}
	});
Ejemplo n.º 2
0
	var run_multiple = function(item, tests) {
		var prefs = require("preferences");
		var restore = prefs.getExt("seriesdigits", 3);
		try {
			prefs.setExt("seriesdigits", 3);
			const rename = createRenamer(item);
			for (var i of ["first run ", "second run"]) {
				for (var [mask, res] in Iterator(tests)) {
					res = normalizeSlashes(res);
					strictEqual(normalizeSlashes(rename(mask)), res, i + mask + " = " + res);
				}
			}
		}
		finally {
			prefs.setExt("seriesdigits", restore);
		}
	};
test("setters", function() {
	var p = require("preferences");
	p.set("extensions.dta.testSet", "test");
	equal(p.getExt("testSet"), "test");
	p.reset("extensions.dta.testSet");
	equal(p.getExt("testSet"), undefined);
	p.setExt("testSet", "test");
	equal(p.get("extensions.dta.testSet"), "test");
	p.resetExt("testSet");
	equal(p.getExt("extensions.dta.testSet"), undefined);
});
test("observers", function() {
	var p = require("preferences");

	var obs1 = {
			observe: function(s,t,d) {
				this.observed = true;
			}
	};
	var obs2 = {
			QueryInterface: XPCOMUtils.generateQI([Ci.nsIRunnable]),
			observe: function(s,t,d) {
				this.observed = true;
			}
	};
	p.makeObserver(obs1);
	p.makeObserver(obs2);
	strictEqual(obs1.QueryInterface(Ci.nsIObserver), obs1, "QI works");
	throws(() => obs1.QueryInterface(Ci.nsIRunnable), "QI works (throws)");

	strictEqual(obs2.QueryInterface(Ci.nsIObserver), obs2, "QI2 works");
	strictEqual(obs2.QueryInterface(Ci.nsIRunnable), obs2, "Old QI2 works");

	var obs3 = {
			observe: function(s,t,d) {
				this.observed = true;
			}
	};

	var u1 = p.addObserver("extensions.dta", obs1);
	var u2 = p.addObserver("extensions.dta", obs2);
	var u3 = p.addObserver("extensions.dta", obs3);
	p.setExt("testObs", "yep");
	ok(obs1.observed && obs1.observed && obs3.observed, "all observers fired");

	u1(); u2(); u3();
	obs1.observed = false;

	p.setExt("testObs", "yeppy");
	p.resetExt("testObs");
	ok(!obs1.observed, "observers removed");
});
Ejemplo n.º 5
0
	async _processOne(download, data) {
		log(LOG_DEBUG, "ConflictManager: Starting conflict resolution for " + download);
		let dest = download.destinationLocalFile;
		let exists = this._pinned.has(dest.path);
		if (!exists) {
			exists = await OS.File.exists(dest.path);
			// recheck
			exists = exists || this._pinned.has(dest.path);
		}
		if (!exists) {
			log(LOG_DEBUG, "ConflictManager: Does not exist " + download);
			if (data.pinned) {
				this.pin(dest.path, true);
			}
			return dest.path;
		}

		let cr = -1;

		let conflicts = 0;
		const basename = download.destinationName;
		let newDest = download.destinationLocalFile.clone();

		if (this._prefs.conflictResolution !== 3) {
			cr = this._prefs.conflictResolution;
		}
		else if (download.shouldOverwrite) {
			cr = 1;
		}
		else if ('_sessionSetting' in this) {
			cr = this._sessionSetting;
		}
		else if ('_conflictSetting' in download) {
			cr = download._conflictSetting;
		}

		if (cr < 0) {
			let dialog = {};
			dialog.promise = new Promise(function(resolve, reject) {
				dialog.resolve = resolve;
				dialog.reject = reject;
			});
			conflicts = await this._findUnique(newDest, basename, conflicts);
			let options = {
				url: cropCenter(download.urlManager.usable, 45),
				fn: cropCenter(download.destinationLocalFile.leafName, 45),
				newDest: cropCenter(newDest.leafName, 45)
			};
			this._window.openDialog(
				"chrome://dta/content/dta/manager/conflicts.xul",
				"_blank",
				"chrome,centerscreen,resizable=no,dialog,close=no,dependent",
				options, dialog
				);
			let ctype = 0;
			[cr, ctype] = await dialog.promise;

			if (ctype === 1) {
				this._sessionSetting = cr;
			}
			else if (ctype === 2) {
				Preferences.setExt('conflictresolution', cr);
			}
			else {
				download._conflictSetting = cr;
			}
		}

		switch (cr) {
			case 0: {
				if (!data.pinned) {
					// No need to actually check here...
					// Check will be performed once we pin
					return;
				}
				conflicts = await this._findUnique(newDest, basename, conflicts);
				let pinned = null;
				if (data.pinned) {
					download.conflicts = conflicts;
					pinned = download.destinationFile;
					download.shouldOverwrite = false;
					this.pin(pinned, true);
				}
				log(LOG_DEBUG, "ConflictManager: resolved setting conflicts for " + download);
				return pinned;
			}
			case 1: {
				let pinned = null;
				if (data.pinned) {
					pinned = download.destinationFile;
					download.shouldOverwrite = true;
					this.pin(pinned, false);
				}
				return pinned;
			}
			default:
				download.cancel(this.l10n('skipped'));
				return false;
		}
	}