Skip to content

Commit

Permalink
More settings page improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tilden committed Dec 27, 2018
1 parent 5dc6a93 commit 4569b78
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 161 deletions.
48 changes: 44 additions & 4 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
import { me } from "appbit";
import clock from 'clock';
import document from 'document';
import { today } from 'user-activity';
import { HeartRateSensor } from "heart-rate";
import { preferences } from 'user-settings';
import { language_names, weekday_names, month_names } from './localDates'
import * as fs from "fs";
import * as messaging from 'messaging';
import { language_names, weekday_names, month_names } from './localDates';
import * as util from '../common/utils';

// Update the clock every minute
// BEGIN settings nonsense

const SETTINGS_TYPE = "cbor";
const SETTINGS_FILE = "settings.cbor";

let settings = loadSettings();
console.log("the settings are...")
console.log(JSON.stringify(settings));

me.onunload = saveSettings;

function loadSettings() {
try {
return fs.readFileSync(SETTINGS_FILE, SETTINGS_TYPE);
} catch (ex) {
// Defaults
return {
hideLeadingZero: 'false',
fakeDefaults: 'true',
}
}
}

function saveSettings() {
fs.writeFileSync(SETTINGS_FILE, settings, SETTINGS_TYPE);
}

// END settings nonsense


messaging.peerSocket.onmessage = (evt) => {
settings[evt.data.key] = evt.data.newValue;
//myElement.style.fill = evt.data.value;
// redo settings...i guess?
}

// Update the clock every second
clock.granularity = 'seconds';

let hrm = new HeartRateSensor();
Expand Down Expand Up @@ -47,10 +86,10 @@ const stairs_text = document.getElementById('stairs_text');
clock.ontick = (evt) => {
const now = evt.date;
const hours = util.zeroPad(
(preferences.clockDisplay === '12h')
(preferences.clockDisplay === '24h')
? now.getHours()
: now.getHours() % 12 || 12
);
, settings.hideLeadingZero === 'true' ? ' ' : '0');

const mins = util.zeroPad(now.getMinutes());

Expand All @@ -72,3 +111,4 @@ clock.ontick = (evt) => {

hrm.start();
}

4 changes: 2 additions & 2 deletions common/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Add zero in front of numbers < 10
export function zeroPad(i) {
export function zeroPad(i, spacer = '0') {
if (i < 10) {
i = "0" + i;
i = spacer + i;
}
return "" + i;
}
Expand Down
15 changes: 10 additions & 5 deletions companion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import { settingsStorage } from "settings";
import * as messaging from "messaging";

settingsStorage.onchange = function(evt) {
console.log(`${evt.key} : ${evt.newValue}`);
console.log("warning setting recvd");
console.log(JSON.stringify(evt));
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
if (evt.key === "theme") {
let data = JSON.parse(evt.newValue);
messaging.peerSocket.send(data["values"][0].value);
}
// uh
messaging.peerSocket.send(evt);


// if (evt.key === "theme") {
// let data = JSON.parse(evt.newValue);
// messaging.peerSocket.send(data["values"][0].value);
// }
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@
"name": "TimeStyle"
}
}
},
"devDependencies": {
"@fitbit/sdk": "~1.0.0"
}
}
43 changes: 43 additions & 0 deletions settings/components/SuperColorSelect.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { pebbleColors, colorNames, sneakySpacer } from '../pebbleColors';
import { getColorPreviewSVG, getThemePreviewSVG } from '../previewGenerators';

const SuperColorSelect = ({ title, settingsKey, currentSelection, currentTheme }) => {
return (
<Select
label={
<TextImageRow
label={title}
sublabel={colorNames[currentSelection]}
icon={getColorPreviewSVG(currentSelection)}
/>
}
selectViewTitle={title}
options={pebbleColors}
settingsKey={settingsKey}
renderItem={
(option) => {
const previewSVG = currentTheme ?
getThemePreviewSVG({
timeColor:
currentTheme.timeColor ? currentTheme.timeColor : option.color,
sidebarColor:
currentTheme.sidebarColor ? currentTheme.sidebarColor : option.color,
backgroundColor:
currentTheme.backgroundColor ? currentTheme.backgroundColor : option.color,
})
:
getColorPreviewSVG(option.color);

return (
<TextImageRow
label={ colorNames[option.color] }
icon={ previewSVG }
/>
);
}
}
/>
);
};

export default SuperColorSelect;
Loading

0 comments on commit 4569b78

Please sign in to comment.