Skip to content

Commit

Permalink
unpublishing api key
Browse files Browse the repository at this point in the history
  • Loading branch information
alicescfernandes committed Mar 6, 2021
1 parent 33858c1 commit 4541e09
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
build
build
**/keys.json
16 changes: 12 additions & 4 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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() {
Expand Down Expand Up @@ -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 = '';
Expand Down
4 changes: 3 additions & 1 deletion common/constants.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const API_KEY = "80dcebdcd7e07d1de5b23c35f5db197f";
import * as fs from 'fs';

export const API_KEY = '80dcebdcd7e07d1de5b23c35f5db197f';
13 changes: 9 additions & 4 deletions companion/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);
}
});
Expand Down

0 comments on commit 4541e09

Please sign in to comment.