Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/xdjinnx/Slebble
Browse files Browse the repository at this point in the history
  • Loading branch information
xdjinnx committed Mar 5, 2016
2 parents 3270106 + 879fd32 commit 7485825
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 64 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
![Screenshot4](https://assets.getpebble.com/api/file/KxSn79xGRnSZl8YXahUi/convert?cache=true&w=144&h=168&fit=)

## Build & Install
You will need to download and install the Pebble SDK found on the [official Pebble developer website](https://developer.getpebble.com/sdk/install/). It's also recommended that you follow the instructions found on the website.
You will need to download and install the Pebble SDK found on the [official Pebble developer website](https://developer.getpebble.com/sdk/install/). It's also recommended that you follow the instructions found on the website. **NOTE: The appmessage does not work in Slebble when compiling with a SDK above version 3.7**

### No Pebble watch needed
There is an emulator available to use within the Pebble SDK. Instruction on how to use the emulator can be found [here](https://developer.getpebble.com/guides/publishing-tools/pebble-tool/#installing-watchapps) and how to use the settings page can be found [here](https://developer.getpebble.com/guides/pebble-apps/pebblekit-js/app-configuration/#testing-in-the-sdk-emulator).
Expand Down
19 changes: 13 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var gulp = require('gulp'),
shell = require('gulp-shell'),
webpack = require('webpack-stream'),
stripCode = require('gulp-strip-code'),
eslint = require('gulp-eslint');
eslint = require('gulp-eslint'),
concat = require('gulp-concat');

gulp.task('webpack', ['lint'], function() {
return gulp.src('./src/js/main.js')
Expand All @@ -17,26 +18,32 @@ gulp.task('webpack', ['lint'], function() {
}]
}
}))
.pipe(gulp.dest('./src/js/'));
.pipe(gulp.dest('./src/js/build/'));
});

