WIP chrome extension - using chrome's storage api, figuring out background scripts
This commit is contained in:
parent
b4bb64eba3
commit
49e19df1d1
14 changed files with 64 additions and 61 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
|||
/.idea/
|
||||
/.vscode/
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
<link rel="stylesheet" integrity="" href="{{rootURL}}assets/vendor.css">
|
||||
<link rel="stylesheet" integrity="" href="{{rootURL}}assets/huegasm.css"> {{content-for 'head-footer'}}
|
||||
|
||||
<script src="https://connect.soundcloud.com/sdk/sdk-3.1.2.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
|||
|
|
@ -13,16 +13,17 @@ export default Controller.extend({
|
|||
init() {
|
||||
this._super(...arguments);
|
||||
|
||||
let dimmerOn = chrome.storage.local.get('huegasm.dimmerOn'),
|
||||
lightsIconsOn = chrome.storage.local.get('huegasm.lightsIconsOn');
|
||||
chrome.storage.local.get('dimmerOn', ({dimmerOn}) => {
|
||||
chrome.storage.local.get('lightsIconsOn', ({lightsIconsOn}) => {
|
||||
if (!isEmpty(dimmerOn) && dimmerOn) {
|
||||
this.send('toggleDimmer');
|
||||
}
|
||||
|
||||
if (!isEmpty(dimmerOn) && dimmerOn) {
|
||||
this.send('toggleDimmer');
|
||||
}
|
||||
|
||||
if (!isEmpty(lightsIconsOn)) {
|
||||
this.set('lightsIconsOn', lightsIconsOn);
|
||||
}
|
||||
if (!isEmpty(lightsIconsOn)) {
|
||||
this.set('lightsIconsOn', lightsIconsOn);
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
|
@ -31,7 +32,7 @@ export default Controller.extend({
|
|||
|
||||
let lightsIconsOn = this.get('lightsIconsOn');
|
||||
|
||||
chrome.storage.local.set('huegasm.lightsIconsOn', lightsIconsOn);
|
||||
chrome.storage.local.set({ 'lightsIconsOn': lightsIconsOn });
|
||||
},
|
||||
toggleDimmer() {
|
||||
this.toggleProperty('dimmerOn');
|
||||
|
|
@ -46,7 +47,7 @@ export default Controller.extend({
|
|||
$('html').removeClass('dimmerOn');
|
||||
}
|
||||
|
||||
chrome.storage.local.set('huegasm.dimmerOn', dimmerOn);
|
||||
chrome.storage.local.set({ 'dimmerOn': dimmerOn });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ export default Component.extend({
|
|||
|
||||
if (status === 'success' && result.length === 1) {
|
||||
this.set('bridgeIp', result[0].internalipaddress);
|
||||
chrome.storage.local.set('huegasm.bridgeIp', result[0].internalipaddress);
|
||||
chrome.storage.local.set({ 'bridgeIp': result[0].internalipaddress });
|
||||
bridgeFindStatus = 'success';
|
||||
} else if (result.length > 1) {
|
||||
let multipleBridgeIps = this.get('multipleBridgeIps');
|
||||
|
|
@ -99,7 +99,8 @@ export default Component.extend({
|
|||
|
||||
if (status === 'success' && !result[0].error) {
|
||||
this.clearBridgePingIntervalHandle();
|
||||
chrome.storage.local.set('huegasm.bridgeUsername', result[0].success.username);
|
||||
debugger;
|
||||
chrome.storage.local.set({ 'bridgeUsername': result[0].success.username });
|
||||
this.set('bridgeUsername', result[0].success.username);
|
||||
}
|
||||
}
|
||||
|
|
@ -120,9 +121,9 @@ export default Component.extend({
|
|||
retry() {
|
||||
this.onBridgeIpChange();
|
||||
},
|
||||
chooseBridge(bridge) {
|
||||
this.set('bridgeIp', bridge);
|
||||
chrome.storage.local.set('huegasm.bridgeIp', bridge);
|
||||
chooseBridge(bridgeIp) {
|
||||
this.set('bridgeIp', bridgeIp);
|
||||
chrome.storage.local.set({ 'bridgeIp': bridgeIp });
|
||||
},
|
||||
findBridgeByIp() {
|
||||
let manualBridgeIp = this.get('manualBridgeIp');
|
||||
|
|
|
|||
|
|
@ -78,9 +78,11 @@ export default Component.extend({
|
|||
setInterval(this.updateLightData.bind(this), 2000);
|
||||
}
|
||||
|
||||
if (!isNone(chrome.storage.local.get('huegasm.selectedTab'))) {
|
||||
this.set('selectedTab', chrome.storage.local.get('huegasm.selectedTab'));
|
||||
}
|
||||
chrome.storage.local.get('selectedTab', ({selectedTab}) => {
|
||||
if (!isNone(selectedTab)) {
|
||||
this.set('selectedTab', selectedTab);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
updateLightData() {
|
||||
|
|
@ -112,11 +114,11 @@ export default Component.extend({
|
|||
changeTab(tabName) {
|
||||
let index = this.get('tabList').indexOf(tabName);
|
||||
this.set('selectedTab', index);
|
||||
chrome.storage.local.set('huegasm.selectedTab', index);
|
||||
chrome.storage.local.set({ 'selectedTab': index });
|
||||
},
|
||||
clearBridge() {
|
||||
chrome.storage.local.remove('huegasm.bridgeUsername');
|
||||
chrome.storage.local.remove('huegasm.bridgeIp');
|
||||
chrome.storage.local.remove('bridgeUsername');
|
||||
chrome.storage.local.remove('bridgeIp');
|
||||
location.reload();
|
||||
},
|
||||
toggleDimmer() {
|
||||
|
|
|
|||
|
|
@ -15,12 +15,14 @@ export default Component.extend({
|
|||
init() {
|
||||
this._super(...arguments);
|
||||
|
||||
if (!isEmpty(chrome.storage.local.get('huegasm.bridgeIp')) && !isEmpty(chrome.storage.local.get('huegasm.bridgeUsername'))) {
|
||||
this.setProperties({
|
||||
bridgeIp: chrome.storage.local.get('huegasm.bridgeIp'),
|
||||
bridgeUsername: chrome.storage.local.get('huegasm.bridgeUsername')
|
||||
chrome.storage.local.get('bridgeIp', ({bridgeIp}) => {
|
||||
chrome.storage.local.get('bridgeUsername', ({bridgeUsername}) => {
|
||||
this.setProperties({
|
||||
bridgeIp,
|
||||
bridgeUsername
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
|
|
|||
|
|
@ -86,29 +86,30 @@ export default Component.extend({
|
|||
}),
|
||||
|
||||
onActiveLightsChange: observer('activeLights.[]', function () {
|
||||
chrome.storage.local.set('huegasm.activeLights', this.get('activeLights'));
|
||||
chrome.storage.local.set({ 'activeLights': this.get('activeLights') });
|
||||
}),
|
||||
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
|
||||
let lightsData = this.get('lightsData'),
|
||||
activeLights = this.get('activeLights'),
|
||||
activeLightsCache = chrome.storage.local.get('huegasm.activeLights');
|
||||
activeLights = this.get('activeLights');
|
||||
|
||||
if (!isNone(activeLightsCache)) {
|
||||
activeLightsCache.forEach(function (i) {
|
||||
if (!isNone(lightsData) && lightsData.hasOwnProperty(i) && lightsData[i].state.reachable) {
|
||||
activeLights.pushObject(i);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
for (let key in lightsData) {
|
||||
if (lightsData.hasOwnProperty(key) && lightsData[key].state.reachable) {
|
||||
activeLights.pushObject(key);
|
||||
chrome.storage.local.get('activeLights', ({activeLightsCache}) => {
|
||||
if (!isNone(activeLightsCache)) {
|
||||
activeLightsCache.forEach(function (i) {
|
||||
if (!isNone(lightsData) && lightsData.hasOwnProperty(i) && lightsData[i].state.reachable) {
|
||||
activeLights.pushObject(i);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
for (let key in lightsData) {
|
||||
if (lightsData.hasOwnProperty(key) && lightsData[key].state.reachable) {
|
||||
activeLights.pushObject(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
|
|
|||
|
|
@ -122,7 +122,9 @@ export default Component.extend({
|
|||
this.get('kick').set({ threshold: value });
|
||||
}
|
||||
|
||||
chrome.storage.local.set('huegasm.' + name, value);
|
||||
let toSave = {};
|
||||
toSave[name] = value;
|
||||
chrome.storage.local.set(toSave);
|
||||
},
|
||||
|
||||
simulateKick(/*mag, ratioKickMag*/) {
|
||||
|
|
@ -223,15 +225,15 @@ export default Component.extend({
|
|||
});
|
||||
|
||||
['threshold', 'playerBottomDisplayed', 'flashingTransitions', 'colorloopMode', 'hueRange', 'brightnessRange'].forEach((item) => {
|
||||
if (!isNone(chrome.storage.local.get('huegasm.' + item))) {
|
||||
let itemVal = chrome.storage.local.get('huegasm.' + item);
|
||||
|
||||
if (isNone(this.actions[item + 'Changed'])) {
|
||||
this.set(item, itemVal);
|
||||
} else {
|
||||
this.send(item + 'Changed', itemVal);
|
||||
chrome.storage.local.get(item, ({itemVal}) => {
|
||||
if (!isNone(itemVal)) {
|
||||
if (isNone(this.actions[item + 'Changed'])) {
|
||||
this.set(item, itemVal);
|
||||
} else {
|
||||
this.send(item + 'Changed', itemVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
// preload images
|
||||
#hue-controls:after, md-progress-circular:after {
|
||||
display: none;
|
||||
content: url(images/colormap.png) url(images/missingArtwork.png) url(images/sc-white.png) url(images/huegasm.png) url(images/lights/a19.svg) url(images/lights/a19w.svg) url(images/lights/br30.svg) url(images/lights/br30w.svg) url(images/lights/gu10.svg) url(images/lights/gu10w.svg) url(images/lights/huego.svg) url(images/lights/huegow.svg) url(images/lights/lc_aura.svg) url(images/lights/lc_auraw.svg) url(images/lights/lc_bloom.svg) url(images/lights/lc_bloomw.svg) url(images/lights/lc_iris.svg) url(images/lights/lc_irisw.svg) url(images/lights/lightstrip.svg) url(images/lights/lightstripw.svg) url(images/lights/storylight.svg) url(images/lights/storylightw.svg);
|
||||
content: url(images/colormap.png) url(images/huegasm.png) url(images/lights/a19.svg) url(images/lights/a19w.svg) url(images/lights/br30.svg) url(images/lights/br30w.svg) url(images/lights/gu10.svg) url(images/lights/gu10w.svg) url(images/lights/huego.svg) url(images/lights/huegow.svg) url(images/lights/lc_aura.svg) url(images/lights/lc_auraw.svg) url(images/lights/lc_bloom.svg) url(images/lights/lc_bloomw.svg) url(images/lights/lc_iris.svg) url(images/lights/lc_irisw.svg) url(images/lights/lightstrip.svg) url(images/lights/lightstripw.svg) url(images/lights/storylight.svg) url(images/lights/storylightw.svg);
|
||||
}
|
||||
|
||||
#navigation {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"broccoli-asset-rev": "^2.2.0",
|
||||
"ember-ajax": "^2.0.1",
|
||||
"ember-cli": "^2.8.0",
|
||||
"ember-cli-app-version": "^2.0.0",
|
||||
"ember-cli-babel": "^5.1.5",
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB |
|
|
@ -9,11 +9,9 @@
|
|||
"128": "128x128.png"
|
||||
},
|
||||
"background": {
|
||||
"background": {
|
||||
"scripts": [
|
||||
"background.js"
|
||||
]
|
||||
},
|
||||
"scripts": [
|
||||
"background.js"
|
||||
]
|
||||
},
|
||||
"browser_action": {
|
||||
"default_icon": {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"broccoli-asset-rev": "^2.2.0",
|
||||
"ember-ajax": "^2.0.1",
|
||||
"ember-cli": "^2.11.0",
|
||||
"ember-cli-app-version": "^2.0.0",
|
||||
"ember-cli-babel": "^5.1.5",
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"broccoli-asset-rev": "^2.2.0",
|
||||
"ember-ajax": "^2.0.1",
|
||||
"ember-cli": "^2.8.0",
|
||||
"ember-cli-app-version": "^2.0.0",
|
||||
"ember-cli-babel": "^5.1.5",
|
||||
|
|
|
|||
Reference in a new issue