Coder Social home page Coder Social logo

Comments (10)

dnmgns avatar dnmgns commented on August 26, 2024 1

What about waiting for the ready event? Like suggested here: https://developer.pebble.com/blog/2013/12/20/Pebble-Javascript-Tips-and-Tricks/
I guessing that an addEventListener("ready") added to pebblejs/src/js/platform/platform.js would solve this, right?

from pebblejs.

matopeto avatar matopeto commented on August 26, 2024

Please share your code, maybe you run/copy it from old sample.

from pebblejs.

edouardkleinhans avatar edouardkleinhans commented on August 26, 2024

var UI = require('ui');
var Settings = require('settings');
var ajax = require('ajax');
var Vibe = require('ui/vibe');
var menuSettings;
var sectionsMenu = [];
var itemsMenu = [];
var jebbleApiUrl = "plugins/jebble/core/api/jebble_api.php";
var jeeApiUrl = "core/api/jeeApi.php";

Settings.option('jeedomBaseUrl', 'https://dom.kleinhans.info/jeedom/');
Settings.option('jeedomApiKey', 'p5ecbuny626yhig1wjjl');
Settings.option('reset', 'false');

Settings.data('menu',
   JSON.stringify([{"id":"19","name":"Confort","group":"Chauffage"},{"id":"20","name":"Eco","group":"Chauffage"},{"id":"21","name":"Off","group":"Chauffage"},{"id":"12","name":"Allumer Salon","group":"Lumi\u00e8res"},{"id":"13","name":"Eteindre Salon","group":"Lumi\u00e8res"},{"id":"18","name":"Fermer Volet","group":"Volets"},{"id":"17","name":"Ouvrir Volet","group":"Volets"}])
);

var cardError = new UI.Card({
title: "Erreur",
body: "Une erreur est survenue"
});

var cardResult = new UI.Card({});

var cardWait = new UI.Card({
title: "",
body: "Chargement..."
});

// Create Menu Card
var menu = new UI.Menu({
sections: []
});

var sousMenu = new UI.Menu({
sections: []
});

