From 49e19df1d1218c828e2e9c6badb4ba7468c8af9e Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 17 Feb 2017 00:05:40 -0800 Subject: [PATCH] WIP chrome extension - using chrome's storage api, figuring out background scripts --- .gitignore | 1 + chrome/app/index.html | 2 -- chrome/app/pods/application/controller.js | 23 +++++++------- .../components/bridge-finder/component.js | 11 ++++--- .../pods/components/hue-controls/component.js | 14 +++++---- .../pods/components/huegasm-app/component.js | 12 +++++--- .../pods/components/light-group/component.js | 29 +++++++++--------- .../pods/components/music-tab/component.js | 20 ++++++------ chrome/app/styles/hue-controls.scss | 2 +- chrome/package.json | 1 - .../public/assets/images/missingArtwork.png | Bin 1867 -> 0 bytes chrome/public/manifest.json | 8 ++--- mobile/package.json | 1 - web/package.json | 1 - 14 files changed, 64 insertions(+), 61 deletions(-) delete mode 100644 chrome/public/assets/images/missingArtwork.png diff --git a/.gitignore b/.gitignore index 85e7c1d..d0038b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.idea/ +/.vscode/ diff --git a/chrome/app/index.html b/chrome/app/index.html index 297c7f4..e093db1 100644 --- a/chrome/app/index.html +++ b/chrome/app/index.html @@ -14,8 +14,6 @@ {{content-for 'head-footer'}} - - diff --git a/chrome/app/pods/application/controller.js b/chrome/app/pods/application/controller.js index d1497ec..a117a59 100644 --- a/chrome/app/pods/application/controller.js +++ b/chrome/app/pods/application/controller.js @@ -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 }); } } }); diff --git a/chrome/app/pods/components/bridge-finder/component.js b/chrome/app/pods/components/bridge-finder/component.js index 603ceac..c36715b 100644 --- a/chrome/app/pods/components/bridge-finder/component.js +++ b/chrome/app/pods/components/bridge-finder/component.js @@ -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'); diff --git a/chrome/app/pods/components/hue-controls/component.js b/chrome/app/pods/components/hue-controls/component.js index dd5c04d..0f20356 100644 --- a/chrome/app/pods/components/hue-controls/component.js +++ b/chrome/app/pods/components/hue-controls/component.js @@ -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() { diff --git a/chrome/app/pods/components/huegasm-app/component.js b/chrome/app/pods/components/huegasm-app/component.js index 6c951a1..fa2e451 100644 --- a/chrome/app/pods/components/huegasm-app/component.js +++ b/chrome/app/pods/components/huegasm-app/component.js @@ -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: { diff --git a/chrome/app/pods/components/light-group/component.js b/chrome/app/pods/components/light-group/component.js index 6def914..cb2679a 100644 --- a/chrome/app/pods/components/light-group/component.js +++ b/chrome/app/pods/components/light-group/component.js @@ -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: { diff --git a/chrome/app/pods/components/music-tab/component.js b/chrome/app/pods/components/music-tab/component.js index cb62fa5..1672cd1 100644 --- a/chrome/app/pods/components/music-tab/component.js +++ b/chrome/app/pods/components/music-tab/component.js @@ -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); + } } - } + }); }); }, diff --git a/chrome/app/styles/hue-controls.scss b/chrome/app/styles/hue-controls.scss index e517619..90baa9c 100644 --- a/chrome/app/styles/hue-controls.scss +++ b/chrome/app/styles/hue-controls.scss @@ -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 { diff --git a/chrome/package.json b/chrome/package.json index b05c55d..c232c52 100644 --- a/chrome/package.json +++ b/chrome/package.json @@ -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", diff --git a/chrome/public/assets/images/missingArtwork.png b/chrome/public/assets/images/missingArtwork.png deleted file mode 100644 index 3cf2548d612a45a8439500adba79db945260f274..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1867 zcmV-R2ekN!P)1O9>>1D37-vlf3RF~7|BD;t_i2NJ zga6e4ii|7y{!_`x$tWo&i;If`gp_&8r2TvxJthv0n zOaZa6vCZ3CV`F2(-E!&a={v-{|E(0ue-KJ!M4_Rf|G5;@@_s8fGvnw=mtqO%a2Wit z5C5eZKsz+S!NLE*2YPyY^!ZT#bRTL(2Y7S|w0#Ml(vAQAGM01$zUYc&Y9r&B5AsbN z0m|i8XE=J9Ts%BGa&mIEwzl?y8q0|c$2Asy(yIy7-qzOElQ9qQ@bJ8|1G>7p{bL{e zrW9z^y*4ZYY*+#Rsu`iykG*3OsH-%ps;YNg0rT_o8z~}z+q10Um1fPg0KCsABpWSO%;{Eg0- zhQyL*d`I>5^$NYj|M396zP^Q|V&2}~|NjR$B^1WS#*EFElGL5AW)C_xHvioM2NDt4 z+1dZl1^`4$rlzLv>n;EP|6RhYYhVFDKtBKU0CQ>qARZYtI2->|BKMCO|Nj8@cpI$f zp6^Z_{qqL<@dp0>{*#lFw6P(hDiZ(y2msROvgn!o`7dg-l7{5F-}`{@l@yw%M*zIx z@uUx8o_uN&3&$83X4%5-w*%jJ7L$npg4wUZSQPc<0UIeT|Gx+|aANIS8o}$0!S0a7 z@sa{rUjjW#0IS(>cP>nwiBqbUT)(UT&j`=!cmT-w3c|*zbqKU^4aKAY*{cHdcN_UQ z9+Sa=eL)M&lM03x4pLbro}n^iVGsaYXK#N$iDCpsQ7imVA1sK1ine)EfMUbHAOcEL z0JqryxXQT1QT$&W5F;cxFCqp%KL|Wq@&Et>;Ymb6RCwBASWW?87}Y$KHP6Ul7uQo0 z(O3ln8fvzQvM$pWRS=_@RXkx9Td=U_qfo{tLPA0vrMjk*oH^Wk+(r163282?GdbtQ z!%*bfx_E){>WwqQrNrE>T5_eW(2-lx?uTEqwP0#)kb)>@L!S3VZixlP+m?BlF>4ji zO{-BT)A@PyQo_q zOyimM-&K70>!$^;$PCst-Bb3&-h7{+ zz8$A#L!iyM=7RhfF`A{mN}Kn`1>4!GxNS~+4fJ!+xmEp`3Bpfi6+7#8JfXdPn&9)# z&E`C8>{yah7Qqyzu?rYgJS8%!WTb7N)iHm7QN^~DoQ$zuV^^;ECeGgZs^sLV*@BmY zo{2ILXEjEyvds+Il+5th5X4TB$dW2I$_Q)TF2cgO!Ka7~nDNWj>;{!2SBmGz zH!1R7$ReTulzl0>fq~D;W&3jVg6xjc!@BV=<^nZqCvGP~vo#yA7;^OtSiW2}Ktn`C zO=IC#E}-WB*2EOO8MBf(8~8%iU>4;lRnL{L(dn@#MzgZgX`tp;@O&9CY3~I2lV3!L zD)jqT^>Q{iM%TlVw_3dA9Ql(RJBX_>G)fp69FMMLg@*q8>D6=6R`jS7r&*1Kp&`%p zqah?I>wRi0o^bY#`()xYCklf!FSZf~hy6O{$gl}jw+)G`=-5pd81lRqKlKF#nXT?Y zU(h8~ELB-HDCK-EDno`zlQx-3lFak9z`rM|k%^|HFmQxo2YtWeD(u=zhm(gCx zDAd*U{q39f4ANVG6|y1;_4NrNJ1Rz7y`!23NHaiy0RWK8K^HTIDhL1o002ovPDHLk FV1oB7oW=kE diff --git a/chrome/public/manifest.json b/chrome/public/manifest.json index 2208354..61634b0 100644 --- a/chrome/public/manifest.json +++ b/chrome/public/manifest.json @@ -9,11 +9,9 @@ "128": "128x128.png" }, "background": { - "background": { - "scripts": [ - "background.js" - ] - }, + "scripts": [ + "background.js" + ] }, "browser_action": { "default_icon": { diff --git a/mobile/package.json b/mobile/package.json index 4160019..dac321b 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -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", diff --git a/web/package.json b/web/package.json index 7e5d052..3de24d9 100644 --- a/web/package.json +++ b/web/package.json @@ -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",