Merge pull request #23 from status-im/feat/single-instance

feat: SingleInstance API
This commit is contained in:
Iuri Matias 2021-08-05 15:47:15 -04:00 committed by GitHub
commit 753187bae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 0 deletions

View File

@ -32,6 +32,7 @@ include "nimqml/private/qabstracttablemodel.nim"
include "nimqml/private/qresource.nim"
include "nimqml/private/qdeclarative.nim"
include "nimqml/private/nimqmlmacros.nim"
include "nimqml/private/singleinstance.nim"
proc signal_handler*(receiver: pointer, signal: cstring, slot: cstring) =

View File

@ -332,3 +332,8 @@ proc dos_escape_html(input: cstring): cstring {.cdecl, dynlib: dynLibName, impor
proc dos_qurl_fromUserInput(input: cstring): cstring {.cdecl, dynlib: dynLibName, importc.}
proc dos_qurl_host(host: cstring): cstring {.cdecl, dynlib: dynLibName, importc.}
proc dos_qurl_replaceHostAndAddPath(url: cstring, newScheme: cstring, newHost: cstring, pathPrefix: cstring): cstring {.cdecl, dynlib: dynLibName, importc.}
# SingleInstance
proc dos_singleinstance_create(uniqueName: cstring): DosQObject {.cdecl, dynlib: dynLibName, importc.}
proc dos_singleinstance_isfirst(vptr: DosQObject): bool {.cdecl, dynlib: dynLibName, importc.}
proc dos_singleinstance_delete(vptr: DosQObject) {.cdecl, dynlib: dynLibName, importc.}

View File

@ -130,5 +130,7 @@ type
Take, # The ownership is passed to the wrapper
Clone # The node should be cloned
SingleInstance* = ref object of QObject
const
UserRole* = 0x100

View File

@ -0,0 +1,17 @@
proc setup*(self: SingleInstance, uniqueName: string) =
## Setup a new SingleInstance
self.vptr = dos_singleinstance_create(uniqueName)
proc delete*(self: SingleInstance) =
## Delete the given SingleInstance
if self.vptr.isNil:
return
dos_singleinstance_delete(self.vptr)
self.vptr.resetToNil
proc newSingleInstance*(uniqueName: string): SingleInstance =
new(result, delete)
result.setup(uniqueName)
proc secondInstance*(self: SingleInstance): bool =
return not dos_singleinstance_isfirst(self.vptr)