Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Online check update in OM-Sharp #61

Open
charlesneimog opened this issue Apr 24, 2022 · 1 comment
Open

Online check update in OM-Sharp #61

charlesneimog opened this issue Apr 24, 2022 · 1 comment

Comments

@charlesneimog
Copy link

Hi Jean,

I'd like to suggest one more thing!

Could be possible to add a way to check the actual version of om-sharp. I am seeing a lot of people using old versions (??). I think that is because they do not use Github a lot.

Search on the internet I saw two ways to do that, the first one is using curl and uploading a file text in Github repo. The code would be something like this:

(let* (
      (tmpfile (om::tmpfile "om-sharp-version.txt"))
      (cmd-command
            #+windows(oa::om-command-line (format nil "curl https://raw.githubusercontent.com/charlesneimog/OM-CKN/master/resources/om-sharp-version.lisp --ssl-no-revoke --output  ~d" (namestring tmpfile)) nil)
            #+mac(oa::om-command-line (format nil "curl https://raw.githubusercontent.com/charlesneimog/OM-CKN/master/resources/om-sharp-version.lisp -L --output ~d" (namestring tmpfile)) nil)
            #+linux(oa::om-command-line (format nil "curl https://raw.githubusercontent.com/charlesneimog/OM-CKN/master/resources/om-sharp-version.lisp -L --output ~d" (namestring tmpfile)) nil)))
      (eval (read-from-string (car (uiop:read-file-lines tmpfile))))
      (if (> *actual-version-of-om-sharp* (read-from-string (format nil "~d.~d" CL-USER::*version-major* CL-USER::*version-minor*)))
          (let* (
                (update? (om::om-y-or-n-dialog (format nil "OM-SHARP has been UPDATED to version ~d. Want to update now?" *actual-version-of-om-sharp*))))
                (if update?
                    (let* ()
                          (hqn-web:browse "https://github.com/cac-t-u-s/om-sharp/releases/latest")))))
      (alexandria::delete-file tmpfile))

One second way will be use this code more beautiful and elegant without curl, just LispWorks functions!

(with-open-stream (http (comm:open-tcp-stream
                         "raw.githubusercontent.com" 443
                         :ssl-ctx t))
  (format http "GET charlesneimog/OM-CKN/master/resources/om-sharp-version.lisp HTTP/1.1~%Host: raw.githubusercontent.com~%~%"
               (code-char 13) (code-char 10)
               (code-char 13) (code-char 10))
  (force-output http)
  (write-string "Check Update for OM-Sharp...")
  (loop :for ch = (read-char-no-hang http nil :eof)
        :until ch
        :do (write-char #\.)
           (sleep 0.25)
        :finally (unless (eq ch :eof)
                  (unread-char ch http)))
  (terpri)
  (loop :for line := (read-line http nil nil)
        :do (om::om-print line "LINE ::::")
        :while line
        :do (x-append line nil)
        :finally (close http)))

But I am not sure how to close the stream (you probably must know!). You will see that the last print of LINE::: something is the (defparameter *actual-version-of-om-sharp* 1.7) from github than I have no more prints but the evaluation do not stop :). This is from reddit from the user tdrhq.

All can be used inside OM without any adaption of an external library that already is on OM-Sharp.

I think that this could help people to always have the last version of OM-Sharp which normally have fewer bugs, etc...

It will be great to use this with libraries too!!!

The file that I am using in https://github.com/charlesneimog/OM-CKN/blob/master/resources/om-sharp-version.lisp.

@charlesneimog
Copy link
Author

charlesneimog commented Apr 24, 2022

This work without curl.

NOTE: The file om-sharp-version is with 1.7 so it will tell that have update in 1.6.

;; ========================================================================

(defun check-update()

      (with-open-stream 
            (http (comm:open-tcp-stream 
                    "raw.githubusercontent.com" 443
                    :ssl-ctx t
                    :element-type '(unsigned-byte 8)))
            (write-sequence (format 
                        http "GET charlesneimog/OM-CKN/master/resources/om-sharp-version.lisp HTTP/1.1~%Host: raw.githubusercontent.com~%~%" 
                        (code-char 13) (code-char 10)
                        (code-char 13) (code-char 10)) http)
      (force-output http)

      (ignore-errors (loop :for line := (read-line http nil)
                           :while line 
                           :do (setf *om-sharp-last-update* line)))
      (close http)))

;; ========================================================================


(setf *actual-version-of-om-sharp* 0)
(setf *process-of-update* (mp:process-run-function "Check Update for OM-Sharp" () (lambda () (check-update))))
(sleep 2)
(mp:process-terminate *process-of-update*)
(eval (read-from-string *om-sharp-last-update* "OM-Sharp Last Version"))

(if (> *actual-version-of-om-sharp* (read-from-string (format nil "~d.~d" CL-USER::*version-major* CL-USER::*version-minor*)))
           (let* (
                 (update? (om::om-y-or-n-dialog (format nil "OM-SHARP has been UPDATED to version ~d. Want to update now?" *actual-version-of-om-sharp*))))
                 (if update?
                     (let* ()
                           (hqn-web:browse "https://github.com/cac-t-u-s/om-sharp/releases/latest")))))

      

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant