Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ You can create a file `src/pkjs/dev-config.js` to set values for Clay keys (for
```javascript
var owmApiKey = 'abc123';
module.exports.owmApiKey = owmApiKey;
module.exports.location = 'New York, NY';
module.exports.forceFetchOnBoot = true;
```

When `forceFetchOnBoot` is `true`, PKJS clears the saved `lastFetchSuccess` value on startup so weather is fetched immediately instead of waiting for the normal refresh window.
9 changes: 9 additions & 0 deletions src/pkjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,19 @@ function clayTryDevConfig() {
var persistClay = getClaySettings();
for (var prop in devConfig) {
if (Object.prototype.hasOwnProperty.call(devConfig, prop)) {
if (prop === 'forceFetchOnBoot') {
continue;
}
persistClay[prop] = devConfig[prop];
console.log('Found dev setting: ' + prop + '=' + devConfig[prop]);
}
}

if (devConfig.forceFetchOnBoot === true) {
console.log('Found dev setting: forceFetchOnBoot=true (clearing lastFetchSuccess)');
localStorage.removeItem('lastFetchSuccess');
}

localStorage.setItem('clay-settings', JSON.stringify(persistClay));
}
catch (ex) {
Expand Down
20 changes: 13 additions & 7 deletions src/pkjs/weather/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,31 @@ WeatherProvider.prototype.withCityName = function(lat, lon, callback) {
var url = 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?f=json&langCode=EN&location='
+ lon + ',' + lat;
request(url, 'GET', function (response) {
var address = JSON.parse(response).address;
var body = JSON.parse(response);
if (!body.address) {
console.log('[!] Reverse geocoding response had no address object');
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the reverse-geocode response has no address, this function returns without invoking callback, which will stall the whole fetch chain (fetch() waits on withCityName). Consider still calling callback with a safe fallback (e.g., empty/"Unknown") and/or propagating failure so the fetch can complete deterministically.

Suggested change
console.log('[!] Reverse geocoding response had no address object');
console.log('[!] Reverse geocoding response had no address object');
callback('Unknown');

Copilot uses AI. Check for mistakes.
return;
}
var address = body.address;
var name = address.District ? address.District : address.City;
console.log('Running callback with city: ' + name);
callback(name);
});
}

// https://github.com/mattrossman/forecaswatch2/issues/59#issue-1317582743
const r_lat_long = new RegExp(/([-+]?[\d\.]*),([-+]?[\d\.]*)/gm);
const r_lat_long = /^\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)\s*$/;

WeatherProvider.prototype.withGeocodeCoordinates = function(callback) {
// callback(lattitude, longtitude)
var locationiq_key = 'pk.5a61972cde94491774bcfaa0705d5a0d';
var locationQuery = this.location;
var url = 'https://us1.locationiq.com/v1/search.php?key=' + locationiq_key
+ '&q=' + this.location
+ '&q=' + locationQuery
+ '&format=json';
Comment on lines 88 to 90
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locationQuery is interpolated into the LocationIQ URL without URL-encoding. Queries like the README example ("New York, NY") contain spaces/comma and should be passed through encodeURIComponent to avoid malformed requests or unexpected server parsing.

Copilot uses AI. Check for mistakes.
var m = r_lat_long.exec(this.location);
var m = locationQuery ? locationQuery.match(r_lat_long) : null;

console.log('WeatherProvider.prototype.withGeocodeCoordinates lets regex, this.location: ' + JSON.stringify(this.location));
console.log('WeatherProvider.prototype.withGeocodeCoordinates lets regex, this.location: ' + JSON.stringify(locationQuery));
if (m != null) {
var latitude = m[1];
var longitude = m[2];
Expand All @@ -101,7 +107,7 @@ WeatherProvider.prototype.withGeocodeCoordinates = function(callback) {
}
else {
var closest = locations[0];
console.log('Query ' + this.location + ' geocoded to ' + closest.lat + ', ' + closest.lon);
console.log('Query "' + locationQuery + '" geocoded to ' + closest.lat + ', ' + closest.lon);
JSON.stringify('closest.lat ' + JSON.stringify(closest.lat));
JSON.stringify('closest ' + JSON.stringify(closest));
callback(closest.lat, closest.lon);
Expand Down Expand Up @@ -232,4 +238,4 @@ WeatherProvider.prototype.getPayload = function() {
return payload;
}

module.exports = WeatherProvider;
module.exports = WeatherProvider;