[Pkg-mozext-commits] [tabmixplus] 40/61: Use OS.File to import/export our preferences file asynchronicity, update changeset 908c146f670b to support Pale Moon. Pale Moon 25.6.0 doesn't support generator functions and some OS.file arguments are different
David Prévot
taffit at moszumanska.debian.org
Fri Aug 28 19:09:21 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository tabmixplus.
commit 67cb3948d6c5800d590f78ae95f732bd3aed5bf9
Author: onemen <tabmix.onemen at gmail.com>
Date: Thu Aug 6 19:25:03 2015 +0300
Use OS.File to import/export our preferences file asynchronicity, update changeset 908c146f670b to support Pale Moon. Pale Moon 25.6.0 doesn't support generator functions and some OS.file arguments are different
---
chrome/content/preferences/preferences.js | 37 +++++++++++++++----------------
modules/AsyncUtils.jsm | 10 ++++-----
2 files changed, 22 insertions(+), 25 deletions(-)
diff --git a/chrome/content/preferences/preferences.js b/chrome/content/preferences/preferences.js
index ea8e0ef..7539c2b 100644
--- a/chrome/content/preferences/preferences.js
+++ b/chrome/content/preferences/preferences.js
@@ -413,30 +413,29 @@ function toggleSyncPreference() {
function exportData() {
// save all pending changes
gPrefWindow.onApply();
-
- let patterns = gPreferenceList.map(function(pref) {
- return pref + "=" + getPrefByType(pref) + "\n";
- });
- patterns[patterns.length-1] = patterns[patterns.length-1].replace(/\n$/, "");
- patterns.unshift("tabmixplus\n");
- Task.spawn(function* () {
- let file = yield showFilePicker("save");
+ showFilePicker("save").then(file => {
if (file) {
- yield OS.File.writeAtomic(file.path, patterns.join(""), {encoding: "utf-8"});
+ let patterns = gPreferenceList.map(function(pref) {
+ return "\n" + pref + "=" + getPrefByType(pref);
+ });
+ patterns.unshift("tabmixplus");
+ return OS.File.writeAtomic(file.path, patterns.join(""), {
+ encoding: "utf-8", tmpPath: file.path + ".tmp"
+ });
}
- }).catch(Tabmix.reportError);
+ }).then(null, Tabmix.reportError);
}
function importData () {
- Task.spawn(function* () {
- let file = yield showFilePicker("open");
- if (file) {
- let input = yield OS.File.read(file.path, {encoding: "utf-8"});
- if (input) {
- loadData(input.replace(/\r\n/g, "\n").split("\n"));
- }
+ showFilePicker("open").then(file => {
+ return file && OS.File.read(file.path);
+ }).then((input) => {
+ if (input) {
+ let decoder = new TextDecoder();
+ input = decoder.decode(input);
+ loadData(input.replace(/\r\n/g, "\n").split("\n"));
}
- }).catch(Tabmix.reportError);
+ }).then(null, Tabmix.reportError);
}
/**
@@ -460,7 +459,7 @@ function showFilePicker(mode) {
fp.init(window, null, mode);
fp.appendFilters(nsIFilePicker.filterText);
return AsyncUtils.spawnFn(fp, fp.open).then(aResult => {
- if (aResult == nsIFilePicker.returnOK)
+ if (aResult != nsIFilePicker.returnCancel)
return fp.file;
});
}
diff --git a/modules/AsyncUtils.jsm b/modules/AsyncUtils.jsm
index 30b1a52..3d1649c 100644
--- a/modules/AsyncUtils.jsm
+++ b/modules/AsyncUtils.jsm
@@ -45,15 +45,13 @@ this.AsyncUtils = {
};
function Deferred() {
- this.resolve = null;
- this.reject = null;
+ let defer = Promise.defer();
+ this.promise = defer.promise;
+ this.resolve = defer.resolve;
+ this.reject = defer.reject;
this.callback = (result, error) => {
if (error)
return this.reject(error);
return this.resolve(result);
};
- this.promise = new Promise((resolve, reject) => {
- this.resolve = resolve;
- this.reject = reject;
- });
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/tabmixplus.git
More information about the Pkg-mozext-commits
mailing list