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