gulp.task('lint', function(){
return gulp.src(['./src/js/*.js', '!./src/js/pebble-js-app.js'])
return gulp.src(['./src/js/*.js', '!./src/js/build/*'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('strip', ['webpack'],function(){
return gulp.src(['./src/js/pebble-js-app.js'])
return gulp.src(['./src/js/build/pebble-js-app.js'])
.pipe(stripCode({
start_comment: "test-block",
end_comment: "end-test-block"
}))
.pipe(gulp.dest('./src/js'));
.pipe(gulp.dest('./src/js/build/'));
});

gulp.task('build', ['strip'], shell.task([
gulp.task('concat', ['strip'], function() {
return gulp.src(['./src/js/build/pebble-js-app.js', './node_modules/trackjs/tracker.js'])
.pipe(concat('pebble-js-app.js'))
.pipe(gulp.dest('./src/js/build/'));
});

gulp.task('build', ['concat'], shell.task([
'pebble build'
]));

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"babel-eslint": "^4.1.3",
"babel-loader": "^5.3.2",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-eslint": "^1.0.0",
"gulp-shell": "^0.4.3",
"gulp-strip-code": "^0.1.2",
"jest-cli": "^0.8.2",
"object-assign": "^4.0.1",
"promise": "^7.0.4",
"trackjs": "^2.2.0",
"webpack-stream": "^2.1.1"
},
"scripts": {
Expand Down
124 changes: 68 additions & 56 deletions src/js/main.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,89 @@
/* eslint strict: 0 */
/* global trackJs */

var Slebble = require('./slebble.js');
window._trackJs = { token: '9f36ea9a2ea04439907e32f217e1fcc2' };

Pebble.addEventListener('ready', () => {
console.log('ready');
var response = localStorage.data;
if (response !== '' && typeof response === 'string') {
console.log('has data');
response = JSON.parse(localStorage.data);
console.log('saved data'+JSON.stringify(response));
Slebble.loadConfig(response);
var stations = [];
for (var i = 0; i < response.route.length; i++) {
Pebble.addEventListener('ready', () => {
trackJs.attempt(() => {
console.log('Running ready event');
console.log('TrackJs version: ' + trackJs.version);

var response = localStorage.data;
if (response !== '' && typeof response === 'string') {
console.log('has data');
response = JSON.parse(localStorage.data);
console.log('saved data'+JSON.stringify(response));
Slebble.loadConfig(response);
var stations = [];
for (var i = 0; i < response.route.length; i++) {
let ad = {};
ad.from = response.route[i].from.replace(/\053/g, ' ');
stations.push(ad);
}
Slebble.addStation(stations, 0);
} else {
let ad = {};
ad.from = response.route[i].from.replace(/\053/g, ' ');
stations.push(ad);
ad.from = 'No configuration';
ad = [ad];
Slebble.addStation(ad, 0);
}
Slebble.addStation(stations, 0);
} else {
let ad = {};
ad.from = 'No configuration';
ad = [ad];
Slebble.addStation(ad, 0);
}
}, this);
});


Pebble.addEventListener('showConfiguration', () => {
if (localStorage.data) {
Pebble.openURL('https://diesel-ability-711.appspot.com/webconfig/index.html?version=2.0' + '&setting=' + localStorage.data);
} else {
Pebble.openURL('https://diesel-ability-711.appspot.com/webconfig/index.html?version=2.0');
}
Pebble.addEventListener('showConfiguration', () => {
trackJs.attempt(() => {
if (localStorage.data) {
Pebble.openURL('https://diesel-ability-711.appspot.com/webconfig/index.html?version=2.0' + '&setting=' + localStorage.data);
} else {
Pebble.openURL('https://diesel-ability-711.appspot.com/webconfig/index.html?version=2.0');
}
}, this);
});

Pebble.addEventListener('webviewclosed', (e) => {
if (e.response === 'reset') {
localStorage.removeItem('data');
} else if (e.response !== 'CANCELLED' && e.response.substring(0, 12) !== '{"route": []' && e.response !== '{}') {
localStorage.setItem('data', e.response);
Pebble.addEventListener('webviewclosed', (e) => {
trackJs.attempt((e) => {
if (e.response === 'reset') {
localStorage.removeItem('data');
} else if (e.response !== 'CANCELLED' && e.response.substring(0, 12) !== '{"route": []' && e.response !== '{}') {
localStorage.setItem('data', e.response);

if (localStorage.data) {
var response = JSON.parse(localStorage.data);
Slebble.loadConfig(response);
if (localStorage.data) {
var response = JSON.parse(localStorage.data);
Slebble.loadConfig(response);

var stations = [];
for (var i = 0; i < response.route.length; i++) {
var ad = {};
ad.from = response.route[i].from.replace(/\053/g, ' ');
stations.push(ad);
}
var stations = [];
for (var i = 0; i < response.route.length; i++) {
var ad = {};
ad.from = response.route[i].from.replace(/\053/g, ' ');
stations.push(ad);
}

Slebble.addStation(stations, 0);
Slebble.addStation(stations, 0);

}
}
}
}, this, e);
});

Pebble.addEventListener('appmessage', (e) => {
/**
* payload[1] : menu row
* payload[2] : step, is saying which instruction the watch excpects
* payload[3] : expected package key
*/
if (e.payload[2] === 0) {
if (e.payload[1] !== 0) {
Slebble.requestRides(e.payload[1] - 1, e.payload[2], e.payload[3]);
Pebble.addEventListener('appmessage', (e) => {
trackJs.attempt((e) => {
/**
* payload[1] : menu row
* payload[2] : step, is saying which instruction the watch excpects
* payload[3] : expected package key
*/
if (e.payload[2] === 0) {
if (e.payload[1] !== 0) {
Slebble.requestRides(e.payload[1] - 1, e.payload[2], e.payload[3]);
} else {
Slebble.requestGeoRides(e.payload[3]);
}
} else if (e.payload[2] === 1){
Slebble.requestRides(e.payload[1], e.payload[2], e.payload[3]);
} else {
Slebble.requestGeoRides(e.payload[3]);
Slebble.requestUpdate(e.payload[3]);
}
} else if (e.payload[2] === 1){
Slebble.requestRides(e.payload[1], e.payload[2], e.payload[3]);
} else {
Slebble.requestUpdate(e.payload[3]);
}
}, this, e);
});
2 changes: 1 addition & 1 deletion wscript
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def build(ctx):
else:
binaries.append({'platform': p, 'app_elf': app_elf})

ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob('src/js/pebble-js-app.js'))
ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob('src/js/build/*.js'))

0 comments on commit 7485825

Please sign in to comment.