This commit is contained in:
Andrei Smirnov 2021-09-06 16:37:00 +03:00 committed by Iuri Matias
parent 315c4014a7
commit 10de9fc0c1
2 changed files with 20 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import NimQml, chronicles, os, strformat, times
import NimQml, chronicles, os, strformat, times, md5
import app/chat/core as chat
import app/wallet/v1/core as wallet
@ -66,6 +66,12 @@ proc mainProc() =
"/../resources.rcc"
QResource.registerResource(app.applicationDirPath & resources)
let singleInstance = newSingleInstance($toMD5(getAppDir()))
defer: singleInstance.delete()
if singleInstance.secondInstance():
info "Terminating the app as the second instance"
quit()
let statusAppIcon =
if defined(production):
if defined(macosx):
@ -207,6 +213,7 @@ proc mainProc() =
engine.setRootContextProperty("loginModel", login.variant)
engine.setRootContextProperty("onboardingModel", onboarding.variant)
engine.setRootContextProperty("singleInstance", newQVariant(singleInstance))
let isExperimental = if getEnv("EXPERIMENTAL") == "1": "1" else: "0" # value explicity passed to avoid trusting input
let experimentalFlag = newQVariant(isExperimental)

View File

@ -120,6 +120,18 @@ StatusWindow {
}
}
}
Connections {
target: singleInstance
onSecondInstanceDetected: {
console.log("User attempted to run the second instance of the application")
// activating this instance to give user visual feedback
applicationWindow.show()
applicationWindow.raise()
applicationWindow.requestActivate()
}
}
// The easiest way to get current system theme (is it light or dark) without using
// OS native methods is to check lightness (0 - 1.0) of the window color.