function httpCall(url, params, method, sync, returnDatas) {
var jeedomUrl = Settings.option("jeedomBaseUrl").replace(//?$/, '/');
var result = 'Fait';
var _async = sync ? false : true;
var _method = method ? method : 'GET';
console.log("url: " + jeedomUrl + url + "?apikey=" + Settings.option("jeedomApiKey") + (params ? params : ""));
ajax(
{
url: jeedomUrl + url + "?apikey=" + Settings.option("jeedomApiKey") + (params ? params : ""),
type: 'json',
method: _method,
async: _async
},
function(data, status, request) {
//console.log('return: ' + data);
if(returnDatas) {
result = data;
}
},
function(error, status, request) {
console.log('The ajax request failed: ' + error);
result = error;
}
);
return result;
}

function loadMenuSettings() {
console.log('load menu settings');
// var response = httpCall(jebbleApiUrl, "", "GET", true, true);
// Persist
// Settings.data('menu', JSON.stringify(response));
Settings.option("reset", false);
}

function constructMenu() {
menuSettings = Settings.data('menu');
if(menuSettings) {
// console.log(menuSettings);
var elements = JSON.parse(menuSettings);
for (var e in elements){
var currentGroup = elements[e].group ? elements[e].group : "Aucun";
if(!itemsMenu[currentGroup]){
itemsMenu[currentGroup] = [];
}
// console.log("e: " + e + " Name: " + elements[e].name + " Element Id: " + elements[e].id);
itemsMenu[currentGroup].push({title: elements[e].name, command: elements[e].id});
}

for (var s_itemsMenu in itemsMenu){
//  console.log("s_itemsMenu: " + s_itemsMenu);
  sectionsMenu.push({title: s_itemsMenu});
}
menu.section(0, {title: 'Jebble', items: sectionsMenu}); //Set Title for menu
menu.show();
cardWait.hide();
} else {
cardError.show();
cardWait.hide();

}
}

cardWait.show();

Settings.config(
{ url:'https://dl.dropboxusercontent.com/u/13087853/configuration_jebble.html?' + encodeURIComponent(JSON.stringify(Settings.option()))},
function(e) {
console.log('opened config');
},
function(e) {
if(e.options != "CANCELLED" && e.response.charAt(0) == "{" && e.response.slice(-1) == "}" && e.response.length > 5) {
// console.log(e.response);
// console.log('Recieved settings!');
Settings.option(JSON.parse(decodeURIComponent(e.response)));
loadMenuSettings();
constructMenu();
Vibe.vibrate('short');
} else {
console.log("cancelled");
}
}
);

if(!Settings.data('menu') || Settings.option("reset")){
loadMenuSettings();
}/* else {
console.log('construct menu');
}*/

constructMenu();

menu.on('select', function (event) {
// console.log("event: " + event.item.title);
sousMenu.section(0, {title: event.item.title, items: itemsMenu[event.item.title]});
sousMenu.show();
});

sousMenu.on('select', function (event) {
var result = httpCall(jeeApiUrl, "&type=scenario&id=" + event.item.command + "&action=start", "GET", true, true);
Vibe.vibrate('short');
//console.log("result command[" + event.item.command + "] : " + result);
cardResult.body(result);
cardResult.show();
setTimeout(function() {cardResult.hide();}, 500);
});

from pebblejs.

matopeto avatar matopeto commented on August 26, 2024

I run your code in cloud pebble (emulators) and on the watch too (Pebble steel), but it is working. When you get the error? What is your watch. It may be not work with Pebble 2. I sent Pull request for Pebble 2 support: #170 Feel free to try with my pull request.

from pebblejs.

edouardkleinhans avatar edouardkleinhans commented on August 26, 2024

My watch is a pebble (first gen). Everytime I launch this app, it crash.

from pebblejs.

pattyland avatar pattyland commented on August 26, 2024

Same here. My App works in Simulators for aplite and basalt. Test on a Pebble Time Steel: works. Test on a Pebble Classic: crashes with the exact error message from above!
Related topic: https://forums.pebble.com/t/pebble-js-crash/24705 ("anymore"!)

I made a new project, this is the full code of app.js:

var UI = require('ui');
var main = new UI.Window();

Crashes on Pebble classic with:

[HANDY] pebble-app.js:?: JS: starting app: 33B76CEC-E1F6-40A9-91CC-72F94E28A9AB Test
[HANDY] pebble-app.js:?: JS: Test: JavaScript Error:
TypeError: undefined is not an object (evaluating 'v.x')
    at copy (lib/vector2.js:38:15)
    at size (ui/window.js:260:29)
    at Window (ui/window.js:75:12)
    at app.js:2:25
    at require (loader.js:44:16)
    at require (loader.js:41:55)
    at main.js:41:10

from pebblejs.

matopeto avatar matopeto commented on August 26, 2024

More info here: https://forums.pebble.com/t/pebble-js-crash/24705/8

It looks like Pebble.getActiveWatchInfo return null like here: https://forums.pebble.com/t/getactivewatchinfo-returning-null-on-ios/23800

from pebblejs.

dnmgns avatar dnmgns commented on August 26, 2024

For the record, I'm getting this on a Pebble Time Steel but works fine in emulator:
[01:19:06] pkjs> JS: starting app: DA23189C-A117-4AF1-95F5-CCA07C843842 test
[01:19:06] pkjs> Error: Cellar Temp: TypeError: null is not an object (evaluating 'Pebble.getActiveWatchInfo().platform') at line 2186 in pebble-js-app.

from pebblejs.

iSevenDays avatar iSevenDays commented on August 26, 2024

I also get the error above. Did anybody find the fix?

from pebblejs.

iSevenDays avatar iSevenDays commented on August 26, 2024

The issue is that some pebble watch has color "unknown".
https://developer.rebble.io/developer.pebble.com/docs/c/Foundation/WatchInfo/index.html#WatchInfoColor
Weird to know, but getActiveWatchInfo depends on this property.
If you use iOS application, you need to inject the following methods(use IPAPatch as the example):

  • (BOOL)NSUUID_pb_isSystemAppUUID {
    return NO;
    }
  • (NSUInteger)PBWatch_watchColor {
    //NSUInteger color = [self PBWatch_watchColor];
    return 14; <-- Pebble Time Steel. Check your model from the URL above, the counter starts from 0.
    }
    [TWXRuntime exchangeInstanceMethod:@"pb_isSystemAppUUID" ofClass:@"NSUUID"];
    [TWXRuntime exchangeInstanceMethod:@"watchColor" ofClass:@"PBWatch"];

PM me for more details in case you don't know how to do this.

from pebblejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.