Skip to content

Commit

Permalink
Enable extension to sync files using chrome.storage.sync
Browse files Browse the repository at this point in the history
  • Loading branch information
d11e9 committed Apr 17, 2016
1 parent e44ceb8 commit 2206248
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
32 changes: 32 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@
}


// ----------------- storage --------------------

function syncStorage() {

var obj = {}

function check(key){
chrome.storage.sync.get( key, function(resp){
console.log("comparing to cloud", resp)
if (obj[key] !== resp[key] && confirm("Overwrite '" + fileNameFromKey(key) + "' from cloud storage?")) {
console.log("Overwriting", key )
localStorage.setItem( key, resp[key] );
updateFiles();
}
})
}

for (var y in window.localStorage) {
console.log("checking", y)
obj[y] = window.localStorage.getItem(y);
if (y.indexOf(SOL_CACHE_FILE_PREFIX) !== 0) continue;
check(y)
}

}

window.syncStorage = syncStorage;
if (chrome && chrome.storage && chrome.storage.sync) syncStorage()



// ----------------- editor ----------------------

Expand Down Expand Up @@ -801,4 +831,6 @@
return funABI;
};

syncStorage()

});
11 changes: 8 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({'url': chrome.extension.getURL('index.html')}, function(tab) {
// tab opened
});

chrome.storage.sync.set({"chrome-app-sync": true});


chrome.tabs.create({'url': chrome.extension.getURL('index.html')}, function(tab) {
// tab opened
});

});
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<link rel="stylesheet" href="assets/css/universal-dapp.css">
<link rel="stylesheet" href="assets/css/browser-solidity.css">
<link rel="stylesheet" href="assets/css/font-awesome.min.css">
<link rel="icon" type="x-icon" href="icon.png">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

<script src="https://ethereum.github.io/solc-bin/bin/list.js"></script>
Expand Down
14 changes: 9 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@
"description": "Realtime compiler and runtime",
"devtools_page": "devtools.html",
"update_url": "https://chriseth.github.io/browser-solidity/",
"version": "1.0",
"version": "1.1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"],
"persistent": true
},

"icons": {
"32": "icon.png"
},

"browser_action": {
"default_icon": "icon.png"
},

"permissions": [
"storage",
"tabs",
"activeTab",
"https://ajax.googleapis.com/",
"webRequest",
"webRequestBlocking",
"\u003Call_urls>",
"storage"
"webRequest",
"webRequestBlocking",
"\u003Call_urls>"
]
}

0 comments on commit 2206248

Please sign in to comment.