Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/build-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
cache: true

- name: Install Pebble SDK
run: pebble sdk install latest
run: scripts/ensure-pebble-sdk.sh

- name: Build dev .pbw
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Install Pebble SDK
if: ${{ steps.release.outputs.release_created }}
run: pebble sdk install latest
run: scripts/ensure-pebble-sdk.sh

- name: Build .pbw
if: ${{ steps.release.outputs.release_created }}
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mise build
mise build release
```

This builds the project with the Pebble SDK provisioned by mise. The `.pbw` output can be found in the `build` directory.
This builds the project with the Pebble SDK version pinned in `pebble-sdk-version` and provisioned by the repo scripts. The `.pbw` output can be found in the `build` directory.

## Supabase (telemetry)

Expand Down
36 changes: 36 additions & 0 deletions mise.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,38 @@ url = "https://github.com/supabase/cli/releases/download/v2.78.1/supabase_darwin
checksum = "sha256:37019238428370db923341b0ae108a227e4c1b5f6dbea30e2687059a64cd7630"
url = "https://github.com/supabase/cli/releases/download/v2.78.1/supabase_windows_amd64.tar.gz"

[[tools."aqua:supabase/cli"]]
version = "2.84.2"
backend = "aqua:supabase/cli"

[tools."aqua:supabase/cli"."platforms.linux-arm64"]
checksum = "sha256:c660f5c9f62489f7c777cbd10a71b7af0a30bced1230783ab56713bceeaa4313"
url = "https://github.com/supabase/cli/releases/download/v2.84.2/supabase_linux_arm64.tar.gz"

[tools."aqua:supabase/cli"."platforms.linux-arm64-musl"]
checksum = "sha256:c660f5c9f62489f7c777cbd10a71b7af0a30bced1230783ab56713bceeaa4313"
url = "https://github.com/supabase/cli/releases/download/v2.84.2/supabase_linux_arm64.tar.gz"

[tools."aqua:supabase/cli"."platforms.linux-x64"]
checksum = "sha256:620a5f6ea7b60f9b4fe112a5d72464ea0e53d04022035641674a2e6d121e0eb5"
url = "https://github.com/supabase/cli/releases/download/v2.84.2/supabase_linux_amd64.tar.gz"

[tools."aqua:supabase/cli"."platforms.linux-x64-musl"]
checksum = "sha256:620a5f6ea7b60f9b4fe112a5d72464ea0e53d04022035641674a2e6d121e0eb5"
url = "https://github.com/supabase/cli/releases/download/v2.84.2/supabase_linux_amd64.tar.gz"

[tools."aqua:supabase/cli"."platforms.macos-arm64"]
checksum = "sha256:25e5cbbf4d1b79c265d40c9875b3457570d4600920f93161186f07e5ec1f75b8"
url = "https://github.com/supabase/cli/releases/download/v2.84.2/supabase_darwin_arm64.tar.gz"

[tools."aqua:supabase/cli"."platforms.macos-x64"]
checksum = "sha256:6c4d42cc6d0e15d83f8564ec455a03586ce76fdd72fa3c4d1b7ac4d40472f563"
url = "https://github.com/supabase/cli/releases/download/v2.84.2/supabase_darwin_amd64.tar.gz"

[tools."aqua:supabase/cli"."platforms.windows-x64"]
checksum = "sha256:617b37d756d3a6457ac63f60372ce85a816112350f97ebda711fddb4002b346c"
url = "https://github.com/supabase/cli/releases/download/v2.84.2/supabase_windows_amd64.tar.gz"

[[tools.deno]]
version = "2.1.4"
backend = "core:deno"
Expand Down Expand Up @@ -67,3 +99,7 @@ url = "https://dl.deno.land/release/v2.1.4/deno-x86_64-pc-windows-msvc.zip"
[[tools."pipx:pebble-tool"]]
version = "5.0.28"
backend = "pipx:pebble-tool"

[[tools."pipx:pebble-tool"]]
version = "5.0.31"
backend = "pipx:pebble-tool"
4 changes: 2 additions & 2 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ lockfile = true
# https://developer.rebble.io/sdk/
# https://github.com/coredevices/pebble-tool
# https://mise.jdx.dev/dev-tools/backends/pipx.html
"pipx:pebble-tool" = "5.0.28"
"pipx:pebble-tool" = "5.0.31"

# https://deno.com/
deno = "2.1.4"

# https://github.com/supabase/cli
# https://mise.jdx.dev/dev-tools/backends/aqua.html
"aqua:supabase/cli" = "2.78.1"
"aqua:supabase/cli" = "2.84.2"

[env]
_.file = ".env"
Expand Down
1 change: 1 addition & 0 deletions pebble-sdk-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.9.148
1 change: 1 addition & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if [[ "${1:-}" == "--" ]]; then
shift
fi

scripts/ensure-pebble-sdk.sh
mise run prepare-package -- "$profile"
pebble build "$@"

Expand Down
26 changes: 26 additions & 0 deletions scripts/ensure-pebble-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -euo pipefail

# Activate the Pebble SDK version pinned in the repo before any build or install.

repo_root="$(cd "$(dirname "$0")/.." && pwd)"
sdk_version_file="$repo_root/pebble-sdk-version"

if [[ ! -f "$sdk_version_file" ]]; then
echo "Missing Pebble SDK version file: $sdk_version_file" >&2
exit 1
fi

sdk_version="$(<"$sdk_version_file")"
sdk_version="${sdk_version//$'\r'/}"

if [[ -z "$sdk_version" ]]; then
echo "Empty Pebble SDK version file: $sdk_version_file" >&2
exit 1
fi

if ! pebble sdk activate "$sdk_version"; then
pebble sdk install "$sdk_version"
pebble sdk activate "$sdk_version"
fi
2 changes: 1 addition & 1 deletion src/pkjs/clay/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ module.exports = [
"type": "toggle",
"label": "Force weather fetch",
"messageKey": "fetch",
"description": "Last successful fetch:<br><span id='lastFetchSpan'>Never :(</span>"
"description": "Last successful fetch:<br><span id='lastFetchSpan'>Never :(</span><span id='lastAttemptBlock'></span>"
},
{
"type": "input",
Expand Down
83 changes: 70 additions & 13 deletions src/pkjs/clay/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,54 @@ module.exports = function (minified) {
clayConfig = this;
var $ = minified.$;

/**
* Parse stored JSON safely.
*
* @param {string|null} value Raw JSON string.
* @returns {Object|null} Parsed object or null.
*/
function parseStoredJson(value) {
if (value === null) {
return null;
}

try {
return JSON.parse(value);
}
catch (ex) {
return null;
}
}

clayConfig.on(clayConfig.EVENTS.AFTER_BUILD, function() {
var clayFetch = clayConfig.getItemByMessageKey('fetch');
var clayFetch;
var clayOwmApiKey;
var clayProvider;
var clayLocation;
var initProvider;
var initOwmApiKey;
var initLocation;
var lastFetchSuccessString;
var lastFetchSuccess;
var date;
var lastFetchSuccessTime;
var lastFetchAttemptString;
var lastFetchAttempt;
var attemptDate;
var attemptTime;
var attemptText;
var shouldShowLastAttempt;

clayFetch = clayConfig.getItemByMessageKey('fetch');
clayFetch.set(false);

// Save initial states to detect changes to provider
var clayOwmApiKey = clayConfig.getItemByMessageKey('owmApiKey');
var clayProvider = clayConfig.getItemByMessageKey('provider');
var clayLocation = clayConfig.getItemByMessageKey('location');
var initProvider = clayProvider.get();
var initOwmApiKey = clayOwmApiKey.get();
var initLocation = clayLocation.get();
clayOwmApiKey = clayConfig.getItemByMessageKey('owmApiKey');
clayProvider = clayConfig.getItemByMessageKey('provider');
clayLocation = clayConfig.getItemByMessageKey('location');
initProvider = clayProvider.get();
initOwmApiKey = clayOwmApiKey.get();
initLocation = clayLocation.get();

// Configure default provide section layout
if (initProvider !== 'openweathermap') {
Expand All @@ -31,25 +68,45 @@ module.exports = function (minified) {
})

// Show last weather fetch status
var lastFetchSuccessString = clayConfig.meta.userData.lastFetchSuccess;
if (lastFetchSuccessString !== null) {
var lastFetchSuccess = JSON.parse(lastFetchSuccessString);
var date = new Date(lastFetchSuccess.time);
lastFetchSuccessString = clayConfig.meta.userData.lastFetchSuccess;
lastFetchSuccessTime = null;
lastFetchSuccess = parseStoredJson(lastFetchSuccessString);
if (lastFetchSuccess !== null) {
date = new Date(lastFetchSuccess.time);
lastFetchSuccessTime = date.getTime();
$('#lastFetchSpan').ht(date.toLocaleDateString() + ' ' + date.toLocaleTimeString() + ' with ' + lastFetchSuccess.name);
}

lastFetchAttemptString = clayConfig.meta.userData.lastFetchAttempt;
lastFetchAttempt = parseStoredJson(lastFetchAttemptString);
if (lastFetchAttempt !== null) {
if (lastFetchAttempt.error) {
attemptDate = new Date(lastFetchAttempt.time);
attemptTime = attemptDate.getTime();
shouldShowLastAttempt = !Boolean(lastFetchSuccessTime) || attemptTime > lastFetchSuccessTime;

if (shouldShowLastAttempt) {
attemptText = '<br>Last failed attempt:<br>';
attemptText += attemptDate.toLocaleDateString() + ' ' + attemptDate.toLocaleTimeString() + ' with ' + lastFetchAttempt.name;
attemptText += '<br>Error: ' + lastFetchAttempt.error.stage + ': ' + lastFetchAttempt.error.code;
$('#lastAttemptBlock').ht(attemptText);
}
}
}

// Override submit handler to force re-fetch if provider config changed
$('#main-form').on('submit', function() {
var returnTo;
if (clayProvider.get() !== initProvider
|| clayOwmApiKey.get() !== initOwmApiKey
|| clayLocation.get() !== initLocation) {
clayFetch.set(true);
}

// Copied from original handler ($.off requires non-anonymous handler)
var returnTo = window.returnTo || 'pebblejs://close#';
returnTo = window.returnTo || 'pebblejs://close#';
location.href = returnTo +
encodeURIComponent(JSON.stringify(clayConfig.serialize()));
})
});
};
};
32 changes: 26 additions & 6 deletions src/pkjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var createTelemetryClient = require('./telemetry.js');
var Clay = require('./clay/_source.js');
var clayConfig = require('./clay/config.js');
var customClay = require('./clay/inject.js');
var storageKeys = require('./storage-keys.js');
var pkg = require('../../package.json');

/**
Expand All @@ -26,11 +27,16 @@ var releaseNotificationsManifest = loadReleaseNotificationsManifest();
var clay = new Clay(clayConfig, customClay, { autoHandleEvents: false });
var app = {}; // Namespace for global app variables
var KEY_MAX_NOTIFIED_VERSION = 'max_notified_version';
var KEY_FETCH_ATTEMPT = 'weather_fetch_attempt';
var KEY_FETCH_ATTEMPT = storageKeys.FETCH_ATTEMPT_KEY;
var KEY_LAST_FETCH_SUCCESS = storageKeys.LAST_FETCH_SUCCESS_KEY;
var KEY_LAST_FETCH_ATTEMPT = storageKeys.LAST_FETCH_ATTEMPT_KEY;
var KEY_GEOCODE_CACHE = storageKeys.GEOCODE_CACHE_KEY;
var KEY_GEOCODE_BACKOFF = storageKeys.GEOCODE_BACKOFF_KEY;

Pebble.addEventListener('showConfiguration', function(e) {
// Set the userData here rather than in the Clay() constructor so it's actually up to date
clay.meta.userData.lastFetchSuccess = localStorage.getItem('lastFetchSuccess');
clay.meta.userData.lastFetchSuccess = localStorage.getItem(KEY_LAST_FETCH_SUCCESS);
clay.meta.userData.lastFetchAttempt = localStorage.getItem(KEY_LAST_FETCH_ATTEMPT);
Pebble.openURL(clay.generateUrl());
console.log('Showing clay: ' + JSON.stringify(getClaySettings()));
});
Expand Down Expand Up @@ -340,8 +346,15 @@ function sendClaySettings() {
}

function refreshProvider() {
var oldLocation = app.provider ? app.provider.location : null;
setProvider(app.settings.provider);
app.provider.location = app.settings.location === '' ? null : app.settings.location
app.provider.location = app.settings.location === '' ? null : app.settings.location;

// Clear geocode cache when location changes so a fresh lookup always happens
if (oldLocation !== app.provider.location) {
localStorage.removeItem(KEY_GEOCODE_CACHE);
localStorage.removeItem(KEY_GEOCODE_BACKOFF);
}
}

function setProvider(providerId) {
Expand Down Expand Up @@ -481,11 +494,11 @@ function fetch(provider, force) {
id: provider.id,
name: provider.name
}
localStorage.setItem('lastFetchAttempt', JSON.stringify(fetchStatus));
localStorage.setItem(KEY_LAST_FETCH_ATTEMPT, JSON.stringify(fetchStatus));
provider.fetch(
function() {
// Sucess, update recent fetch time
localStorage.setItem('lastFetchSuccess', JSON.stringify(fetchStatus));
localStorage.setItem(KEY_LAST_FETCH_SUCCESS, JSON.stringify(fetchStatus));
resetFetchAttemptCounter();
console.log('Successfully fetched weather!');
maybeTrackWeatherFetch({
Expand All @@ -504,6 +517,13 @@ function fetch(provider, force) {
function(failure) {
// Failure
console.log('[!] Provider failed to update weather: ' + JSON.stringify(failure));
var attemptStatus = {
time: fetchStatus.time,
id: fetchStatus.id,
name: fetchStatus.name,
error: failure
};
localStorage.setItem(KEY_LAST_FETCH_ATTEMPT, JSON.stringify(attemptStatus));
maybeTrackWeatherFetch({
provider: provider.id,
success: false,
Expand Down Expand Up @@ -552,7 +572,7 @@ function roundDownMinutes(date, minuteMod) {

function needRefresh() {
// If the weather has never been fetched
var lastFetchSuccessString = localStorage.getItem('lastFetchSuccess');
var lastFetchSuccessString = localStorage.getItem(KEY_LAST_FETCH_SUCCESS);
if (lastFetchSuccessString === null) {
return true;
}
Expand Down
7 changes: 7 additions & 0 deletions src/pkjs/storage-keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
FETCH_ATTEMPT_KEY: 'weather_fetch_attempt',
LAST_FETCH_SUCCESS_KEY: 'lastFetchSuccess',
LAST_FETCH_ATTEMPT_KEY: 'lastFetchAttempt',
GEOCODE_CACHE_KEY: 'geocodeCache',
GEOCODE_BACKOFF_KEY: 'geocodeBackoff'
};
Loading