将配置页面设置为已保存在Pebble 3.0 SDK中的特定默认值

setting the configuration page to specific defaults already saved in the Pebble 3.0 SDK

本文关键字:SDK 默认值 Pebble 页面设置 配置 存在 保存      更新时间:2023-09-26

我试图让我的表盘的配置页面默认为用户之前已经保存在配置页面中的内容。目前,我有一个表盘,可以通过设置配置网页和pebble- java -app.js从列表中选择15种颜色。用户提交他们想要的颜色,然后表盘改变颜色,当用户返回配置网页时,网站上有颜色列表,就像他们第一次访问该网页一样。我想让网页以他们之前选择的颜色开始。

如有任何帮助或建议,我将不胜感激。我所有的源代码都可以在https://github.com/palian/BlueFuturistic

您可以使用localstorage

function getConfigData() {
    var backgroundColorPicker = document.getElementById('background_color_picker');
    var highContrastCheckbox = document.getElementById('high_contrast_checkbox');
    var options = {
      'background_color': backgroundColorPicker.value,
      'high_contrast': highContrastCheckbox.checked
    };
    // Save for next launch
    localStorage['background_color'] = options['background_color'];
    localStorage['high_contrast'] = options['high_contrast'];
    console.log('Got options: ' + JSON.stringify(options));
    return options;
  }

在加载配置页面后使用自调用的JavaScript函数来设置GUI状态:

(function() {
    var backgroundColorPicker = document.getElementById('background_color_picker');
    var highContrastCheckbox = document.getElementById('high_contrast_checkbox');
    // Load any previously saved configuration, if available
    if(localStorage['high_contrast']) {
      highContrastCheckbox.checked = JSON.parse(localStorage['high_contrast']);
      backgroundColorPicker.value = localStorage['background_color'];
    }
  })();

(示例来自https://github.com/pebble-examples/slate-config-example)