Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register app running user name in rwt_app_chooser #95

Merged
merged 2 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rwt_app_chooser/www/components/add_robot.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ <h1 class="title">Add Robot</h1>
var rs = load_robots();
for (var r of rs) {
if (r.name == name) {
var prompt = phonon.alert("Robot " + name + " is already registered", "Error");
prompt.on("confirm", function() {});
var alert = phonon.alert("Robot " + name + " is already registered", "Error");
alert.on("confirm", function() {});
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions rwt_app_chooser/www/components/robot.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ <h1 class="title">Select Robot</h1>
});

document.querySelector("#clear").on("tap", function() {
var prompt = phonon.prompt("Are you sure to remove all robots from the list?", "Clear");
prompt.on("confirm", function(value) {
var confirm = phonon.confirm("Are you sure to remove all robots from the list?", "Clear");
confirm.on("confirm", function() {
robots = [];
render_list();
phonon.notif("Cleared all robots", 3000, false, false);
});
prompt.on("cancel", function() {
confirm.on("cancel", function() {
phonon.notif("Canceled removing the list", 3000, false, false);
});
});
Expand Down
92 changes: 71 additions & 21 deletions rwt_app_chooser/www/components/task.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h1 class="title">Select Task</h1>
var robot_uri = null;
var ros = null;
var app_list_sub = null;
var running_user_name = null;

var start_app = function(name, cb) {
var srv_name = '/' + robot_name + '/start_app';
Expand Down Expand Up @@ -53,6 +54,38 @@ <h1 class="title">Select Task</h1>
}
};

var get_running_user_name = function(next) {
var param = new ROSLIB.Param({
ros: ros,
name: "/app_manager/running_user_name",
});
param.get(function(value) {
console.log("Getting param: /app_manager/running_user_name " + value);
running_user_name = value;
next();
});
}

var set_running_user_name = function(param_value) {
var param = new ROSLIB.Param({
ros: ros,
name: "/app_manager/running_user_name",
});
console.log("Setting param: /app_manager/running_user_name " + param_value);
param.set(param_value);
running_user_name = param_value;
}

var delete_running_user_name = function(param_name) {
var param = new ROSLIB.Param({
ros: ros,
name: "/app_manager/running_user_name",
});
console.log("Deleting param: /app_manager/running_user_name");
param.delete();
running_user_name = null;
}

var render_app_list = function(apps) {
clear_app_list();
var parent = document.querySelector("#app-list");
Expand All @@ -73,8 +106,10 @@ <h1 class="title">Select Task</h1>
item.on('tap', function() {
var that = this;
if (this.running) {
var prompt = phonon.prompt("Shutdown " + this.display_name + "?", "Kill application");
prompt.on("confirm", function(value) {
var confirm = phonon.confirm("Shutdown " + that.display_name + "?", "Kill application");
confirm.on("confirm", function() {
console.log("unregister app user name");
delete_running_user_name();
stop_app(that.name, function(res) {
console.log("stop_app", res);
if (res.stopped) {
Expand All @@ -85,15 +120,23 @@ <h1 class="title">Select Task</h1>
});
});
} else {
var prompt = phonon.prompt("Launch " + this.display_name + "?", "Launch application");
var prompt = phonon.prompt("Please fill your user name.", "Register user name");
prompt.on("confirm", function(value) {
start_app(that.name, function(res) {
console.log("start_app", res);
if (res.started) {
phonon.notif("Launched " + that.display_name, 3000, false, false);
} else {
phonon.notif(res.message + " (" + res.error_code + ")", 3000, false, false);
}
var user_name = String(value);
if (user_name.length > 0) {
console.log("register app user name: " + user_name);
set_running_user_name(user_name);
}
var confirm = phonon.confirm("Launch " + that.display_name + "?", "Launch application");
confirm.on("confirm", function() {
start_app(that.name, function(res) {
console.log("start_app", res);
if (res.started) {
phonon.notif("Launched " + that.display_name, 3000, false, false);
} else {
phonon.notif(res.message + " (" + res.error_code + ")", 3000, false, false);
}
});
});
});
}
Expand Down Expand Up @@ -174,19 +217,26 @@ <h1 class="title">Select Task</h1>
console.log("subscribing: " + list_name);

app_list_sub.subscribe(function(msg) {
console.log("subscribe");
var apps = [];
msg.available_apps.forEach(function(app) {
if (msg.running_apps.find(function(e) {
return e.name == app.name;
})) {
app["running"] = true;
} else {
app["running"] = false;
get_running_user_name(function() {
console.log("subscribe");
var apps = [];
var running = false;
msg.available_apps.forEach(function(app) {
if (msg.running_apps.find(function(e) {
return e.name == app.name;
})) {
app["running"] = true;
running = true;
} else {
app["running"] = false;
}
apps.push(app);
});
if (!running && running_user_name) {
delete_running_user_name();
}
apps.push(app);
render_app_list(apps);
});
render_app_list(apps);
});
});
};
Expand Down