[Gambas-user] DBus oddity with startup application.

Bruce Steers bsteers4 at gmail.com
Wed Aug 11 12:16:18 CEST 2021


My fix was terrible.
Seemed quite random if it would work or not, i tried using Wait / Sleep to
pause the app while login1 woke up but sometimes it would work sometimes
not.
My new fix is to make a simple gbs script, now the Shutdown option goes
like this..


*Public Sub btnShutdown_Click()*













*      Try
DBus["system://org.freedesktop.login1"]["/org/freedesktop/login1",
"org.freedesktop.login1.Manager"].PowerOff(True)      If Error Then
If RunGBS("PowerOff(True)") Then          Message("DBus error " &
Error.Text & "\n\nWill try shell command Shutdown...")          Print
("error " & Error.Text)          If System.Exist("shutdown") Then
  FakeDis("Shutting down, Closing programs cleanly\nPlease wait...")
    Application.Busy += 1            Shell System.Find("shutdown")
            Endif        Endif      Endif*
*End*













*Public Sub RunGBS(sText As String) As Boolean    Dim sOut As String, sName
As String = Temp("script") & ".gbs"    File.Save(sName, "#!/usr/bin/env
gbs3\nUse \"gb.dbus\"\n" &  "Try
DBus[\"system://org.freedesktop.login1\"][\"/org/freedesktop/login1\",
\"org.freedesktop.login1.Manager\"]." &   sText & "\nIf Error Then Print
\"Error: \" & Error.Text\n")  Chmod sName To "rwxr-x---"  Exec [sName] To
sOut  If InStr(sOut, "Error:") Then Return True  Return False  End*


That works.
If the running app didn't get login1 interfaces on load then the freshly
run gbs script does


On Mon, 9 Aug 2021 at 21:50, Benoît Minisini <g4mba5 at gmail.com> wrote:

> Le 09/08/2021 à 22:27, Bruce Steers a écrit :
> >
> >
> > On Mon, 9 Aug 2021, 19:33 Benoît Minisini, <g4mba5 at gmail.com
> > <mailto:g4mba5 at gmail.com>> wrote:
> >
> >     Le 09/08/2021 à 20:24, Bruce Steers a écrit :
> >      >
> >      > I've fixed the problem with this in my FMain.class ...
> >      >
> >      > *Static Public Sub _init()
> >      > *
> >      > *If Not Exist("/tmp/dish_opened") Then
> >      >      Wait 2
> >      >      File.Save("/tmp/dish_opened", "true")
> >      >    Endif
> >      >
> >      > End*
> >      > that gives a couple of seconds and then the
> >      > org.freedesktop.login1.Manager.PowerOff() function works
> >      > if app is closed and relaunched it finds the file in /tmp/ and
> >     does not
> >      > wait and dbus is still okay.
> >      >
> >      >
> >      > Seems any call to Dbus like DBus.System.Applications.Exist() in
> >     _init()
> >      > initialises dbus too early, it finds the login1
> >     DBus.System.Applications
> >      > but the Interfaces do not work.
> >
> >     Then the problem is in the application that handles
> >     'org.freedesktop.login1.Manager'.
> >
> >
> > Seems quite odd that the login1 interface is not found but the login1
> > Application is unless I restart the program.
>
> This is why I say it's a problem in the login1 application.
>
> It registers on the DBus bus, but misteriously does not return the
> expected introspection data when you first call
> DBus["system://org.freedesktop.login1"]["/org/freedesktop/login1",
> "org.freedesktop.login1.Manager"].
>
> I guess it does return the expected introspection later. The 'gb.dbus'
> component does not support DBus objects whose interface changes during
> their lifetime.
>
> I could add a Refresh() method to the DBusApplication class, so that you
> can call DBus["system://org.freedesktop.login1"].Refresh() to clear all
> the internal caches.
>
> But anyway you will have to wait an arbitrary amount of time, because
> apparently the "org.freedesktop.login1.Manager" interface does not
> appear immediately after the "login1" application register to the bus.
>
> Look at the 'gb.dbus' source code to understand how all that works.
>
> Regards,
>
> --
> Benoît Minisini
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210811/2cb1b41d/attachment.htm>


More information about the User mailing list