webXMPP

Check-in [cea9e18da0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Initial markups, actual phone notifications
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:cea9e18da01b65d1757cc6c1f454be9cef14e91abdd3fec0ee98bea5da826996
User & Date: vandyswa@gmail.com 2017-06-29 18:29:25
Context
2017-06-29
22:19
Bring up notified.py client on actual UBports phone check-in: a33e6791c5 user: vandyswa@gmail.com tags: master, trunk
18:29
Initial markups, actual phone notifications check-in: cea9e18da0 user: vandyswa@gmail.com tags: master, trunk
18:09
Bringup, actual notification delivery check-in: 7ff7888f34 user: vandyswa@gmail.com tags: master, trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to notified.py.

    82     82   is_locked = False
    83     83   def dbus_watcher(*args, **kwargs):
    84     84       global blinking, is_locked
    85     85   
    86     86       dd = args[1]
    87     87       if "IsActive" not in dd:
    88     88           return
    89         -    islocked = bool(dd["IsActive"])
    90         -    if blinking and (not islocked):
           89  +    is_locked = bool(dd["IsActive"])
           90  +    if blinking and (not is_locked):
    91     91           unblink()
    92     92   
    93     93   def setup_dbus():
    94     94       global leds
    95     95   
    96     96       # We only need this to turn the LED indication back off, so
    97     97       #  skip it if there's no LED's in the first place
................................................................................
   151    151       f = open(os.getenv("HOME") + "/.config/notify.json", "r")
   152    152       d = json.loads(f.read())
   153    153       f.close()
   154    154       cfg = DictOb(d)
   155    155   
   156    156   # New notifications contained in this packet
   157    157   def notify(pak):
   158         -    global gen, w
          158  +    global gen, w, leds, blinking, is_locked
   159    159   
   160    160       inner = pak.inner
   161    161       w("Notification: gen %d -> %d\n" % (gen, inner["gen"]))
   162    162       for tup in inner["msgs"]:
   163         -        w("%r\n" % (tup,))
          163  +        lt = len(tup)
          164  +
          165  +        # No details at all, so just show one
          166  +        if lt == 0:
          167  +            n = notify2.Notification("New Message")
          168  +            n.show()
          169  +            break
          170  +
          171  +        # Just who
          172  +        if lt == 1:
          173  +            n = notify2.Notification("New Message", tup[0])
          174  +
          175  +        # Who plus headline 
          176  +        elif lt == 2:
          177  +            n = notify2.Notification(tup[0], tup[1])
          178  +
          179  +        # Who plus headline plus body
          180  +        else:
          181  +            n = notify2.Notification(tup[0] + ": " + tup[1],
          182  +                tup[2])
          183  +
          184  +        n.show()
          185  +
          186  +    # Worry about the LEDs?
          187  +    if leds and (not blinking) and is_locked:
          188  +        blink()
   164    189   
   165    190   # Endless execution, notification client
   166    191   def run():
   167    192       global cfg, gen
   168    193   
   169    194       # Get a wrapper for our pong network connection
   170    195       conn = pong.Client(cfg.server, cfg.port, cfg.user, cfg.password)
   171    196   
   172    197       # Prep LEDs for use if possible
   173    198       setup_leds()
   174    199   
   175    200       # Watch DBus to turn LED's off when screen unlocks
   176    201       setup_dbus()
          202  +
          203  +    # Prepare for notifications
          204  +    notify2.init("Messsaging")
   177    205   
   178    206       # Params; we in particular need to know the server's
   179    207       #  intended timeout.
   180    208       while True:
   181    209           pak = conn.pingpong(conn.msg("params", "get"))
   182    210           if pak is not None:
   183    211               break
   184    212           time.sleep(pong.WAITNET)
   185    213   
   186    214       # This is how long they'll hold a notify/get pending before
   187    215       #  sending back a null result.
   188    216       # If we request one and don't hear back in this amount of
   189    217       #  time, we have a lost packet or something.
   190         -    tmo = pak.inner["timeout"]
          218  +    tmo = pak.inner["timeout"] * 1.1
   191    219   
   192    220       # Server loop
   193    221       dest = (cfg.server, cfg.port)
   194    222       while True:
   195    223           # Always yield for a second, so no matter
   196    224           #  what we never CPU spin hard.
   197    225           time.sleep(1)
................................................................................
   199    227           # Next round of notifications
   200    228           # Request events starting at this serial number
   201    229           pak = conn.msg("notify", "get", {
   202    230               "gen": gen,
   203    231               "detail": cfg.detail,
   204    232               "nmsg": cfg.nmsg})
   205    233           pak.who = dest
   206         -        resp = conn.ping_pong(pak, tmo*1.1)
          234  +        resp = conn.ping_pong(pak, tmo)
   207    235   
   208    236           # Failure
   209    237           if resp is None:
   210    238               time.sleep(pong.WAITNET)
   211    239               continue
   212    240   
   213    241           # Nothing happened