@@ -45,6 +45,9 @@ var KEY_LAST_FETCH_SUCCESS = storageKeys.LAST_FETCH_SUCCESS_KEY;
4545var KEY_LAST_FETCH_ATTEMPT = storageKeys . LAST_FETCH_ATTEMPT_KEY ;
4646var KEY_GEOCODE_CACHE = storageKeys . GEOCODE_CACHE_KEY ;
4747var KEY_GEOCODE_BACKOFF = storageKeys . GEOCODE_BACKOFF_KEY ;
48+ var KEY_V1_34_0_WEEKEND_HOLIDAY_COLOR_MIGRATION = 'v1.34.0_weekend_holiday_color_migration' ;
49+ var DEFAULT_COLOR_WHITE = pebbleColors . GColorWhite ;
50+ var DEFAULT_COLOR_FOLLY = pebbleColors . GColorFolly ;
4851
4952app . fetchInProgress = false ;
5053app . pendingStartupFetch = false ;
@@ -103,6 +106,8 @@ Pebble.addEventListener('webviewclosed', function(e) {
103106// Listen for when the watchface is opened
104107Pebble . addEventListener ( 'ready' ,
105108 function ( e ) {
109+ var migratedWeekendHolidayColors ;
110+
106111 app . devConfig = getDevConfig ( ) ;
107112 maybeHandleDevStorageReset ( app . devConfig ) ;
108113 var hadExistingInstall = localStorage . getItem ( 'clay-settings' ) !== null ;
@@ -111,6 +116,7 @@ Pebble.addEventListener('ready',
111116 app . devConfig . forceShowReleaseNotificationOnBoot
112117 ) ;
113118 clayTryDefaults ( ) ;
119+ migratedWeekendHolidayColors = clayTryWeekendHolidayColorMigration ( ) ;
114120 clayTryDevConfig ( app . devConfig ) ;
115121 clayTryFixtureSettings ( activeFixture ) ;
116122 console . log ( 'PebbleKit JS ready!' ) ;
@@ -132,6 +138,9 @@ Pebble.addEventListener('ready',
132138 } ) ;
133139 return ;
134140 }
141+ if ( migratedWeekendHolidayColors ) {
142+ sendClaySettings ( markWeekendHolidayColorMigrationComplete ) ;
143+ }
135144 if ( app . pendingStartupFetch ) {
136145 app . pendingStartupFetch = false ;
137146 fetch ( app . provider , true ) ;
@@ -322,11 +331,20 @@ function maybeShowReleaseNotification(hadExistingInstall, forceVersionSpec) {
322331 */
323332function maybeHandleDevStorageReset ( devConfig ) {
324333 var shouldClear = ! ! ( devConfig && devConfig . clearPkjsStorageOnBoot ) ;
334+ var shouldResetV134WeekendHolidayColorMigration = ! ! (
335+ devConfig &&
336+ devConfig . resetV134WeekendHolidayColorMigration
337+ ) ;
325338
326339 if ( shouldClear ) {
327340 console . log ( '[dev] clearPkjsStorageOnBoot=true, clearing localStorage' ) ;
328341 localStorage . clear ( ) ;
329342 }
343+
344+ if ( shouldResetV134WeekendHolidayColorMigration ) {
345+ console . log ( '[dev] resetV134WeekendHolidayColorMigration=true, clearing migration marker' ) ;
346+ localStorage . removeItem ( KEY_V1_34_0_WEEKEND_HOLIDAY_COLOR_MIGRATION ) ;
347+ }
330348}
331349
332350/**
@@ -376,7 +394,7 @@ function sendClaySettings(onSuccess, onFailure) {
376394 "CLAY_CELSIUS" : app . settings . temperatureUnits === 'c' ,
377395 "CLAY_TIME_LEAD_ZERO" : app . settings . timeLeadingZero ,
378396 "CLAY_AXIS_12H" : app . settings . axisTimeFormat === '12h' ,
379- "CLAY_COLOR_TODAY" : app . settings . hasOwnProperty ( 'colorToday' ) ? app . settings . colorToday : 16777215 ,
397+ "CLAY_COLOR_TODAY" : app . settings . hasOwnProperty ( 'colorToday' ) ? app . settings . colorToday : DEFAULT_COLOR_WHITE ,
380398 "CLAY_START_MON" : app . settings . weekStartDay === 'mon' ,
381399 "CLAY_PREV_WEEK" : app . settings . firstWeek === 'prev' ,
382400 "CLAY_TIME_FONT" : [ 'roboto' , 'leco' , 'bitham' ] . indexOf ( app . settings . timeFont ) ,
@@ -385,10 +403,10 @@ function sendClaySettings(onSuccess, onFailure) {
385403 "CLAY_SHOW_BT_DISCONNECT" : app . settings . btIcons === "disconnected" || app . settings . btIcons === "both" ,
386404 "CLAY_VIBE" : app . settings . vibe ,
387405 "CLAY_SHOW_AM_PM" : app . settings . timeShowAmPm ,
388- "CLAY_COLOR_SUNDAY" : app . settings . hasOwnProperty ( 'colorSunday' ) ? app . settings . colorSunday : 16777215 ,
389- "CLAY_COLOR_SATURDAY" : app . settings . hasOwnProperty ( 'colorSaturday' ) ? app . settings . colorSaturday : 16777215 ,
390- "CLAY_COLOR_US_FEDERAL" : app . settings . hasOwnProperty ( 'colorUSFederal' ) ? app . settings . colorUSFederal : 16777215 ,
391- "CLAY_COLOR_TIME" : app . settings . hasOwnProperty ( 'colorTime' ) ? app . settings . colorTime : 16777215 ,
406+ "CLAY_COLOR_SUNDAY" : app . settings . hasOwnProperty ( 'colorSunday' ) ? app . settings . colorSunday : DEFAULT_COLOR_FOLLY ,
407+ "CLAY_COLOR_SATURDAY" : app . settings . hasOwnProperty ( 'colorSaturday' ) ? app . settings . colorSaturday : DEFAULT_COLOR_FOLLY ,
408+ "CLAY_COLOR_US_FEDERAL" : app . settings . hasOwnProperty ( 'colorUSFederal' ) ? app . settings . colorUSFederal : DEFAULT_COLOR_FOLLY ,
409+ "CLAY_COLOR_TIME" : app . settings . hasOwnProperty ( 'colorTime' ) ? app . settings . colorTime : DEFAULT_COLOR_WHITE ,
392410 "CLAY_DAY_NIGHT_SHADING" : app . settings . hasOwnProperty ( 'dayNightShading' ) ? app . settings . dayNightShading : true ,
393411 }
394412 Pebble . sendAppMessage ( payload , function ( ) {
@@ -484,20 +502,79 @@ function getDefaultClaySettings() {
484502 timeShowAmPm : false ,
485503 axisTimeFormat : '24h' ,
486504 timeFont : 'roboto' ,
487- colorTime : 16777215 ,
505+ colorTime : DEFAULT_COLOR_WHITE ,
488506 weekStartDay : 'sun' ,
489507 firstWeek : 'prev' ,
490508 colorToday : 0 ,
491- colorSunday : 16777215 ,
492- colorSaturday : 16777215 ,
493- colorUSFederal : 16777215 ,
509+ colorSunday : DEFAULT_COLOR_FOLLY ,
510+ colorSaturday : DEFAULT_COLOR_FOLLY ,
511+ colorUSFederal : DEFAULT_COLOR_FOLLY ,
494512 showQt : true ,
495513 vibe : false ,
496514 btIcons : 'both' ,
497515 telemetryEnabled : true
498516 } ;
499517}
500518
519+ /**
520+ * Move existing installs from the old all-white weekend/holiday defaults to the
521+ * current highlighted default while preserving any customized color set.
522+ *
523+ * @returns {boolean } True when the migrated settings should be sent to the watch.
524+ */
525+ function clayTryWeekendHolidayColorMigration ( ) {
526+ var persistClayString = localStorage . getItem ( 'clay-settings' ) ;
527+ var persistClay ;
528+
529+ if (
530+ persistClayString === null ||
531+ localStorage . getItem ( KEY_V1_34_0_WEEKEND_HOLIDAY_COLOR_MIGRATION ) !== null
532+ ) {
533+ return false ;
534+ }
535+
536+ try {
537+ persistClay = JSON . parse ( persistClayString ) ;
538+ }
539+ catch ( ex ) {
540+ console . log ( 'Malformed clay settings found, skipping weekend/holiday color migration' ) ;
541+ return false ;
542+ }
543+
544+ if (
545+ persistClay . colorSunday === DEFAULT_COLOR_WHITE &&
546+ persistClay . colorSaturday === DEFAULT_COLOR_WHITE &&
547+ persistClay . colorUSFederal === DEFAULT_COLOR_WHITE
548+ ) {
549+ persistClay . colorSunday = DEFAULT_COLOR_FOLLY ;
550+ persistClay . colorSaturday = DEFAULT_COLOR_FOLLY ;
551+ persistClay . colorUSFederal = DEFAULT_COLOR_FOLLY ;
552+ localStorage . setItem ( 'clay-settings' , JSON . stringify ( persistClay ) ) ;
553+ console . log ( 'Migrated weekend/holiday color defaults to Folly' ) ;
554+ return true ;
555+ }
556+
557+ if (
558+ persistClay . colorSunday === DEFAULT_COLOR_FOLLY &&
559+ persistClay . colorSaturday === DEFAULT_COLOR_FOLLY &&
560+ persistClay . colorUSFederal === DEFAULT_COLOR_FOLLY
561+ ) {
562+ return true ;
563+ }
564+
565+ markWeekendHolidayColorMigrationComplete ( ) ;
566+ return false ;
567+ }
568+
569+ /**
570+ * Mark the v1.34.0 weekend/holiday color migration as complete.
571+ *
572+ * @returns {void }
573+ */
574+ function markWeekendHolidayColorMigrationComplete ( ) {
575+ localStorage . setItem ( KEY_V1_34_0_WEEKEND_HOLIDAY_COLOR_MIGRATION , '1' ) ;
576+ }
577+
501578function getDevConfig ( ) {
502579 try {
503580 return require ( './dev-config.js' ) ;
@@ -518,6 +595,7 @@ function clayTryDevConfig(devConfig) {
518595 var localOnlyDevConfigKeys = {
519596 clearPkjsStorageOnBoot : true ,
520597 forceShowReleaseNotificationOnBoot : true ,
598+ resetV134WeekendHolidayColorMigration : true ,
521599 } ;
522600
523601 persistClay = getClaySettings ( ) ;
0 commit comments