diff options
author | pacien | 2018-02-25 01:42:27 +0100 |
---|---|---|
committer | pacien | 2018-02-25 01:42:27 +0100 |
commit | c6de35b7b283d1693c314559effd177cb912862b (patch) | |
tree | 03a8157dbb389222a45abaeabf85662ef99177ee /app/src/main/java/org/pacien/tincapp/commands | |
parent | eb31e3770f8c79ee0debb866e0fd56f9c37eb1be (diff) | |
download | tincapp-c6de35b7b283d1693c314559effd177cb912862b.tar.gz |
Add log viewer
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Executor.kt | 18 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | 5 |
2 files changed, 14 insertions, 9 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt index 39c413e..96e48b9 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt | |||
@@ -47,16 +47,16 @@ internal object Executor { | |||
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | fun call(cmd: Command): CompletableFuture<List<String>> { | 50 | fun run(cmd: Command): Process = try { |
51 | val proc = try { | 51 | ProcessBuilder(cmd.asList()).start() |
52 | ProcessBuilder(cmd.asList()).start() | 52 | } catch (e: IOException) { |
53 | } catch (e: IOException) { | 53 | throw CommandExecutionException(e.message ?: "Could not start process.") |
54 | throw CommandExecutionException(e.message ?: "Could not start process.") | 54 | } |
55 | } | ||
56 | 55 | ||
57 | return supplyAsyncTask<List<String>> { | 56 | fun call(cmd: Command): CompletableFuture<List<String>> = run(cmd).let { process -> |
58 | if (proc.waitFor() == 0) read(proc.inputStream) | 57 | supplyAsyncTask<List<String>> { |
59 | else throw CommandExecutionException(read(proc.errorStream).lastOrNull() ?: "Non-zero exit status.") | 58 | if (process.waitFor() == 0) read(process.inputStream) |
59 | else throw CommandExecutionException(read(process.errorStream).lastOrNull() ?: "Non-zero exit status.") | ||
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt index 556288a..0f4c0a4 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | |||
@@ -46,4 +46,9 @@ object Tinc { | |||
46 | .withOption("config", AppPaths.confDir(netName).absolutePath) | 46 | .withOption("config", AppPaths.confDir(netName).absolutePath) |
47 | .withArguments("join", invitationUrl)) | 47 | .withArguments("join", invitationUrl)) |
48 | .thenApply<String> { it.joinToString("\n") } | 48 | .thenApply<String> { it.joinToString("\n") } |
49 | |||
50 | fun log(netName: String, level: Int? = null): Process = | ||
51 | Executor.run(newCommand(netName) | ||
52 | .withArguments("log") | ||
53 | .apply { if (level != null) withArguments(level.toString()) }) | ||
49 | } | 54 | } |