mirror of https://github.com/status-im/nimqml.git
Merge pull request #23 from status-im/feat/single-instance
feat: SingleInstance API
This commit is contained in:
commit
753187bae1
|
@ -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) =
|
||||
|
|
|
@ -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.}
|
||||
|
|
|
@ -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