mirror of https://github.com/status-im/nimqml.git
feat: single instance
This commit is contained in:
parent
65fa68c244
commit
cbf7c56462
|
@ -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) =
|
||||
|
|
|
@ -330,3 +330,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.}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue