31 lines
1002 B
Python
31 lines
1002 B
Python
"""Unprivileged XDG startup: wait for Node before opening its ordinary UI."""
|
|
import http.client
|
|
import os
|
|
import time
|
|
|
|
|
|
def wait_for_service(now=time.monotonic, sleep=time.sleep, connection=http.client.HTTPConnection):
|
|
deadline = now() + 180
|
|
while now() < deadline:
|
|
client = connection('127.0.0.1', 8780, timeout=2)
|
|
try:
|
|
client.request('GET', '/')
|
|
response = client.getresponse()
|
|
if response.status == 200:
|
|
return True
|
|
except (OSError, http.client.HTTPException):
|
|
pass
|
|
finally:
|
|
client.close()
|
|
sleep(1)
|
|
return False
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if os.geteuid() == 0:
|
|
raise SystemExit('Run in the normal graphical user session')
|
|
wait_for_service()
|
|
# Gtk.Application retains one window per desktop session. Its ordinary
|
|
# polkit authorization and error handling are unchanged.
|
|
os.execv('/usr/bin/mission-core-node', ['/usr/bin/mission-core-node'])
|