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 Unified Diffs Show Whitespace Changes Patch

Changes to notified.py.

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
151
152
153
154
155
156
157
158
159
160
161
162
163

























164
165
166
167
168
169
170
171
172
173
174
175
176



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
...
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
is_locked = False
def dbus_watcher(*args, **kwargs):
    global blinking, is_locked

    dd = args[1]
    if "IsActive" not in dd:
        return
    islocked = bool(dd["IsActive"])
    if blinking and (not islocked):
        unblink()

def setup_dbus():
    global leds

    # We only need this to turn the LED indication back off, so
    #  skip it if there's no LED's in the first place
................................................................................
    f = open(os.getenv("HOME") + "/.config/notify.json", "r")
    d = json.loads(f.read())
    f.close()
    cfg = DictOb(d)

# New notifications contained in this packet
def notify(pak):
    global gen, w

    inner = pak.inner
    w("Notification: gen %d -> %d\n" % (gen, inner["gen"]))
    for tup in inner["msgs"]:
        w("%r\n" % (tup,))


























# Endless execution, notification client
def run():
    global cfg, gen

    # Get a wrapper for our pong network connection
    conn = pong.Client(cfg.server, cfg.port, cfg.user, cfg.password)

    # Prep LEDs for use if possible
    setup_leds()

    # Watch DBus to turn LED's off when screen unlocks
    setup_dbus()




    # Params; we in particular need to know the server's
    #  intended timeout.
    while True:
        pak = conn.pingpong(conn.msg("params", "get"))
        if pak is not None:
            break
        time.sleep(pong.WAITNET)

    # This is how long they'll hold a notify/get pending before
    #  sending back a null result.
    # If we request one and don't hear back in this amount of
    #  time, we have a lost packet or something.
    tmo = pak.inner["timeout"]

    # Server loop
    dest = (cfg.server, cfg.port)
    while True:
        # Always yield for a second, so no matter
        #  what we never CPU spin hard.
        time.sleep(1)
................................................................................
        # Next round of notifications
        # Request events starting at this serial number
        pak = conn.msg("notify", "get", {
            "gen": gen,
            "detail": cfg.detail,
            "nmsg": cfg.nmsg})
        pak.who = dest
        resp = conn.ping_pong(pak, tmo*1.1)

        # Failure
        if resp is None:
            time.sleep(pong.WAITNET)
            continue

        # Nothing happened







|
|







 







|




|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>













>
>
>













|







 







|







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
is_locked = False
def dbus_watcher(*args, **kwargs):
    global blinking, is_locked

    dd = args[1]
    if "IsActive" not in dd:
        return
    is_locked = bool(dd["IsActive"])
    if blinking and (not is_locked):
        unblink()

def setup_dbus():
    global leds

    # We only need this to turn the LED indication back off, so
    #  skip it if there's no LED's in the first place
................................................................................
    f = open(os.getenv("HOME") + "/.config/notify.json", "r")
    d = json.loads(f.read())
    f.close()
    cfg = DictOb(d)

# New notifications contained in this packet
def notify(pak):
    global gen, w, leds, blinking, is_locked

    inner = pak.inner
    w("Notification: gen %d -> %d\n" % (gen, inner["gen"]))
    for tup in inner["msgs"]:
        lt = len(tup)

        # No details at all, so just show one
        if lt == 0:
            n = notify2.Notification("New Message")
            n.show()
            break

        # Just who
        if lt == 1:
            n = notify2.Notification("New Message", tup[0])

        # Who plus headline 
        elif lt == 2:
            n = notify2.Notification(tup[0], tup[1])

        # Who plus headline plus body
        else:
            n = notify2.Notification(tup[0] + ": " + tup[1],
                tup[2])

        n.show()

    # Worry about the LEDs?
    if leds and (not blinking) and is_locked:
        blink()

# Endless execution, notification client
def run():
    global cfg, gen

    # Get a wrapper for our pong network connection
    conn = pong.Client(cfg.server, cfg.port, cfg.user, cfg.password)

    # Prep LEDs for use if possible
    setup_leds()

    # Watch DBus to turn LED's off when screen unlocks
    setup_dbus()

    # Prepare for notifications
    notify2.init("Messsaging")

    # Params; we in particular need to know the server's
    #  intended timeout.
    while True:
        pak = conn.pingpong(conn.msg("params", "get"))
        if pak is not None:
            break
        time.sleep(pong.WAITNET)

    # This is how long they'll hold a notify/get pending before
    #  sending back a null result.
    # If we request one and don't hear back in this amount of
    #  time, we have a lost packet or something.
    tmo = pak.inner["timeout"] * 1.1

    # Server loop
    dest = (cfg.server, cfg.port)
    while True:
        # Always yield for a second, so no matter
        #  what we never CPU spin hard.
        time.sleep(1)
................................................................................
        # Next round of notifications
        # Request events starting at this serial number
        pak = conn.msg("notify", "get", {
            "gen": gen,
            "detail": cfg.detail,
            "nmsg": cfg.nmsg})
        pak.who = dest
        resp = conn.ping_pong(pak, tmo)

        # Failure
        if resp is None:
            time.sleep(pong.WAITNET)
            continue

        # Nothing happened