Browse Source

fix config export in safari

Gildas 3 years ago
parent
commit
d6961bb432
3 changed files with 28 additions and 12 deletions
  1. 0 0
      lib/single-file-extension-background.js
  2. 19 10
      src/core/bg/config.js
  3. 9 2
      src/ui/bg/ui-options.js

File diff suppressed because it is too large
+ 0 - 0
lib/single-file-extension-background.js


+ 19 - 10
src/core/bg/config.js

@@ -526,16 +526,25 @@ async function resetProfile(profileName) {
 
 async function exportConfig() {
 	const config = await getConfig();
-	const url = URL.createObjectURL(new Blob([JSON.stringify({ profiles: config.profiles, rules: config.rules, maxParallelWorkers: config.maxParallelWorkers }, null, 2)], { type: "text/json" }));
-	const downloadInfo = {
-		url,
-		filename: `singlefile-settings-${(new Date()).toISOString().replace(/:/g, "_")}.json`,
-		saveAs: true
-	};
-	try {
-		await download(downloadInfo, "_");
-	} finally {
-		URL.revokeObjectURL(url);
+	const textContent = JSON.stringify({ profiles: config.profiles, rules: config.rules, maxParallelWorkers: config.maxParallelWorkers }, null, 2);
+	const filename = `singlefile-settings-${(new Date()).toISOString().replace(/:/g, "_")}.json`;
+	if (IS_NOT_SAFARI) {
+		const url = URL.createObjectURL(new Blob([textContent], { type: "text/json" }));
+		try {
+			await download({
+				url,
+				filename,
+				saveAs: true
+			}, "_");
+		} finally {
+			URL.revokeObjectURL(url);
+		}
+		return {};
+	} else {
+		return {
+			filename,
+			textContent
+		};
 	}
 }
 

+ 9 - 2
src/ui/bg/ui-options.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global browser, window, document, localStorage, FileReader, location, fetch, TextDecoder, DOMParser, HTMLElement */
+/* global browser, window, document, localStorage, FileReader, location, fetch, TextDecoder, DOMParser, HTMLElement, MouseEvent */
 
 const HELP_ICON_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABIUlEQVQ4y+2TsarCMBSGvxTBRdqiUZAWOrhJB9EXcPKFfCvfQYfulUKHDqXg4CYUJSioYO4mSDX3ttzt3n87fMlHTpIjlsulxpDZbEYYhgghSNOUOI5Ny2mZYBAELBYLer0eAJ7ncTweKYri4x7LJJRS0u12n7XrukgpjSc0CpVSXK/XZ32/31FKNW85z3PW6zXT6RSAJEnIsqy5UGvNZrNhu90CcDqd+C6tT6J+v//2Th+PB2VZ1hN2Oh3G4zGTyQTbtl/YbrdjtVpxu91+Ljyfz0RRhG3bzOfzF+Y4TvNXvlwuaK2pE4tfzr/wzwsty0IIURlL0998KxRCMBqN8H2/wlzXJQxD2u12vVkeDoeUZUkURRU+GAw4HA7s9/sK+wK6CWHasQ/S/wAAAABJRU5ErkJggg==";
 const HELP_PAGE_PATH = "/src/ui/pages/help.html";
@@ -432,7 +432,14 @@ resetButton.addEventListener("click", async event => {
 	}
 }, false);
 exportButton.addEventListener("click", async () => {
-	await browser.runtime.sendMessage({ method: "config.exportConfig" });
+	const response = await browser.runtime.sendMessage({ method: "config.exportConfig" });
+	if (response.filename && response.textContent) {
+		const link = document.createElement("a");
+		link.download = response.filename;
+		link.href = "data:application/octet-stream," + response.textContent;
+		link.target = "_blank";
+		link.dispatchEvent(new MouseEvent("click"));
+	}
 }, false);
 importButton.addEventListener("click", () => {
 	fileInput.onchange = async () => {

Some files were not shown because too many files changed in this diff