1
0
Fork 0

- [GUI] added button to refresh the gemlogs subcriptions.

This commit is contained in:
cage 2023-06-18 14:48:40 +02:00
parent 97fd09adf0
commit 7aa707bfb6
9 changed files with 90 additions and 49 deletions

View File

@ -210,4 +210,5 @@
(:shadowing-import-from :misc :random-elt :shuffle) (:shadowing-import-from :misc :random-elt :shuffle)
(:export (:export
:subscribe :subscribe
:refresh-subscription-low-level
:refresh)) :refresh))

View File

@ -63,10 +63,7 @@ This function return the 'post-title' substring."
(db:gemini-subscribe-url url title subtitle)) (db:gemini-subscribe-url url title subtitle))
t)))) t))))
(defun refresh (url) (defun refresh-subscription-low-level (url)
"Refresh gemlog entries that can be found at 'url'. The gemlog must
be subscribed before (see: 'gemini-subscription:subcribe'"
(handler-case
(when-let* ((data (slurp-gemini-url url)) (when-let* ((data (slurp-gemini-url url))
(page (text-utils:to-s data)) (page (text-utils:to-s data))
(parsed (parse-gemini-file page :initialize-parser t)) (parsed (parse-gemini-file page :initialize-parser t))
@ -76,14 +73,23 @@ be subscribed before (see: 'gemini-subscription:subcribe'"
(uri:host gemlog-iri) (uri:host gemlog-iri)
(uri:port gemlog-iri) (uri:port gemlog-iri)
(uri:path gemlog-iri) (uri:path gemlog-iri)
(uri:query gemlog-iri))))) (uri:query gemlog-iri))))
(new-posts-count 0))
(loop for link in links do (loop for link in links do
(when (not (db:find-gemlog-entry (to-s (target link)))) (when (not (db:find-gemlog-entry (to-s (target link))))
(incf new-posts-count)
(let ((date (link-post-timestamp (name link)))) (let ((date (link-post-timestamp (name link))))
(db:add-gemlog-entries (to-s gemlog-iri) (db:add-gemlog-entries (to-s gemlog-iri)
(target link) (target link)
(link-post-title (name link)) (link-post-title (name link))
date date
nil)))))) nil))))
new-posts-count)))
(defun refresh (url)
"Refresh gemlog entries that can be found at 'url'. The gemlog must
be subscribed before (see: 'gemini-subscription:subcribe'"
(handler-case
(refresh-subscription-low-level url)
(gemini-client:gemini-tofu-error (e) (gemini-client:gemini-tofu-error (e)
(ui:ask-input-on-tofu-error e (lambda () (refresh url)))))) (ui:ask-input-on-tofu-error e (lambda () (refresh url))))))

View File

@ -116,7 +116,7 @@
(resync-rows certificate-frame (all-rows)) (resync-rows certificate-frame (all-rows))
(gui:exit-from-toplevel (gui:master import-window))) (gui:exit-from-toplevel (gui:master import-window)))
(error (e) (error (e)
(client-main-window::notify-request-error e))))))) (gui-goodies:notify-request-error e)))))))
(defmethod initialize-instance :after ((object import-window) &key (certificate-frame nil) (defmethod initialize-instance :after ((object import-window) &key (certificate-frame nil)
&allow-other-keys) &allow-other-keys)

View File

@ -82,6 +82,15 @@
(let ((new-rows (all-rows))) (let ((new-rows (all-rows)))
(resync-rows gemlog-frame new-rows))))))) (resync-rows gemlog-frame new-rows)))))))
(defun refresh-gemlogs-clsr (gemlog-frame)
(lambda ()
(when (gui:children (gui-goodies:tree gemlog-frame) gui:+treeview-root+)
(ev:with-enqueued-process-and-unblock ()
(gui-goodies::with-notify-errors
(comm:make-request :gemini-gemlog-refresh-all-subscriptions 1)
(let ((new-rows (all-rows)))
(resync-rows gemlog-frame new-rows)))))))
(defun open-gemlog-clsr (main-window treeview-gemlogs) (defun open-gemlog-clsr (main-window treeview-gemlogs)
(lambda (e) (lambda (e)
(declare (ignore e)) (declare (ignore e))
@ -110,11 +119,17 @@
(unsubscribe-button (make-instance 'gui:button (unsubscribe-button (make-instance 'gui:button
:master buttons-frame :master buttons-frame
:image icons:*document-delete* :image icons:*document-delete*
:command (unsubscribe-gemlog-clsr table)))) :command (unsubscribe-gemlog-clsr table)))
(gui-goodies:attach-tooltips (unsubscribe-button (_ "unsubscribe from selected gemlog"))) (refresh-button (make-instance 'gui:button
:master buttons-frame
:image icons:*refresh*
:command (refresh-gemlogs-clsr table))))
(gui-goodies:attach-tooltips (unsubscribe-button (_ "unsubscribe from selected gemlog"))
(refresh-button (_ "refresh all subscription")))
(gui:grid table 0 0 :sticky :nwe) (gui:grid table 0 0 :sticky :nwe)
(gui:grid buttons-frame 1 0 :sticky :s) (gui:grid buttons-frame 1 0 :sticky :s)
(gui:grid unsubscribe-button 0 0 :sticky :s) (gui:grid unsubscribe-button 0 0 :sticky :s)
(gui:grid refresh-button 0 1 :sticky :s)
(gui:bind (gui:treeview (gui-goodies:tree table)) (gui:bind (gui:treeview (gui-goodies:tree table))
#$<<TreeviewSelect>>$ #$<<TreeviewSelect>>$
(open-gemlog-clsr main-window table))) (open-gemlog-clsr main-window table)))

