Added support for for cross-app launching and international characters.
This commit is contained in:
parent
01499d06dc
commit
cd296a6102
7 changed files with 125 additions and 33 deletions
|
@ -1,6 +1,6 @@
|
||||||
Software License Agreement (BSD License)
|
Software License Agreement (BSD License)
|
||||||
|
|
||||||
Copyright (c) 2010, Erik C. Thauvin (http://erik.thauvin.net/)
|
Copyright (c) 2010-11, Erik C. Thauvin (http://erik.thauvin.net/)
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
|
34
Ping.fm/app/assistants/app-assistant.js
Normal file
34
Ping.fm/app/assistants/app-assistant.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
var MainStageName = 'main';
|
||||||
|
|
||||||
|
function AppAssistant(appController)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AppAssistant.prototype.handleLaunch = function(launchParams)
|
||||||
|
{
|
||||||
|
var stageProxy = this.controller.getStageProxy(MainStageName);
|
||||||
|
var stageController = this.controller.getStageController(MainStageName);
|
||||||
|
|
||||||
|
if (stageProxy)
|
||||||
|
{
|
||||||
|
if (stageController)
|
||||||
|
{
|
||||||
|
stageController.window.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var pushMainScene = function(stageController)
|
||||||
|
{
|
||||||
|
stageController.pushScene(MainStageName, launchParams);
|
||||||
|
};
|
||||||
|
|
||||||
|
var stageArguments =
|
||||||
|
{
|
||||||
|
name: MainStageName,
|
||||||
|
lightweight: true
|
||||||
|
};
|
||||||
|
|
||||||
|
this.controller.createStageWithCallback(stageArguments, pushMainScene, 'card');
|
||||||
|
}
|
||||||
|
};
|
|
@ -153,13 +153,36 @@ KeyDialogAssistant.prototype.activate = function(event)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// MainAssistant
|
// MainAssistant
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
function MainAssistant()
|
function MainAssistant(args)
|
||||||
{
|
{
|
||||||
|
Mojo.Log.info('args: ' + args);
|
||||||
|
|
||||||
|
this.launchParams =
|
||||||
|
{
|
||||||
|
method: '',
|
||||||
|
title: '',
|
||||||
|
message: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
if (args.method)
|
||||||
|
{
|
||||||
|
this.launchParams.method = args.method;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.message)
|
||||||
|
{
|
||||||
|
this.launchParams.message = args.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.title)
|
||||||
|
{
|
||||||
|
this.launchParams.title = args.title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MainAssistant.prototype.setup = function()
|
MainAssistant.prototype.setup = function()
|
||||||
{
|
{
|
||||||
//$$('body')[0].addClassName('palm-dark');
|
// $$('body')[0].addClassName('palm-dark');
|
||||||
|
|
||||||
this.hasConnectivity = false;
|
this.hasConnectivity = false;
|
||||||
this.checkConnectivity();
|
this.checkConnectivity();
|
||||||
|
@ -169,8 +192,7 @@ MainAssistant.prototype.setup = function()
|
||||||
this.cookieData = new Mojo.Model.Cookie('netThauvinErikWebOsPingFm');
|
this.cookieData = new Mojo.Model.Cookie('netThauvinErikWebOsPingFm');
|
||||||
this.prefs = this.cookieData.get();
|
this.prefs = this.cookieData.get();
|
||||||
|
|
||||||
//this.api_key = 'edb93979c2abd58781f72d96f042e3a4';
|
this.api_key = 'e67b1c8c335bfc67cbd729d7a4535092';
|
||||||
this.api_key = 'e67b1c8c335bfc67cbd729d7a4535092';
|
|
||||||
this.messageMaxLen = 140;
|
this.messageMaxLen = 140;
|
||||||
|
|
||||||
this.defaultMethods = [
|
this.defaultMethods = [
|
||||||
|
@ -205,6 +227,42 @@ MainAssistant.prototype.setup = function()
|
||||||
this.cookieData.put(this.prefs);
|
this.cookieData.put(this.prefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.launchParams.title.blank())
|
||||||
|
{
|
||||||
|
this.prefs.showTitle = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.launchParams.method.blank())
|
||||||
|
{
|
||||||
|
var param;
|
||||||
|
var label;
|
||||||
|
var value;
|
||||||
|
|
||||||
|
for (var i = 0; i < this.prefs.methods.length; i++)
|
||||||
|
{
|
||||||
|
param = this.launchParams.method.toLowerCase();
|
||||||
|
value = this.prefs.methods[i].value.toLowerCase();
|
||||||
|
label = this.prefs.methods[i].label.toLowerCase();
|
||||||
|
|
||||||
|
if (param.charAt(0) == '@')
|
||||||
|
{
|
||||||
|
if (value.charAt(0) == '@')
|
||||||
|
{
|
||||||
|
if (label.substr(label.lastIndexOf('@'), param.length) === param)
|
||||||
|
{
|
||||||
|
this.prefs.defaultMethod = this.prefs.methods[i].value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (value === param || label === param)
|
||||||
|
{
|
||||||
|
this.prefs.defaultMethod = this.prefs.methods[i].value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var hasNoMethods = (this.defaultMethods.length == this.prefs.methods.length);
|
var hasNoMethods = (this.defaultMethods.length == this.prefs.methods.length);
|
||||||
|
|
||||||
this.updatedMethods =
|
this.updatedMethods =
|
||||||
|
@ -218,6 +276,7 @@ MainAssistant.prototype.setup = function()
|
||||||
label: '',
|
label: '',
|
||||||
command: 'do-title'
|
command: 'do-title'
|
||||||
};
|
};
|
||||||
|
|
||||||
this.toggleTitleMenu();
|
this.toggleTitleMenu();
|
||||||
|
|
||||||
this.appMenuModel =
|
this.appMenuModel =
|
||||||
|
@ -263,7 +322,7 @@ MainAssistant.prototype.setup = function()
|
||||||
hide: true
|
hide: true
|
||||||
}, this.titleModel =
|
}, this.titleModel =
|
||||||
{
|
{
|
||||||
value: ''
|
value: this.launchParams.title
|
||||||
});
|
});
|
||||||
|
|
||||||
this.controller.setupWidget('messageField',
|
this.controller.setupWidget('messageField',
|
||||||
|
@ -274,7 +333,7 @@ MainAssistant.prototype.setup = function()
|
||||||
focusMode: Mojo.Widget.focusAppendMode
|
focusMode: Mojo.Widget.focusAppendMode
|
||||||
}, this.messageModel =
|
}, this.messageModel =
|
||||||
{
|
{
|
||||||
value: ''
|
value: this.launchParams.message
|
||||||
});
|
});
|
||||||
|
|
||||||
this.pingButton = this.controller.get('pingBtn');
|
this.pingButton = this.controller.get('pingBtn');
|
||||||
|
@ -297,6 +356,8 @@ MainAssistant.prototype.setup = function()
|
||||||
|
|
||||||
this.activateWindowHandler = this.activateWindow.bindAsEventListener(this);
|
this.activateWindowHandler = this.activateWindow.bindAsEventListener(this);
|
||||||
this.controller.listen(this.controller.stageController.document, Mojo.Event.activate, this.activateWindowHandler);
|
this.controller.listen(this.controller.stageController.document, Mojo.Event.activate, this.activateWindowHandler);
|
||||||
|
|
||||||
|
this.updateCntLabel(this.messageModel.value.length);
|
||||||
};
|
};
|
||||||
|
|
||||||
MainAssistant.prototype.activateWindow = function()
|
MainAssistant.prototype.activateWindow = function()
|
||||||
|
@ -338,13 +399,13 @@ MainAssistant.prototype.togglePingButton = function()
|
||||||
|
|
||||||
MainAssistant.prototype.activate = function(event)
|
MainAssistant.prototype.activate = function(event)
|
||||||
{
|
{
|
||||||
//this.askForKey();
|
// this.askForKey();
|
||||||
};
|
};
|
||||||
|
|
||||||
MainAssistant.prototype.deactivate = function(event)
|
MainAssistant.prototype.deactivate = function(event)
|
||||||
{
|
{
|
||||||
this.cookieData.put(this.prefs);
|
this.cookieData.put(this.prefs);
|
||||||
//this.cookieData.remove();
|
// this.cookieData.remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
MainAssistant.prototype.cleanup = function()
|
MainAssistant.prototype.cleanup = function()
|
||||||
|
@ -354,7 +415,6 @@ MainAssistant.prototype.cleanup = function()
|
||||||
this.controller.stopListening(this.controller.stageController.document, Mojo.Event.activate, this.activateWindowHandler);
|
this.controller.stopListening(this.controller.stageController.document, Mojo.Event.activate, this.activateWindowHandler);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
MainAssistant.prototype.handleCommand = function(event)
|
MainAssistant.prototype.handleCommand = function(event)
|
||||||
{
|
{
|
||||||
if (event.type == Mojo.Event.command)
|
if (event.type == Mojo.Event.command)
|
||||||
|
@ -369,7 +429,7 @@ MainAssistant.prototype.handleCommand = function(event)
|
||||||
onChoose: function(value)
|
onChoose: function(value)
|
||||||
{
|
{
|
||||||
},
|
},
|
||||||
message: '<big><b>#{title} v#{version}</b></big><br/>© 2010, <a href="http://mobile.thauvin.net/">Erik C. Thauvin</a><br/><br/><small>This application uses the Ping.fm API but is not endorsed or certified by <a href="http://ping.fm/">Ping.fm</a></small>'.interpolate(
|
message: '<big><b>#{title} #{version}</b></big><br/>© 2010-11, <a href="http://mobile.thauvin.net/">Erik C. Thauvin</a><br/><br/><small>This application uses the Ping.fm API but is not endorsed or certified by <a href="http://ping.fm/">Ping.fm</a></small>'.interpolate(
|
||||||
{
|
{
|
||||||
title: Mojo.Controller.appInfo.title,
|
title: Mojo.Controller.appInfo.title,
|
||||||
version: Mojo.Controller.appInfo.version
|
version: Mojo.Controller.appInfo.version
|
||||||
|
@ -413,7 +473,13 @@ MainAssistant.prototype.handleCommand = function(event)
|
||||||
|
|
||||||
MainAssistant.prototype.handleKeyEvent = function(event)
|
MainAssistant.prototype.handleKeyEvent = function(event)
|
||||||
{
|
{
|
||||||
var len = this.messageMaxLen - this.messageModel.value.length;
|
this.updateCntLabel(this.messageModel.value.length);
|
||||||
|
this.togglePingButton();
|
||||||
|
};
|
||||||
|
|
||||||
|
MainAssistant.prototype.updateCntLabel = function(messageLength)
|
||||||
|
{
|
||||||
|
var len = this.messageMaxLen - messageLength;
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
{
|
{
|
||||||
|
@ -423,8 +489,6 @@ MainAssistant.prototype.handleKeyEvent = function(event)
|
||||||
{
|
{
|
||||||
this.controller.get('cntLabel').update(len);
|
this.controller.get('cntLabel').update(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.togglePingButton();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MainAssistant.prototype.askForKey = function(event)
|
MainAssistant.prototype.askForKey = function(event)
|
||||||
|
@ -463,7 +527,7 @@ MainAssistant.prototype.pingIt = function()
|
||||||
{
|
{
|
||||||
'api_key': this.api_key,
|
'api_key': this.api_key,
|
||||||
'user_app_key': this.prefs.user_app_key,
|
'user_app_key': this.prefs.user_app_key,
|
||||||
'body': Base64.encode(message),
|
'body': Base64.encode(unescape(encodeURIComponent(message))),
|
||||||
'encoding': 'base64',
|
'encoding': 'base64',
|
||||||
'debug': this.debug
|
'debug': this.debug
|
||||||
});
|
});
|
||||||
|
@ -471,7 +535,8 @@ MainAssistant.prototype.pingIt = function()
|
||||||
if (method.charAt(0) == '#')
|
if (method.charAt(0) == '#')
|
||||||
{
|
{
|
||||||
url = 'http://api.ping.fm/v1/user.tpost';
|
url = 'http://api.ping.fm/v1/user.tpost';
|
||||||
params.set('trigger', method.substring(1));
|
// toLowerCase workaround Ping.fm API bug
|
||||||
|
params.set('trigger', method.substring(1).toLowerCase());
|
||||||
}
|
}
|
||||||
else if (method.charAt(0) == '@')
|
else if (method.charAt(0) == '@')
|
||||||
{
|
{
|
||||||
|
@ -486,7 +551,7 @@ MainAssistant.prototype.pingIt = function()
|
||||||
var title = this.titleModel.value;
|
var title = this.titleModel.value;
|
||||||
if (title != '')
|
if (title != '')
|
||||||
{
|
{
|
||||||
params.set('title', Base64.encode(title));
|
params.set('title', Base64.encode(unescape(encodeURIComponent(title))));
|
||||||
}
|
}
|
||||||
|
|
||||||
Mojo.Log.info('pingIt: ' + params.toQueryString());
|
Mojo.Log.info('pingIt: ' + params.toQueryString());
|
||||||
|
@ -649,7 +714,6 @@ MainAssistant.prototype.updateMethodsSuccess = function(transport)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
MainAssistant.prototype.updateMethodsFailure = function(transport)
|
MainAssistant.prototype.updateMethodsFailure = function(transport)
|
||||||
{
|
{
|
||||||
this.transportFailure('updateMethodFailure', transport);
|
this.transportFailure('updateMethodFailure', transport);
|
||||||
|
@ -671,7 +735,7 @@ MainAssistant.prototype.updateTriggersSuccess = function(transport)
|
||||||
for (var i = 0; i < triggers.length; i++)
|
for (var i = 0; i < triggers.length; i++)
|
||||||
{
|
{
|
||||||
var id = '#' + triggers[i].getAttribute('id');
|
var id = '#' + triggers[i].getAttribute('id');
|
||||||
//var method = triggers[i].getAttribute('method');
|
// var method = triggers[i].getAttribute('method');
|
||||||
|
|
||||||
this.prefs.methods.unshift(
|
this.prefs.methods.unshift(
|
||||||
{
|
{
|
||||||
|
@ -693,7 +757,6 @@ MainAssistant.prototype.updateTriggersFailure = function(transport)
|
||||||
this.transportFailure('updateTriggersFailure', transport);
|
this.transportFailure('updateTriggersFailure', transport);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
MainAssistant.prototype.handleConnectivity = function(status)
|
MainAssistant.prototype.handleConnectivity = function(status)
|
||||||
{
|
{
|
||||||
if (status.isInternetConnectionAvailable === true)
|
if (status.isInternetConnectionAvailable === true)
|
||||||
|
@ -730,4 +793,3 @@ MainAssistant.prototype.transportFailure = function(caller, transport)
|
||||||
status: transport.status
|
status: transport.status
|
||||||
}), this.controller.window);
|
}), this.controller.window);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
function StageAssistant()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
StageAssistant.prototype.setup = function()
|
|
||||||
{
|
|
||||||
this.controller.pushScene('main');
|
|
||||||
};
|
|
|
@ -1,10 +1,11 @@
|
||||||
{
|
{
|
||||||
"id": "net.thauvin.erik.webos.pingfm",
|
"id": "net.thauvin.erik.webos.pingfm",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"vendor": "Erik C. Thauvin",
|
"vendor": "Erik C. Thauvin",
|
||||||
"type": "web",
|
"type": "web",
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"main": "index.html",
|
"main": "index.html",
|
||||||
"title": "Ping.fm",
|
"title": "Ping.fm",
|
||||||
"icon": "icon.png"
|
"icon": "icon.png",
|
||||||
}
|
"noWindow": true
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
[
|
[
|
||||||
{"source": "app/assistants/stage-assistant.js"},
|
{"source": "app/assistants/app-assistant.js"},
|
||||||
{
|
{
|
||||||
"scenes": "main",
|
"scenes": "main",
|
||||||
"source": "app/assistants/main-assistant.js"
|
"source": "app/assistants/main-assistant.js"
|
||||||
|
|
3
remove.bat
Normal file
3
remove.bat
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
@echo on
|
||||||
|
palm-install -r net.thauvin.erik.webos.pingfm
|
||||||
|
pause
|
Loading…
Add table
Add a link
Reference in a new issue