DnDToggle

Posted on
  • So, I tried to make an app that toggles the Quiet Mode of the watch. So when opening the app via the launcher, it shall query the quiet status and set the opposite (later that will be configurable). It works quite good. When starting, it switches from "quiet mode off" (i.e. "noisy") to "silent" and after starting it again, it switches back.

    BUT:
    Having it started once, it will set the watch to silent - regardless if it tries to bring back the "quiet mode off" state. In this case even the settings app shows "quiet mode off", but the watch does not do notifications anymore. The only solution to this is opening the settings app and set "quiet mode off" again - even if it already shows "quiet mode off".
    Any ideas what I'm doing wrong?

    Full code:

    
    const modeNames = [/*LANG*/"Noisy", /*LANG*/"Alarms", /*LANG*/"Silent"];
    let bSettings = require('Storage').readJSON('setting.jso­n',true)||{};
    let current = 0|bSettings.quiet;
    //0 off
    //1 alarms
    //2 silent
    
    console.log("old: " + current);
    
    switch (current) {
    	case 0:
    		bSettings.quiet = "2";
    		Bangle.buzz();
    		setTimeout('Bangle.buzz();',500);
    		break;
    	case 1:
    		bSettings.quiet = "0";  
    		Bangle.buzz();
    		break;
    	case 2:
    		bSettings.quiet = "0";
    		Bangle.buzz();
    		break;
    	default:
    		bSettings.quiet = "0";
    		Bangle.buzz(); 
    }
    	
    console.log("new: " + bSettings.quiet);
    
    E.showMessage(modeNames[current] + " -> " + modeNames[bSettings.quiet]);
    setTimeout('exitApp();', 2000);
    
    
    function exitApp(){
    
    require("Storage").writeJSON("setting.js­on", bSettings);
    // reload clocks with new theme, otherwise just wait for user to switch apps
    if (Bangle.CLOCK) load(global.__FILE__);
    
    load()
     
    }
    
  • You are setting it to the "0" character, instead of the number zero.
    Code like yours which uses the 0| trick will handle it ok, but places that just do if (!bSettings.quiet) /* show notification */ will break, because !"<some text, even 0>" is always false.

  • Same result when I set the number instead of the character.

  • Weird, maybe comparing your settings.json before and after running the app might provide a clue?

  • Thanks, it eventually worked :)
    PR pending

  • Now, I'm getting a little frustrated with my icon
    https://github.com/espruino/BangleApps/p­ull/2125/files#diff-f96a53ce45c9b83f1375­37c39aefcc3ace0cb01b4e368728670c6682bb15­5049
    It won't display correctly in light AND dark mode when I convert it to the img string. I already played around with different transparency settings without success. Any ideas?

  • Try making it white-on-transparent

  • Doesn't work. This shows a blank icon with both themes.

  • Yay, thanks everyone!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

DnDToggle

Posted by Avatar for Hank @Hank

Actions