Skip to content

Commit

Permalink
get rid of blob-urls so they can be garbage collected. fixes a memory…
Browse files Browse the repository at this point in the history
… leak.
  • Loading branch information
pmario committed Aug 7, 2018
1 parent e1e0903 commit 3a8a1e7
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions background_scripts/background.js
Expand Up @@ -40,7 +40,6 @@ var Facet = function ( /* [fields,] fields */ ) {
delete this.fields[t]; // If we get a field that's undefined, delete any previous field value
}
} else {
// Parse the field with the associated field module (if any)
var value = src[t];
// Freeze the field to keep it immutable
if (value != null && typeof value === "object") {
Expand All @@ -50,7 +49,7 @@ var Facet = function ( /* [fields,] fields */ ) {
}
}
}
// Freeze the tiddler against modification
// Freeze the facet against modification
Object.freeze(this.fields);
Object.freeze(this);
};
Expand Down Expand Up @@ -224,12 +223,16 @@ async function createBackup(message) {
var pathX = path.parse(message.path);
var nameX = path.join(message.subdir, backupdir, pathX.base, pathX.name + "(" + nextChar + ")" + pathX.ext);

var element = URL.createObjectURL(new Blob([message.txt], {type: "text/plain"}));

itemId = await browser.downloads.download({
url: URL.createObjectURL(new Blob([message.txt], {type: "text/plain"})),
url: element,
filename: nameX,
conflictAction: "overwrite"
})

if (element) URL.revokeObjectURL(element);

if (itemId) {
results = await browser.downloads.search({id: itemId});
} // if itemId
Expand Down Expand Up @@ -258,12 +261,17 @@ async function downloadWiki(message) {
// let test = path.join(message.subdir, path.basename(message.path));

// needed, for a roundtrip, to set up the right save directory.

var element = URL.createObjectURL(new Blob([message.txt], { type: "text/plain"}));

itemId = await browser.downloads.download({
url: URL.createObjectURL(new Blob([message.txt], { type: "text/plain"})),
url: element,
filename: path.join(message.subdir, path.basename(message.path)),
conflictAction: "overwrite"
});

if (element) URL.revokeObjectURL(element);

if (itemId) {
results = await browser.downloads.search({id: itemId});
}
Expand All @@ -289,13 +297,17 @@ async function downloadDialog(message) {
results,
response = {};

var element = URL.createObjectURL(new Blob([message.txt], {type: "text/plain"}));

itemId = await browser.downloads.download({
url: URL.createObjectURL(new Blob([message.txt], {type: "text/plain"})),
url: element,
filename: path.basename(message.path),
conflictAction: "overwrite",
saveAs: true
})

if (element) URL.revokeObjectURL(element);

if (itemId) {
results = await browser.downloads.search({id: itemId});
}
Expand All @@ -318,12 +330,16 @@ to find out the default position, to save your TiddlyWiki.<br/>
You can delete it if you want. It will be recreated, if needed.<br/>
`;

var element = URL.createObjectURL(new Blob([template], {type: "text/plain"}));

itemId = await browser.downloads.download({
url: URL.createObjectURL(new Blob([template], {type: "text/plain"})),
url: element,
filename: "beakon.tmp.html",
conflictAction: "overwrite"
});

if (element) URL.revokeObjectURL(element);

if (itemId) {
results = await browser.downloads.search({id: itemId});
}
Expand Down

0 comments on commit 3a8a1e7

Please sign in to comment.