1
0
mirror of https://github.com/danog/termux-api.git synced 2024-11-30 04:19:20 +01:00

Show pending job state at end of command, state if no pending jobs

This commit is contained in:
Ben Moran 2019-02-23 12:09:36 +00:00 committed by Fredrik Fornwall
parent 51a02f4fd8
commit 61262f7510

View File

@ -140,9 +140,6 @@ public class JobSchedulerAPI {
PersistableBundle extras = new PersistableBundle(); PersistableBundle extras = new PersistableBundle();
extras.putString(SchedulerJobService.SCRIPT_FILE_PATH, file.getAbsolutePath()); extras.putString(SchedulerJobService.SCRIPT_FILE_PATH, file.getAbsolutePath());
displayPendingJobs(apiReceiver, intent, jobScheduler);
ComponentName serviceComponent = new ComponentName(context, SchedulerJobService.class); ComponentName serviceComponent = new ComponentName(context, SchedulerJobService.class);
JobInfo.Builder builder = new JobInfo.Builder(jobId, serviceComponent) JobInfo.Builder builder = new JobInfo.Builder(jobId, serviceComponent)
.setExtras(extras) .setExtras(extras)
@ -167,13 +164,20 @@ public class JobSchedulerAPI {
Log.i(LOG_TAG, message); Log.i(LOG_TAG, message);
ResultReturner.returnData(apiReceiver, intent, out -> out.println(message)); ResultReturner.returnData(apiReceiver, intent, out -> out.println(message));
displayPendingJobs(apiReceiver, intent, jobScheduler);
} }
private static void displayPendingJobs(TermuxApiReceiver apiReceiver, Intent intent, JobScheduler jobScheduler) { private static void displayPendingJobs(TermuxApiReceiver apiReceiver, Intent intent, JobScheduler jobScheduler) {
// Display pending jobs // Display pending jobs
for (JobInfo job : jobScheduler.getAllPendingJobs()) { final List<JobInfo> jobs = jobScheduler.getAllPendingJobs();
final JobInfo j = job; if (jobs.isEmpty()) {
ResultReturner.returnData(apiReceiver, intent, out -> out.println(String.format(Locale.ENGLISH, "Pending %s", formatJobInfo(j)))); ResultReturner.returnData(apiReceiver, intent, out -> out.println("No pending jobs"));
return;
}
for (JobInfo job : jobs) {
ResultReturner.returnData(apiReceiver, intent, out -> out.println(String.format(Locale.ENGLISH, "Pending %s", formatJobInfo(job))));
} }
} }