Skip to content

Commit cc029e6

Browse files
authored
Improved forecast swipe gesture (#72)
Improved touch/swipe interface for daily forecast.
1 parent 8a0978b commit cc029e6

15 files changed

Lines changed: 168 additions & 99 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.1.1
2+
3+
* Improved touch/swipe interface for daily forecast.
4+
15
## 3.1.0
26

37
* Allow users to add their own alarm tones.

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aw-clock",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"license": "MIT",
55
"author": "Kerry Shetline <kerry@shetline.com>",
66
"scripts": {

sass/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sass/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aw-clock-sass",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"description": "SASS builder for aw-clock",
55
"keywords": [
66
"sass"

server/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aw-clock-server",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"license": "MIT",
55
"author": "Kerry Shetline <kerry@shetline.com>",
66
"private": true,

server/src/app.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { router as forecastRouter } from './forecast-router';
2828
import fs from 'fs';
2929
import * as http from 'http';
3030
import os from 'os';
31-
import { asLines, htmlEscape, isString, noop, push, toBoolean, toNumber } from '@tubular/util';
31+
import { asLines, htmlEscape, isString, noop, processMillis, push, toBoolean, toNumber } from '@tubular/util';
3232
import logger from 'morgan';
3333
import * as path from 'path';
3434
import * as requestIp from 'request-ip';
@@ -93,11 +93,12 @@ if (process.env.AWC_WIRED_TH_GPIO || process.env.AWC_ALT_DEV_SERVER) {
9393
}
9494

9595
// Poll for software updates
96-
const UPDATE_POLL_INTERVAL = 10800000; // 3 hours
96+
const UPDATE_POLL_INTERVAL = 7200000; // 2 hours
9797
const UPDATE_POLL_RETRY_TIME = 60_000; // 10 minutes
9898
let updatePollTimer: any;
9999
let latestVersion = process.env.AWC_FAKE_UPDATE_VERSION ?? AWC_VERSION;
100100
let latestVersionInfo = '';
101+
let lastUpdateCheck = Number.MIN_SAFE_INTEGER;
101102

102103
async function checkForUpdate(): Promise<void> {
103104
updatePollTimer = undefined;
@@ -143,6 +144,7 @@ async function checkForUpdate(): Promise<void> {
143144
console.error('%s: Update info request failed: %s', timeStamp(), e.message ?? e.toString());
144145
}
145146

147+
lastUpdateCheck = processMillis();
146148
updatePollTimer = unref(setTimeout(checkForUpdate, delay));
147149
}
148150

@@ -393,6 +395,9 @@ function getApp(): Express {
393395
theApp.get('/defaults', async (req, res) => {
394396
noCache(res);
395397

398+
if (lastUpdateCheck < processMillis() - UPDATE_POLL_RETRY_TIME)
399+
await checkForUpdate();
400+
396401
const ip = requestIp.getClientIp(req);
397402
const defaults: AwcDefaults = {
398403
allowAdmin: allowAdmin && /^(::1|::ffff:127\.0\.0\.1|127\.0\.0\.1|0\.0\.0\.0|localhost)$/i.test(ip),

server/src/gps.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class Gps extends TimePoller {
2929
private gpsData: GpsData = { fix: 0, signalQuality: 0 };
3030
private googleAccessDenied = false;
3131
private googleKey: string;
32+
private gpsHighDelay = false;
3233
private gpspipe: ChildProcess;
3334
private lastGpsInfo = 0;
3435
private leapSecond = 0;
@@ -114,7 +115,7 @@ export class Gps extends TimePoller {
114115
if ((this.gpsData.fix || 0) === 0)
115116
this.gpsData.signalQuality = 0;
116117
else {
117-
this.gpsData.signalQuality = (this.gpsData.fix === 1 ? 75 : 100);
118+
this.gpsData.signalQuality = (this.gpsData.fix === 1 ? 75 : 100) * (this.gpsHighDelay ? 0.667 : 1);
118119

119120
if (!this.gpsData.pps)
120121
this.gpsData.signalQuality /= 2;
@@ -171,23 +172,22 @@ export class Gps extends TimePoller {
171172

172173
private async checkSystemTime(): Promise<void> {
173174
const ntpInfo = asLines(await monitorProcess(spawn('ntpq', ['-p']), null, ErrorMode.NO_ERRORS));
174-
let gpsFound = false;
175-
let ntpFallback = false;
175+
176+
this.systemTimeIsGps = false;
177+
this.gpsData.ntpFallback = false;
176178

177179
for (const line of ntpInfo) {
178180
const $ = /^\*SHM\b.+\.PPS\.\s+0\s+l\s+.+?\s([-+]?[.\d]+)\s+[.\d]+\s*$/.exec(line);
179181

180-
if ($ && abs(toNumber($[1])) <= 1) {
181-
gpsFound = true;
182+
if ($) {
183+
this.systemTimeIsGps = true;
184+
this.gpsHighDelay = (abs(toNumber($[1])) > 1);
182185
break;
183186
}
184187
else if (line.startsWith('*'))
185-
ntpFallback = true;
188+
this.gpsData.ntpFallback = true;
186189
}
187190

188-
this.systemTimeIsGps = gpsFound;
189-
this.gpsData.ntpFallback = ntpFallback;
190-
191191
const cd = await this.taiUtc.getCurrentDelta();
192192

193193
if (cd.pendingLeapDate) {

src/awc-util.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import $ from 'jquery';
22
import { DateTime, Timezone } from '@tubular/time';
33
import { cos_deg, floor, mod, Point, sin_deg } from '@tubular/math';
44
import {
5-
asLines, htmlEscape, isEdge, isFunction, isSafari, isString, last, padLeft, parseColor,
5+
asLines, htmlEscape, isEdge, isFunction, isObject, isSafari, isString, last, padLeft, parseColor,
66
processMillis, toNumber
77
} from '@tubular/util';
88
import compareVersions, { CompareOperator } from 'compare-versions';
@@ -147,21 +147,34 @@ export function domAlert(message: string, callback?: () => void): void {
147147

148148
type OkCallback = (isOk: boolean) => void;
149149

150+
interface ConfirmOptions {
151+
cancelText?: string;
152+
okText?: string;
153+
optionalHtml?: string;
154+
}
155+
150156
export function domConfirm(message: string, callback: OkCallback): void;
151-
export function domConfirm(message: string, optionsHtml: string, callback: OkCallback): void;
152-
export function domConfirm(message: string, callbackOrOptions: OkCallback | string, callback?: OkCallback): void {
157+
export function domConfirm(message: string, optionsHtml: string | ConfirmOptions, callback: OkCallback): void;
158+
export function domConfirm(message: string, callbackOrOptions: OkCallback | string | ConfirmOptions, callback?: OkCallback): void {
159+
let cancelText = '';
160+
let okText = '';
153161
let optionalHtml: string;
154162

155-
if (isString(callbackOrOptions))
156-
optionalHtml = callbackOrOptions;
157-
else if (!isFunction(callback))
163+
if (isFunction(callbackOrOptions))
158164
callback = callbackOrOptions;
165+
else if (isObject(callbackOrOptions))
166+
({ cancelText, okText, optionalHtml } = callbackOrOptions);
167+
else if (isString(callbackOrOptions))
168+
optionalHtml = callbackOrOptions;
159169

160170
const confirmDialog = $('#confirm-dialog');
161171
const confirmOk = $('#confirm-ok');
162172
const confirmCancel = $('#confirm-cancel');
163173
const confirmOptions = $('#confirm-options');
164174

175+
confirmCancel.text(cancelText || 'Cancel');
176+
confirmOk.text(okText || 'OK');
177+
165178
if (optionalHtml) {
166179
confirmOptions.css('display', 'block');
167180
confirmOptions.html(optionalHtml);

0 commit comments

Comments
 (0)