From 4541e095c3f397939b5c2b7fab19272af996c4fe Mon Sep 17 00:00:00 2001 From: Alice Fernandes Date: Sat, 6 Mar 2021 18:17:53 +0000 Subject: [PATCH] unpublishing api key --- .gitignore | 3 ++- app/index.js | 16 ++++++++++++---- common/constants.js | 4 +++- companion/index.js | 13 +++++++++---- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index b7dab5e..7d3e6a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -build \ No newline at end of file +build +**/keys.json \ No newline at end of file diff --git a/app/index.js b/app/index.js index 9124e66..64ea8a4 100644 --- a/app/index.js +++ b/app/index.js @@ -7,6 +7,9 @@ import { battery } from 'power'; import { HeartRateSensor } from 'heart-rate'; import { preferences } from 'user-settings'; import { me } from 'appbit'; +import { readFileSync } from 'fs'; + +let settings = readFileSync('/mnt/assets/resources/keys.json', 'json'); //icons by https://www.deviantart.com/ncrystal/art/Google-Now-Weather-Icons-597652261 @@ -31,12 +34,12 @@ let parseWeatherData = (evt) => { }; let startCompanionConnection = (evt) => { - messaging.peerSocket.send('clock_ready'); + messaging.peerSocket.send({ event: 'clock_ready', key: settings.OPEN_WEATHER_API }); deviceStarted = true; }; let closeCompanionConnection = (evt) => { - messaging.peerSocket.send('clock_close'); + messaging.peerSocket.send({ event: clock_close }); }; function renderFace() { @@ -99,15 +102,20 @@ clock.ontick = (evt) => { let today = evt.date; let hours = today.getHours(); let mins = util.zeroPad(today.getMinutes()); + console.log(hours); if (preferences.clockDisplay === '12h') { time_element.x = 336 / 2 - 25; if (hours > 12) { - hour_element.text = 'PM'; hours = hours % 12; + hour_element.text = 'PM'; } else { - hour_element.text = 'AM'; + if (hours >= 12) { + hour_element.text = 'PM'; + } else { + hour_element.text = 'AM'; + } } } else { hour_element.text = ''; diff --git a/common/constants.js b/common/constants.js index be41979..82dedd7 100644 --- a/common/constants.js +++ b/common/constants.js @@ -1 +1,3 @@ -export const API_KEY = "80dcebdcd7e07d1de5b23c35f5db197f"; \ No newline at end of file +import * as fs from 'fs'; + +export const API_KEY = '80dcebdcd7e07d1de5b23c35f5db197f'; diff --git a/companion/index.js b/companion/index.js index bc4ff8c..9bb3351 100644 --- a/companion/index.js +++ b/companion/index.js @@ -1,11 +1,11 @@ import { me as companion } from 'companion'; import * as util from '../common/utils'; import * as messaging from 'messaging'; -import { API_KEY } from '../common/constants'; import { settingsStorage } from 'settings'; import { geolocation } from 'geolocation'; -const MILLISECONDS_PER_MINUTE = 1000 * 60; +let API_KEY = ''; +const MILLISECONDS_PER_MINUTE = 1000 * 60; function getSetings() { let city = undefined; let key = API_KEY; @@ -47,9 +47,12 @@ function locationError(city, key) { } function fetchWeather() { + console.log('fetchWeather'); let { city, key, useGeolocation } = getSetings(); if (useGeolocation === 'true') { + console.log('fetchWeather'); + geolocation.getCurrentPosition( (evt) => locationSuccess(evt, key), (evt) => locationError(city, key), @@ -77,11 +80,13 @@ function init() { } messaging.peerSocket.addEventListener('message', (evt) => { - if (evt.data === 'clock_ready') { + if (evt.data.event === 'clock_ready') { + API_KEY = evt.data.key; + console.log(API_KEY); fetchWeather(); companion.addEventListener('wakeinterval', fetchWeather); } - if (evt.data === 'clock_close') { + if (evt.data.event === 'clock_close') { companion.removeEventListener('wakeinterval', fetchWeather); } });