View File

@ -133,3 +133,19 @@
(truncate (min (/ (gui:screen-width) 2 (truncate (min (/ (gui:screen-width) 2
(gui:font-measure gui:+tk-text-font+ "0")))) (gui:font-measure gui:+tk-text-font+ "0"))))
(truncate (/ (gui:screen-width) 2)))) (truncate (/ (gui:screen-width) 2))))
(defun notify-request-error (error)
(error-dialog gui-goodies:*toplevel* error))
(defmacro with-notify-errors (&body body)
`(handler-case
(progn ,@body)
(comm:rpc-error-response (e)
#+debug-mode (misc:dbg "backend comunication RPC error ~a" e)
(notify-request-error (format nil
(_ "~a: ~a")
(comm:code e)
(conditions:text e))))
(error (e)
#+debug-mode (misc:dbg "backend comunication error ~a" e)
(notify-request-error e))))

View File

@ -64,9 +64,6 @@
(defun find-streaming-stream-url () (defun find-streaming-stream-url ()
(find-db-stream-if (lambda (a) (eq (status a) +stream-status-streaming+)))) (find-db-stream-if (lambda (a) (eq (status a) +stream-status-streaming+))))
(defun notify-request-error (error)
(gui-goodies:error-dialog gui-goodies:*toplevel* error))
(defgeneric stop-stream-thread (object)) (defgeneric stop-stream-thread (object))
(defmethod stop-stream-thread ((object gemini-stream)) (defmethod stop-stream-thread ((object gemini-stream))
@ -89,26 +86,13 @@
(a:when-let ((stream-wrapper (find-streaming-stream-url))) (a:when-let ((stream-wrapper (find-streaming-stream-url)))
(stop-stream-thread stream-wrapper))) (stop-stream-thread stream-wrapper)))
(defmacro with-notify-errors (&body body)
`(handler-case
(progn ,@body)
(comm:rpc-error-response (e)
#+debug-mode (misc:dbg "backend comunication RPC error ~a" e)
(notify-request-error (format nil
(_ "~a: ~a")
(comm:code e)
(conditions:text e))))
(error (e)
#+debug-mode (misc:dbg "backend comunication error ~a" e)
(notify-request-error e))))
(defun enqueue-request-notify-error (method-name id &rest args) (defun enqueue-request-notify-error (method-name id &rest args)
(ev:with-enqueued-process-and-unblock () (ev:with-enqueued-process-and-unblock ()
(with-notify-errors (gui-goodies:with-notify-errors
(apply #'comm:make-request method-name id args)))) (apply #'comm:make-request method-name id args))))
(defun render-toc (main-window iri) (defun render-toc (main-window iri)
(with-notify-errors (gui-goodies:with-notify-errors
(toc-clear main-window) (toc-clear main-window)
(let* ((toc-max-width (gui-conf:config-toc-maximum-width)) (let* ((toc-max-width (gui-conf:config-toc-maximum-width))
(toc (comm:make-request :gemini-table-of-contents (toc (comm:make-request :gemini-table-of-contents
@ -141,7 +125,7 @@
status-completed)) status-completed))
(loop-fetch (&optional (last-lines-fetched-count 0)) (loop-fetch (&optional (last-lines-fetched-count 0))
(ev:with-enqueued-process-and-unblock () (ev:with-enqueued-process-and-unblock ()
(with-notify-errors (gui-goodies:with-notify-errors
(let* ((last-lines-fetched (comm:make-request :gemini-stream-parsed-line-slice (let* ((last-lines-fetched (comm:make-request :gemini-stream-parsed-line-slice
1 1
iri iri
@ -303,7 +287,7 @@
(lambda (hint) (lambda (hint)
(if (or (complete:expand-iri-as-local-path-p hint) (if (or (complete:expand-iri-as-local-path-p hint)
(> (length hint) 2)) (> (length hint) 2))
(with-notify-errors (gui-goodies:with-notify-errors
(let ((match-results (cev:enqueue-request-and-wait-results :complete-net-address (let ((match-results (cev:enqueue-request-and-wait-results :complete-net-address
1 1
ev:+maximum-event-priority+ ev:+maximum-event-priority+
@ -384,7 +368,7 @@
((or (gemini-client:header-temporary-failure-p status-code) ((or (gemini-client:header-temporary-failure-p status-code)
(gemini-client:header-permanent-failure-p status-code) (gemini-client:header-permanent-failure-p status-code)
(gemini-client:header-certificate-failure-p status-code)) (gemini-client:header-certificate-failure-p status-code))
(notify-request-error (format nil (gui-goodies:notify-request-error (format nil
"Error getting ~a (~a ~a)" "Error getting ~a (~a ~a)"
iri iri
status-code status-code
@ -807,7 +791,7 @@
((fs:directory-exists-p path) ((fs:directory-exists-p path)
(gui:choose-directory :initial-dir path :parent main-window :mustexist t)) (gui:choose-directory :initial-dir path :parent main-window :mustexist t))
(t (t
(notify-request-error (format nil (_ "No such file or directory: ~a") path))))) (gui-goodies:notify-request-error (format nil (_ "No such file or directory: ~a") path)))))
(defun render-gemtext-string (main-window parsed-lines &key (links-path-prefix "")) (defun render-gemtext-string (main-window parsed-lines &key (links-path-prefix ""))
(ev:with-enqueued-process-and-unblock () (ev:with-enqueued-process-and-unblock ()
@ -843,7 +827,7 @@
(t (t
(client-os-utils:open-resource-with-external-program main-window iri)))) (client-os-utils:open-resource-with-external-program main-window iri))))
(error (e) (error (e)
(notify-request-error e)))) (gui-goodies:notify-request-error e))))
(defun get-user-request-query (iri meta main-window &key (sensitive nil)) (defun get-user-request-query (iri meta main-window &key (sensitive nil))
(let* ((parsed-iri (iri:iri-parse iri)) (let* ((parsed-iri (iri:iri-parse iri))

View File

@ -46,3 +46,18 @@
subtitle subtitle
table))) table)))
(gemini-parse-string page))) (gemini-parse-string page)))
(defun gemini-gemlog-refresh-subscription (gemlog-url)
(list (cons "url" gemlog-url)
(cons "new-posts" (gemini-subscription:refresh-subscription-low-level gemlog-url))))
(defclass gemini-gemlog-subscriptions-refreshed (box) ())
(defmethod yason:encode ((object gemini-gemlog-subscriptions-refreshed) &optional (stream *standard-output*))
(encode-flat-array-of-plists (unbox object) stream))
(defun gemini-gemlog-refresh-all-subscriptions ()
(let ((all-subscribed-gemlogs (mapcar #'db:row-url (db:gemini-all-subscriptions))))
(loop for subscription in all-subscribed-gemlogs
collect
(gemini-gemlog-refresh-subscription subscription))))

View File

@ -121,6 +121,8 @@
(gen-rpc "gemini-gemlog-subscribe" 'gemini-gemlog-subscribe "iri" 0) (gen-rpc "gemini-gemlog-subscribe" 'gemini-gemlog-subscribe "iri" 0)
(gen-rpc "gemini-gemlog-subscribed-p" 'gemini-gemlog-subscribed-p "iri" 0) (gen-rpc "gemini-gemlog-subscribed-p" 'gemini-gemlog-subscribed-p "iri" 0)
(gen-rpc "gemini-gemlog-all-subscription" 'gemini-gemlog-all-subscription) (gen-rpc "gemini-gemlog-all-subscription" 'gemini-gemlog-all-subscription)
(gen-rpc "gemini-gemlog-refresh-all-subscriptions"
'gemini-gemlog-refresh-all-subscriptions)
(gen-rpc "gemini-gemlog-unsubscribe" 'gemini-gemlog-unsubscribe "iri" 0) (gen-rpc "gemini-gemlog-unsubscribe" 'gemini-gemlog-unsubscribe "iri" 0)
(gen-rpc "gemini-gemlog-entries" 'gemini-gemlog-entries (gen-rpc "gemini-gemlog-entries" 'gemini-gemlog-entries
"iri" 0 "iri" 0

View File

@ -3417,7 +3417,9 @@
:table-frame :table-frame
:tree :tree
:rows :rows
:quite-good-dialog-width)) :quite-good-dialog-width
:notify-request-error
:with-notify-errors))
(defpackage :client-menu-command (defpackage :client-menu-command
(:use (:use