Skip to content

Commit

Permalink
Merge pull request #35 from Cortys/2.2.0
Browse files Browse the repository at this point in the history
Version 2.2.0
Fixes #34
  • Loading branch information
Cortys committed Sep 12, 2015
2 parents 8da84c5 + ca1215d commit 85c1a4d
Show file tree
Hide file tree
Showing 14 changed files with 782 additions and 532 deletions.
12 changes: 12 additions & 0 deletions .jsbeautifyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"js": {
"indent_level": 0,
"indent_with_tabs": true,
"brace_style": "end-expand",
"space_after_anon_function": false,
"space_before_conditional": false,
"preserve_newlines": true,
"max_preserve_newlines": 2,
"end_with_newline": true
}
}
27 changes: 26 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,30 @@
"scripturl": true,
"eqnull": true,
"loopfunc": true,
"node": true
"browser": true,
"globalstrict": true,
"esnext": true,
"globals": {
"div": true,
"addTopBar": true,
"updateDialog": true,
"checkVersion": true,
"linkStyle": true,
"diff_match_patch": true,
"sanitizeFilename": true,
"rgbToHsl": true,
"hslToRgb": true,
"dataURLtoBlob": true,
"zip": true,
"getSettings": true,
"connector": true,
"downloadFile": true,
"nullFill": true,
"settings": true,
"updateDialog": true,
"randomString": true,
"Queue": true,
"chrome": true,
"TEMPORARY": true
}
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ The installation is slightly complicated (since I don't want to add this to the
There are two ways of installing the extension.

### *IMPORTANT* for Windows users
If you are using Chrome 35+ on Windows you have to use the [second possibility](#second-possibility)! Using packed extensions, that aren't from the Chrome Web Store, does not work anymore.
If you are using Chrome on Windows you have to use the [second possibility](#second-possibility)! Using packed extensions, that aren't from the Chrome Web Store, does not work anymore.

### First possibility

The first way is [by this help page](https://support.google.com/chrome_webstore/answer/2664769?hl=en). **This does not work on Windows with Chrome version 35+.**
The first way is [by this help page](https://support.google.com/chrome_webstore/answer/2664769?hl=en). **This does not work on Windows.**

- In Chrome, click on the settings icon on the right (looks like three vertical lines on top of each other)
- Select Tools > Extensions
Expand All @@ -31,7 +31,7 @@ The first way is [by this help page](https://support.google.com/chrome_webstore/

The second way is without drag-and-drop, https://developer.chrome.com/extensions/getstarted#unpacked

**This works for Windows with Chrome version 35+!**
**This works on Windows!**

- In Chrome, click on the settings icon on the right (looks like three vertical lines on top of each other)
- Select Tools > Extensions
Expand Down
Binary file modified download.zip
Binary file not shown.
Binary file modified extension.crx
Binary file not shown.
109 changes: 74 additions & 35 deletions source/backgroundManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ var ports = { // stores all opened connections of tabs to bg page: key = tab id,
if(typeof openers[sender] !== "undefined") {
var opener = ports.controller[openers[sender]];
if(opener) {
opener.send({ what:"child_message", tab:sender, message:{ what:"closed_background_tab" } });
opener.send({
what: "child_message",
tab: sender,
message: {
what: "closed_background_tab"
}
});
delete opener.children[sender];
}
delete openers[sender];
Expand All @@ -38,15 +44,16 @@ var ports = { // stores all opened connections of tabs to bg page: key = tab id,
getWriter = function(callback) {
var tmpName, run;
if(!settings.tempMemory || !requestFileSystem) {
callback(new zip.BlobWriter("application/"+(settings.container?"zip":"x-cbz")));
callback(new zip.BlobWriter("application/" + (settings.container ? "zip" : "x-cbz")));
fs = null;
}
else {
run = function() {
tmpName = "tmp"+(Date.now())+".zip";
tmpName = "tmp" + (Date.now()) + ".zip";

function create() {
fs.root.getFile(tmpName, {
create : true
create: true
}, function(zipFile) {
callback(new zip.FileWriter(zipFile), zipFile);
});
Expand All @@ -57,7 +64,7 @@ var ports = { // stores all opened connections of tabs to bg page: key = tab id,
};

if(!fs)
requestFileSystem(TEMPORARY, 4 * 1024 * 1024 * 1024, function (f) {
requestFileSystem(TEMPORARY, 4 * 1024 * 1024 * 1024, function(f) {
fs = f;
run();
});
Expand Down Expand Up @@ -85,41 +92,54 @@ getSettings(function() {
port.children = {}; // each connection stores the ids of the tabs it opened as children; key = tab id, value always true

/* ZIPPING logic
* moved to background script to have a dedicated tab/thread for compression so
* that it doesn't make the reader tab itself slow
*/
* moved to background script to have a dedicated tab/thread for compression so
* that it doesn't make the reader tab itself slow
*/
if(port.name == "reader")
port.receive(function(request, callback) {
if(request.what == "new_zip") {
getWriter(function (writer, zipFile) {
getWriter(function(writer, zipFile) {
port.zipFile = zipFile;
zip.createWriter(writer, function(writer) {
port.zip = writer;
port.user = request.user;
writer.add(".meta.asc", new zip.TextReader("This is a ComiXology backup.\nPlease do not distribute it.\nBackup created by "+(request.user||"[UNKNOWN USER]")));
callback({ what:"new_zip_created", error:false });
writer.add(".meta.asc", new zip.TextReader("This is a ComiXology backup.\nPlease do not distribute it.\nBackup created by " + (request.user || "[UNKNOWN USER]")));
callback({
what: "new_zip_created",
error: false
});
}, function() {
callback({ what:"zip_creation_failed", error:true });
callback({
what: "zip_creation_failed",
error: true
});
}, !settings.compression);
});
return true;
}
else if(request.what == "add_page") {
var name = "page"+nullFill(request.i, request.len)+"."+request.extension,
d = callback.bind(null, { what:"page_added", name:name });
var name = "page" + nullFill(request.i, request.len) + "." + request.extension,
d = callback.bind(null, {
what: "page_added",
name: name
});
if(request.toZip && port.zip) {
port.zip.add(name, new zip.Data64URIReader(request.page), function() {
d();
}, undefined, { comment: port.user });
}, undefined, {
comment: port.user
});
return true;
}
d();
}
else if(request.what == "start_zipping" && port.zip) {
port.zip.close(function(result) {
port.zip = null;
port.zipUrl = port.zipFile?port.zipFile.toURL():URL.createObjectURL(result);
callback({ what:"completed_zipping" });
port.zipUrl = port.zipFile ? port.zipFile.toURL() : URL.createObjectURL(result);
callback({
what: "completed_zipping"
});
});
return true;
}
Expand All @@ -131,17 +151,27 @@ getSettings(function() {
port.zipFile.remove(function() {
port.zipFile = null;
});
callback({ what:"download_complete" });
callback({
what: "download_complete"
});
});
return true;
}
else if(request.what == "message_to_opener" && openers[sender] !== "undefined" && ports.controller[openers[sender]]) {
ports.controller[openers[sender]].send({ what:"child_message", tab:sender, message:request.message }, callback);
ports.controller[openers[sender]].send({
what: "child_message",
tab: sender,
message: request.message
}, callback);
return true;
}
else if(request.what == "broadcast_to_openers") {
for(var tab in ports.controller) {
ports.controller[tab].send({ what:"child_broadcast", tab:sender, message:request.message }, callback);
ports.controller[tab].send({
what: "child_broadcast",
tab: sender,
message: request.message
}, callback);
}
return true;
}
Expand All @@ -151,13 +181,16 @@ getSettings(function() {
port.unlinked = true;
});
/*
* TAB HANDLING logic
* for the controller tabs (like "My Books")
*/
* TAB HANDLING logic
* for the controller tabs (like "My Books")
*/
else if(port.name == "controller")
port.receive(function(request, callback) {
if(request.what == "open_background_tab") {
chrome.tabs.create({ url:request.url, active:request.active }, function(tab) {
chrome.tabs.create({
url: request.url,
active: request.active
}, function(tab) {
openers[tab.id] = sender;
port.children[tab.id] = true;
ports.reader[tab.id] = true; // fake a reader port, as long as reader wasn't loaded, boolean to make it easy to check for "real" port objects
Expand All @@ -167,23 +200,26 @@ getSettings(function() {
}
else if(request.what == "close_background_tab")
chrome.tabs.remove(request.tab, function() {
chrome.runtime.lastError;
return chrome.runtime.lastError;
});
else if(request.what == "message_to_child" && typeof ports.reader[request.tab] === "object") {
ports.reader[request.tab].send({ what:"opener_message", message:request.message }, callback);
ports.reader[request.tab].send({
what: "opener_message",
message: request.message
}, callback);
return true;
}
});

var disconnectAction = port.name == "controller"?function() {
for (var tab in port.children)
// only not YET estabished or established linked port connections are allowed:
// children that once had a port are not closed (if the user started surfing in a backup tab)
var disconnectAction = port.name == "controller" ? function() {
for(var tab in port.children)
// only not YET estabished or established linked port connections are allowed:
// children that once had a port are not closed (if the user started surfing in a backup tab)
if(typeof ports.reader[tab] === "object" && !ports.reader[tab].unlinked)
chrome.tabs.remove(tab*1, function() {
chrome.runtime.lastError;
});
}:closedReader;
chrome.tabs.remove(tab * 1, function() {
return chrome.runtime.lastError;
});
} : closedReader;

port.onDisconnect.addListener(function() {
delete ports[port.name][sender];
Expand All @@ -196,7 +232,10 @@ getSettings(function() {

chrome.tabs.onRemoved.addListener(function(tab) {
if(ports.reader[tab] === true && tab in openers) // tab is a backup-purpose reader but there is no port connection yet:
closedReader({ senderId:tab, fake:true }); // port disconnect wont fire, so it will be "faked".
closedReader({
senderId: tab,
fake: true
}); // port disconnect wont fire, so it will be "faked".
});

// Old communication channel to options page. Separated from the port system to reduce memory and logic overhead.
Expand Down
Loading

0 comments on commit 85c1a4d

Please sign in to comment.