Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
runApp and uninstall should use appId + install app if not installed …
Browse files Browse the repository at this point in the history
…on runApp user request

change remote-simulator-client runApp and uninstall methods to use appId
(an in the install method) and use the appId to check if the application
is already installed in the DOMApllicationRegistry.webapps on the b2g side.

If an app in not installed try to install and run it again.
  • Loading branch information
rpl committed Feb 17, 2013
1 parent 36ce94c commit ca50f16
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
8 changes: 4 additions & 4 deletions addon/lib/remote-simulator-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ const RemoteSimulatorClient = Class({
},

// send a runApp request to the remote simulator actor
runApp: function(appOrigin, onResponse) {
runApp: function(appId, onResponse) {
let remote = this._remote;

remote.client.request({to: remote.simulator, type: "runApp", origin: appOrigin},
remote.client.request({to: remote.simulator, type: "runApp", appId: appId},
onResponse);
},

Expand All @@ -235,10 +235,10 @@ const RemoteSimulatorClient = Class({
onResponse);
},

uninstall: function(appOrigin, onResponse) {
uninstall: function(appId, onResponse) {
this._remote.client.request({ to: this._remote.simulator,
type: "uninstallApp",
origin: appOrigin,
appId: appId,
},
onResponse);
},
Expand Down
31 changes: 22 additions & 9 deletions addon/lib/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ let simulator = module.exports = {
simulator.error(error);
} else {
simulator.sendListApps();
simulator.runApp(app.origin);
simulator.runApp(app);
}
});
}
Expand Down Expand Up @@ -353,7 +353,7 @@ let simulator = module.exports = {
apps[id] = config;

simulator.run(function() {
simulator.remoteSimulator.uninstall(config.origin, function() {
simulator.remoteSimulator.uninstall(config.xkey, function() {
// app uninstall completed
// TODO: add success/error detection and report to the user
simulator.sendListApps();
Expand All @@ -379,7 +379,7 @@ let simulator = module.exports = {
simulator.error(error);
} else {
simulator.sendListApps();
simulator.runApp(app.origin);
simulator.runApp(app);
}
});
},
Expand Down Expand Up @@ -570,7 +570,7 @@ let simulator = module.exports = {
simulator.error(error);
} else {
simulator.sendListApps();
simulator.runApp(app.origin);
simulator.runApp(app);
}
});
},
Expand Down Expand Up @@ -692,9 +692,9 @@ let simulator = module.exports = {
}
},

runApp: function(appOrigin, next) {
runApp: function(app, next) {
this.run(function () {
simulator.remoteSimulator.runApp(appOrigin, next);
simulator.remoteSimulator.runApp(app.xkey, next);
});
},

Expand Down Expand Up @@ -764,13 +764,26 @@ let simulator = module.exports = {
simulator.error(error);
} else {
simulator.sendListApps();
simulator.runApp(app.origin);
simulator.runApp(app);
}
});
break;
case "runApp":
let appOrigin = this.apps[message.id].origin;
simulator.runApp(appOrigin);
let app = this.apps[message.id];
simulator.runApp(app, function (res) {
if (res.success === false) {
if (res.error === 'app-not-installed') {
// install and run if not installed
simulator.onMessage({
name: "updateApp",
id: message.id
});
} else {
// print error message
simulator.error("Run app failed: "+res.message);
}
}
});
break;
case "removeApp":
this.removeApp(message.id);
Expand Down
32 changes: 25 additions & 7 deletions prosthesis/content/dbg-simulator-actors.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ SimulatorActor.prototype = {
},

onRunApp: function(aRequest) {
log("simulator actor received a 'runApp' command:" + aRequest.origin);
log("simulator actor received a 'runApp' command:" + aRequest.appId);
let window = this.simulatorWindow;
let homescreen = XPCNativeWrapper.unwrap(this.homescreenWindow);
let WindowManager = homescreen.WindowManager;
let Applications = homescreen.Applications;
let appOrigin = aRequest.origin;
let DOMApplicationRegistry = window.DOMApplicationRegistry;
let appId = aRequest.appId;

if (!DOMApplicationRegistry.webapps[appId]) {
return { success: false, error: 'app-not-installed', message: 'App not installed.'}
}

let appOrigin = DOMApplicationRegistry.webapps[appId].origin;

let runnable = {
run: function() {
Expand Down Expand Up @@ -173,19 +179,30 @@ SimulatorActor.prototype = {
Services.tm.currentThread.dispatch(runnable,
Ci.nsIThread.DISPATCH_NORMAL);
return {
message: "runApp request received: " + appOrigin
message: "runApp request received: " + appOrigin,
success: true
};
},

onUninstallApp: function(aRequest) {
log("simulator actor received 'uninstallApp' command: " + aRequest.origin);
log("simulator actor received 'uninstallApp' command: " + aRequest.appId);
let window = this.simulatorWindow;
let DOMApplicationRegistry = window.DOMApplicationRegistry;
let appId = aRequest.appId;

if (!DOMApplicationRegistry.webapps[appId]) {
return { success: false, error: 'app-not-installed', message: 'App not installed.'}
}

let appOrigin = DOMApplicationRegistry.webapps[appId].origin;

log("uninstalling app by origin:"+appOrigin);

let runnable = {
run: function() {
try {
let mgmt = window.navigator.mozApps.mgmt;
let req = mgmt.uninstall({origin: aRequest.origin});
let req = mgmt.uninstall({origin: appOrigin});
req.onsuccess = function () {
log("uninstallApp success: " + req.result);
}
Expand All @@ -201,7 +218,8 @@ SimulatorActor.prototype = {
Services.tm.currentThread.dispatch(runnable,
Ci.nsIThread.DISPATCH_NORMAL);
return {
message: "uninstallApp request received"
message: "uninstallApp request received",
success: true
};
},

Expand Down

0 comments on commit ca50f16

Please sign in to comment.