Skip to content

Commit

Permalink
fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jae-jae committed May 5, 2018
1 parent 2eec8a5 commit 9cc37eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "__MSG_appName__",
"version": "0.0.3",
"version": "0.0.4",
"manifest_version": 2,
"description": "__MSG_appDescription__",
"author": "Jaeger <[email protected]>",
Expand Down
31 changes: 21 additions & 10 deletions app/scripts.babel/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ chrome.runtime.onInstalled.addListener(details => {
console.log('previousVersion', details.previousVersion);
});

let enabled = localStorage['enabled'];
let size = localStorage['size'] === undefined ? 0 : localStorage['size']
size = size * 1024 * 1024;
let path = localStorage['path'] === undefined ? 'http://localhost:6800/jsonrpc' : localStorage['path'];
let preNum = 0;

var getStorage = (key) => {
if (key === 'size') {
let size = localStorage['size'] === undefined ? 0 : localStorage['size']
size = size * 1024 * 1024
return size
} else if(key === 'path') {
let path = localStorage['path'] === undefined ? 'http://localhost:6800/jsonrpc' : localStorage['path']
return path
}
return localStorage[key]
}

var notice = (message,title = 'Camtd') => {
chrome.notifications.create({
type: 'basic',
Expand Down Expand Up @@ -68,15 +76,15 @@ chrome.notifications.onClicked.addListener(function(itemId){
chrome.downloads.onDeterminingFilename.addListener(add);

function add(down) {
if (!path) {
if (!getStorage('path')) {
alert('Camtd has not been configured');
chrome.tabs.create({ 'url': 'options.html' }, function (s) { });
return 0;
}
if (enabled == 0) {
if (getStorage('enabled') == 0) {
return 0;
}
if (Math.abs(down.fileSize) > size) {
if (Math.abs(down.fileSize) > getStorage('size')) {
chrome.downloads.cancel(down.id, function (s) { });
getUrlCookie(down.url, (cookies) => {
var aria2_obj = combination(down,cookies);
Expand All @@ -94,7 +102,7 @@ function add(down) {

function postaria2obj(addobj, callback = null) {
var httppost = new XMLHttpRequest();
var aria2jsonrpcpath = path;
var aria2jsonrpcpath = getStorage('path');
httppost.open('POST', aria2jsonrpcpath + '?tm=' + (new Date()).getTime().toString(), true);
var ifregurl = aria2url_reg(aria2jsonrpcpath);
if (ifregurl) {
Expand All @@ -105,7 +113,10 @@ function postaria2obj(addobj, callback = null) {
}
}
httppost.onerror = function () {
notice('Error adding tasks to aria2,please check the configuration!','Error');
console.log('Error aria2 configuration!');
if (addobj[0] && addobj[0].method === 'aria2.addUri') {
notice('Error adding tasks to aria2,please check the configuration!','Error');
}
};
httppost.addEventListener('load', function () {
let rt = JSON.parse(this.responseText)
Expand Down Expand Up @@ -174,7 +185,7 @@ function rightadd(info, tab) {
var down = { filename: '' };
down.finalUrl = info.linkUrl;
down.referrer = info.pageUrl;
if (!path) {
if (!getStorage('path')) {
alert('Camtd has not been configured');
chrome.tabs.create({ 'url': 'options.html' }, function (s) { });
return 0;
Expand Down

0 comments on commit 9cc37eb

Please sign in to comment.