npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-fitbit-settings

v3.1.0

Published

Module to simplify management of settings inside Fitbit OS applications

Downloads

12

Readme

Simple Fitbit Settings

npm

Introduction

The goal of this module is to simplify management of settings inside Fitbit OS applications. It implements communication of settings from the companion to the device application, and the initialization of the companion User Interface (UI).

It could be used with typescript or JavaScript.

Features

This module includes many features that will make you settings easy to use:

  • Include scripts for the companion app and the device app.
  • Type definitions for TypScript or JavaScript (with comments to visualize the documentation when you are coding).
  • Manage your settings and default values from one place (it set the UI of the companion app with default states as expected).
  • Manage your own setting class (you don't have to set and update values).

How does it work?

The cornerstone of this is your own setting class. In the common folder, you could have a class like this (each property is the key used in your settings UI):

export class Settings {
  public showSomething: boolean = true;
  public colorBackground: string = "black";
  public colorForeground: string = "white";
}

From both side (companion app and device app), you will ignite the module with this an instance of this class:

  • The companion app will set the UI in the state defined by the class (if the user had already set settings, UI will respect user settings).
  • The device app will be set with the default settings (if the user had already set settings, this module will load those from a local file). When the user change a setting, this one is sent to the device app via sockets. Only the key and the value of the settings are sent over sockets (a property type is added to the message to allow the device app to filter message and to avoid conflict with other communications). From the device app, your own method is called with an instance of your own settings class (only the changed property is defined). At the launch of your app, this method is called. All properties defined by default or changed by the user are defined.

The way to send settings form companion to device app and to store settings is inspired by the FitBit SDK sample (sdk-moment).

Installation

1. Install the module

You could use a any package manager to install this module. it was tested with npm and pnpm.

npm install simple-fitbit-settings --save-dev

2. Create your settings class

Add a file to define your settings class (example settings.ts) inside the companion folder. Exemple:

import * as commonSettings from "simple-fitbit-settings/common";
export class Settings {
  // Key used with a Toggle control
  public showSomething: boolean = true;
  // Keys used with ColorSelect controls
  public colorBackground: string = "black";
  public colorForeground: string = "white";
  // Key used with a Select control
  public valueFromSelectControl: commonSettings.Selection = { selected: [0], values: [ { name: "Name to show", value: "Value" } ] };
}

Note:

  • Each property is the key used in your settings UI.
  • Your class should have one property (the quantity of properties is not limited).
  • Values defined here will define the default values of the applications.

3. Initilize the device app

Inside the app folder the index.ts file have to :

  • Import the setting module.
  • Import the settings.ts file from the common folder.
  • Define and instantiate a _settings variable to know the settings state from the device app side (it could have on other name).
  • Initialize the settings module with the _settings variable and a callback (to react when settings changes or at the application load).

Exemple:

// Import the settigns module
import * as appSettings from "simple-fitbit-settings/app";
// Import settings class from common folder
import { Settings } from "../common/settings";
// Current settings
const _settings = new Settings();
appSettings.initialize(
  // Default settings
  _settings,
  // callback when settings changed
  (newSettings: Settings) => {
      // Test if colorBackground changed
      if (newSettings.colorBackground !== undefined) {
          // Set color ...
          // newSettings.colorBackground contain the color to use
    }
    // ... more code to test all settings ..
  });

Note : initialize is a generic method. It allows this module to preserve your own type for settings. It will make your work easier with Visauls Studio Code and Typescript.

Node : only known settings (those defined in Settings) will be delivered to the device.

4. Initilize the companion app

Inside the companion folder the index.ts file have to :

  • Import the setting module.
  • Import the settings.ts file from the common folder.
  • Initialize the setting module with an instance of your class settings (it will be used to define default values and set UI state at first load).

Exemple:

import * as companionSettings from "simple-fitbit-settings/companion";
import { Settings } from "../common/settings";
companionSettings.initialize(new Settings());

Contribute or report issues

You can report any issue via GitHub, if you found one, please report it! This code was open to be shared and improved. If you have an idea, tell it or send a pull request.

Keep in mind that this module is built for small devices. It does not have the goal to be a Swiss knife with hundreds of functions. It is why it is simple as possible.

Compilation

This module was built with TypeScript. It uses Typescript to generate JavaScript files that are imported by the Fitbit SDK.

It includes the following npm scripts to:

  • build (generate JavaScript files, delclarations, and copy all requested files to the ./distribution directory).
  • clean (remove generated files from the ./distribution directory).