[Gambas-user] Single instance application, anyone else done it?

Bruce Steers bsteers4 at gmail.com
Thu Jul 8 11:51:51 CEST 2021


On Wed, 7 Jul 2021 at 19:06, Benoît Minisini <g4mba5 at gmail.com> wrote:

> Le 07/07/2021 à 15:18, Bruce Steers a écrit :
> >
> > Excellent thank you Tony :)
> > I was so close lol, things are working now though thanks to your help.
> >
> > Much appreciated :)
> > BruceS
> >
>
> Actually doing that:
>
> If DBus.Session.Applications.Exist(TEXTEDITOR_DBUS_NAME) Then
>
> to know if you are already on the bus is wrong, because it's not atomic.
>
> You must instead set the DBus.Unique property to TRUE before
> registering, so that a unique name is used.
>
> That way, if you register on the DBus bus again, you will get an error,
> and it will be atomic.
>
> So you should do instead:
>
> DBus.Unique = TRUE
>
> hDbusObj = New DbusObj
>
> ' Registering the first object automatically registers the application.
>
> Try DBus.Session.Register(hDbusObj, TEXTEDITOR_PATH,
> TEXTEDITOR_DBUS_INTERFACE])
>
> If Error Then
>
>    ' We suppose we are already registered.
>
>    If Files.Count > 0 Then
>      For Each $file In Files
>        DBus[DBus.Name][TEXTEDITOR_PATH,
> TEXTEDITOR_DBUS_INTERFACE].Open($file.Name, $file.ReadOnly,
> $file.LineNumber, $file.ColumnNumber)
>      Next
>    Endif
>
>    Try DBus[DBus.Name][TEXTEDITOR_PATH, TEXTEDITOR_DBUS_INTERFACE].Show()
>
> Endif
>
> Tell me if it actually works!
>


Seems problematic though maybe.
To suppose an Error means the interface exists is not right.
Error.code is always -1 so that's no help
Error.text differs (bad address / unique address already registered/ etc)
but is not safe to use due to languages.
Is it possible to get the GError value?
https://dbus.freedesktop.org/doc/dbus-glib/dbus-glib-DBusGError.html#DBusGError

otherwise i will have to use the
If DBus.Session.Applications.Exist(DBUS_NAME) Then
just to be sure that's the error i got.
Regards
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210708/e6b9df8b/attachment-0001.htm>


More information about the User mailing list