mirror of
https://github.com/amir1376/ab-download-manager.git
synced 2025-02-20 11:43:24 +08:00
add --exit to exit the current active process
This commit is contained in:
parent
0dc4c676ee
commit
fbbd39daa8
@ -62,6 +62,9 @@ fun main(args: Array<String>) {
|
||||
dispatchVersionAndExit()
|
||||
}
|
||||
val singleInstance = SingleInstanceUtil(AppInfo.configDir.toOkioPath())
|
||||
if (appArguments.exit) {
|
||||
exitExistingProcessAndExit(singleInstance)
|
||||
}
|
||||
if (appArguments.startIfNotStarted && !AppInfo.isInIDE()) {
|
||||
startAndWaitForRunIfNotRunning(singleInstance)
|
||||
}
|
||||
@ -96,10 +99,15 @@ private fun dispatchVersionAndExit(): Nothing {
|
||||
exitProcess(0)
|
||||
}
|
||||
|
||||
private fun exitExistingProcessAndExit(singleInstance: SingleInstanceUtil): Nothing {
|
||||
singleInstance.sendToInstance(Commands.exit)
|
||||
exitProcess(0)
|
||||
}
|
||||
|
||||
private fun dispatchIntegrationPortAndExit(singleInstance: SingleInstanceUtil): Nothing {
|
||||
val port =
|
||||
singleInstance.sendToInstance(Commands.getIntegrationPort)
|
||||
.orElse { IntegrationPortBroadcaster.INTEGRATION_UNKNOWN }
|
||||
singleInstance.sendToInstance(Commands.getIntegrationPort)
|
||||
.orElse { IntegrationPortBroadcaster.INTEGRATION_UNKNOWN }
|
||||
print(port)
|
||||
exitProcess(0)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ data class AppArguments(
|
||||
val startSilent: Boolean,
|
||||
val debug: Boolean,
|
||||
val version: Boolean,
|
||||
val exit: Boolean,
|
||||
) {
|
||||
companion object {
|
||||
private lateinit var instance: AppArguments
|
||||
@ -25,6 +26,7 @@ data class AppArguments(
|
||||
startSilent = args.contains(Args.BACKGROUND),
|
||||
debug = args.contains(Args.DEBUG),
|
||||
version = args.contains(Args.VERSION),
|
||||
exit = args.contains(Args.EXIT),
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -35,5 +37,6 @@ data class AppArguments(
|
||||
const val GET_INTEGRATION_PORT = "--get-integration-port"
|
||||
const val DEBUG = "--debug"
|
||||
const val VERSION = "--version"
|
||||
const val EXIT = "--exit"
|
||||
}
|
||||
}
|
@ -1,20 +1,16 @@
|
||||
package com.abdownloadmanager.desktop
|
||||
|
||||
import com.abdownloadmanager.desktop.Commands.GET_INTEGRATION_PORT
|
||||
import com.abdownloadmanager.desktop.Commands.IS_READY
|
||||
import com.abdownloadmanager.desktop.Commands.SHOW_USER_THAT_APP_IS_RUNNING
|
||||
import com.abdownloadmanager.desktop.actions.exitAction
|
||||
import com.abdownloadmanager.desktop.utils.IntegrationPortBroadcaster
|
||||
import com.abdownloadmanager.desktop.utils.singleInstance.Command
|
||||
import com.abdownloadmanager.desktop.utils.singleInstance.MutableSingleInstanceServerHandler
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
object Commands {
|
||||
const val IS_READY = "IS_READY"
|
||||
const val SHOW_USER_THAT_APP_IS_RUNNING = "SHOW_USER_THAT_APP_IS_RUNNING"
|
||||
const val GET_INTEGRATION_PORT = "GET_INTEGRATION_PORT"
|
||||
val isReady = Command<Boolean>("isReady")
|
||||
val showUserThatAppIsRunning = Command<Unit>("showUserThatAppIsRunning")
|
||||
val getIntegrationPort = Command<Int>("getIntegrationPort")
|
||||
val exit = Command<Unit>("exit")
|
||||
}
|
||||
object SingleInstanceServerInitializer:KoinComponent {
|
||||
private val appComponent by inject<AppComponent> ()
|
||||
@ -29,5 +25,8 @@ object SingleInstanceServerInitializer:KoinComponent {
|
||||
mutableHandler.add(Commands.isReady){
|
||||
appComponent.isReady()
|
||||
}
|
||||
mutableHandler.add(Commands.exit) {
|
||||
exitAction()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user