aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/commands
diff options
context:
space:
mode:
authorpacien2018-02-24 02:37:23 +0100
committerpacien2018-02-24 02:37:23 +0100
commite2f985900c3b07f13c768c803106bdd4d9b94772 (patch)
tree6d1dd2d108547780ffc827880db303643704f2ce /app/src/main/java/org/pacien/tincapp/commands
parent97407c40660893650a6d37c5d760167e2e4d24c7 (diff)
downloadtincapp-e2f985900c3b07f13c768c803106bdd4d9b94772.tar.gz
Unify unit future typing
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands')
-rw-r--r--app/src/main/java/org/pacien/tincapp/commands/Executor.kt6
-rw-r--r--app/src/main/java/org/pacien/tincapp/commands/TincApp.kt7
2 files changed, 6 insertions, 7 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 fedd0d2..39c413e 100644
--- a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt
+++ b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt
@@ -33,12 +33,12 @@ internal object Executor {
33 33
34 private fun read(stream: InputStream) = BufferedReader(InputStreamReader(stream)).readLines() 34 private fun read(stream: InputStream) = BufferedReader(InputStreamReader(stream)).readLines()
35 35
36 fun forkExec(cmd: Command): CompletableFuture<Void> { 36 fun forkExec(cmd: Command): CompletableFuture<Unit> {
37 val pid = forkExec(cmd.asArray()).also { 37 val pid = forkExec(cmd.asArray()).also {
38 if (it == FAILED) throw CommandExecutionException("Could not fork child process.") 38 if (it == FAILED) throw CommandExecutionException("Could not fork child process.")
39 } 39 }
40 40
41 return CompletableFuture.runAsync { 41 return runAsyncTask {
42 when (wait(pid)) { 42 when (wait(pid)) {
43 SUCCESS -> Unit 43 SUCCESS -> Unit
44 FAILED -> throw CommandExecutionException("Process terminated abnormally.") 44 FAILED -> throw CommandExecutionException("Process terminated abnormally.")
@@ -60,6 +60,6 @@ internal object Executor {
60 } 60 }
61 } 61 }
62 62
63 fun runAsyncTask(r: () -> Unit) = CompletableFuture.runAsync(Runnable(r), AsyncTask.THREAD_POOL_EXECUTOR)!! 63 fun runAsyncTask(r: () -> Unit) = CompletableFuture.supplyAsync(Supplier(r), AsyncTask.THREAD_POOL_EXECUTOR)!!
64 fun <U> supplyAsyncTask(s: () -> U) = CompletableFuture.supplyAsync(Supplier(s), AsyncTask.THREAD_POOL_EXECUTOR)!! 64 fun <U> supplyAsyncTask(s: () -> U) = CompletableFuture.supplyAsync(Supplier(s), AsyncTask.THREAD_POOL_EXECUTOR)!!
65} 65}
diff --git a/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt b/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt
index e5172c8..3c2e27a 100644
--- a/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt
+++ b/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt
@@ -1,6 +1,5 @@
1package org.pacien.tincapp.commands 1package org.pacien.tincapp.commands
2 2
3import java8.util.concurrent.CompletableFuture
4import org.pacien.tincapp.R 3import org.pacien.tincapp.R
5import org.pacien.tincapp.commands.Executor.runAsyncTask 4import org.pacien.tincapp.commands.Executor.runAsyncTask
6import org.pacien.tincapp.context.App 5import org.pacien.tincapp.context.App
@@ -30,17 +29,17 @@ object TincApp {
30 throw FileNotFoundException(App.getResources().getString(R.string.message_network_config_not_found_format, e.message!!)) 29 throw FileNotFoundException(App.getResources().getString(R.string.message_network_config_not_found_format, e.message!!))
31 } 30 }
32 31
33 fun removeScripts(netName: String): CompletableFuture<Void> = runAsyncTask { 32 fun removeScripts(netName: String) = runAsyncTask {
34 listScripts(netName).forEach { it.delete() } 33 listScripts(netName).forEach { it.delete() }
35 } 34 }
36 35
37 fun generateIfaceCfg(netName: String): CompletableFuture<Void> = runAsyncTask { 36 fun generateIfaceCfg(netName: String) = runAsyncTask {
38 VpnInterfaceConfiguration 37 VpnInterfaceConfiguration
39 .fromInvitation(AppPaths.invitationFile(netName)) 38 .fromInvitation(AppPaths.invitationFile(netName))
40 .write(AppPaths.netConfFile(netName)) 39 .write(AppPaths.netConfFile(netName))
41 } 40 }
42 41
43 fun setPassphrase(netName: String, currentPassphrase: String? = null, newPassphrase: String?): CompletableFuture<Void> = runAsyncTask { 42 fun setPassphrase(netName: String, currentPassphrase: String? = null, newPassphrase: String?) = runAsyncTask {
44 listPrivateKeys(netName) 43 listPrivateKeys(netName)
45 .filter { it.exists() } 44 .filter { it.exists() }
46 .map { Pair(PemUtils.read(it), it) } 45 .map { Pair(PemUtils.read(it), it) }