This repository has been archived by the owner on Feb 24, 2018. It is now read-only.
forked from darrinhenein/VerticalTabs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add embedded WebExtension + sync settings to new storage (darrinhenei…
- Loading branch information
Showing
4 changed files
with
194 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
"use strict" | ||
|
||
var port = browser.runtime.connect({name: "connection-to-legacy"}); | ||
|
||
|
||
// | ||
// Handle addon settings | ||
// | ||
|
||
function saveSettings(name, value) | ||
{ | ||
let settingsObject = {}; | ||
settingsObject[name] = value; | ||
|
||
browser.storage.local.set(settingsObject).then(error => | ||
{ | ||
if(error) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
} | ||
|
||
function getSettingsError(name) | ||
{ | ||
console.log("VTR WebExt setting '"+ name +"' not saved."); | ||
} | ||
|
||
function getSettings(name) | ||
{ | ||
return new Promise(function (fulfill, reject) | ||
{ | ||
browser.storage.local.get(name).then(results => | ||
{ | ||
if (!results[name]) | ||
{ | ||
getSettingsError(name); | ||
} | ||
|
||
fulfill(results[name]); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
// | ||
// Communication with the legacy part of the addon | ||
// | ||
|
||
function sdk_replyHandler(message) | ||
{ | ||
if(message.type == "settings.post") | ||
{ | ||
// the legacy part sent settings, save them | ||
saveSettings(message.name, message.value); | ||
} | ||
} | ||
|
||
port.onMessage.addListener(sdk_replyHandler); | ||
|
||
function sdk_sendMsg(message) | ||
{ | ||
browser.runtime.sendMessage(message).then(reply => | ||
{ | ||
if (reply) { | ||
sdk_replyHandler(reply); | ||
} | ||
}); | ||
} | ||
|
||
|
||
// Get all settings from the legacy part 10secs after startup | ||
setTimeout(function(){ | ||
sdk_sendMsg({type: "settings.get", name: "right"}); | ||
sdk_sendMsg({type: "settings.get", name: "hideInFullscreen"}); | ||
sdk_sendMsg({type: "settings.get", name: "theme"}); | ||
sdk_sendMsg({type: "settings.get", name: "tabtoolbarPosition"}); | ||
sdk_sendMsg({type: "settings.get", name: "toggleDisplayHotkey"}); | ||
sdk_sendMsg({type: "settings.get", name: "width"}); | ||
sdk_sendMsg({type: "settings.get", name: "debug"}); | ||
}, 10000); | ||
|
||
/*setInterval(function(){ | ||
getSettings("theme").then(value => { | ||
console.log("received theme setting: " + value); | ||
}); | ||
getSettings("toggleDisplayHotkey").then(value => { | ||
console.log("received toggleDisplayHotkey setting: " + value); | ||
}); | ||
getSettings().then(value => { | ||
console.log(value); | ||
}); | ||
}, 4000);*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "Vertical Tabs Reloaded", | ||
"version": "0.8.0-alpha", | ||
"manifest_version": 2, | ||
"permissions": ["storage"], | ||
"background": { | ||
"scripts": ["background.js"] | ||
} | ||
} |