[CHANGED] updated mojo.el to 0.9.4 - auto emulator launching.

This commit is contained in:
Sami Samhuri 2009-11-22 22:24:25 -08:00
parent ca1548afa4
commit 11da9c42ce

View file

@ -1,6 +1,6 @@
;;; mojo.el --- Interactive functions to aid the development of webOS apps ;;; mojo.el --- Interactive functions to aid the development of webOS apps
;; 2009-11-21 22:24:51 ;; 2009-11-22 22:23:26
(defconst mojo-version "0.9.3") (defconst mojo-version "0.9.4")
(require 'json) (require 'json)
@ -117,6 +117,12 @@ ideas. Send me a pull request on github if you hack on mojo.el.")
;; CHANGELOG ;; CHANGELOG
;; ========= ;; =========
;; ;;
;; sjs 2009-11-22
;; v 0.9.4 launch emulator if needed
;;
;; - Commands that use the emulator launch it if necessary and wait till
;; it is fully booted before running commands.
;;
;; sjs 2009-11-21 ;; sjs 2009-11-21
;; v 0.9.3 (one more bug fix for today) ;; v 0.9.3 (one more bug fix for today)
;; ;;
@ -236,7 +242,8 @@ NAME is the name of the scene."
(defun mojo-emulate () (defun mojo-emulate ()
"Launch the palm emulator." "Launch the palm emulator."
(interactive) (interactive)
(mojo-cmd "palm-emulator" nil)) (unless (mojo-emulator-running-p)
(mojo-cmd "palm-emulator" nil)))
;;* interactive ;;* interactive
(defun mojo-package () (defun mojo-package ()
@ -249,6 +256,7 @@ NAME is the name of the scene."
(defun mojo-install () (defun mojo-install ()
"Install the package named by `MOJO-PACKAGE-FILENAME'. The emulator needs to be running." "Install the package named by `MOJO-PACKAGE-FILENAME'. The emulator needs to be running."
(interactive) (interactive)
(mojo-ensure-emulator-is-running)
(mojo-cmd-with-target "palm-install" (list (expand-file-name (mojo-read-package-filename)))) (mojo-cmd-with-target "palm-install" (list (expand-file-name (mojo-read-package-filename))))
(mojo-invalidate-app-cache)) (mojo-invalidate-app-cache))
@ -256,31 +264,50 @@ NAME is the name of the scene."
(defun mojo-list () (defun mojo-list ()
"List all installed packages." "List all installed packages."
(interactive) (interactive)
(mojo-ensure-emulator-is-running)
(mojo-cmd-with-target "palm-install" (list "--list"))) (mojo-cmd-with-target "palm-install" (list "--list")))
;;* interactive ;;* interactive
(defun mojo-delete () (defun mojo-delete ()
"Remove the current application using `MOJO-APP-ID'." "Remove the current application using `MOJO-APP-ID'."
(interactive) (interactive)
(mojo-ensure-emulator-is-running)
(mojo-cmd-with-target "palm-install" (list "-r" (mojo-read-app-id))) (mojo-cmd-with-target "palm-install" (list "-r" (mojo-read-app-id)))
(mojo-invalidate-app-cache)) (mojo-invalidate-app-cache))
;;* interactive ;;* interactive
(defun mojo-launch () (defun mojo-ensure-emulator-is-running ()
"Launch the current application in an emulator." "Launch the current application, and the emulator if necessary."
(interactive) (interactive)
(if (string= "tcp" *mojo-target*)
(progn
(when (not (mojo-emulator-running-p))
(mojo-emulate)
(print "Launching the emulator, this will take a minute..."))
(while (not (mojo-emulator-responsive-p))
(sleep-for 3))
(print "Emulator has booted!"))
(print "Connect your device if necessary.")))
;;* interactive
(defun mojo-launch ()
"Launch the current application in the emulator."
(interactive)
(mojo-ensure-emulator-is-running)
(mojo-cmd-with-target "palm-launch" (list (mojo-read-app-id)))) (mojo-cmd-with-target "palm-launch" (list (mojo-read-app-id))))
;;* interactive ;;* interactive
(defun mojo-close () (defun mojo-close ()
"Close launched application." "Close launched application."
(interactive) (interactive)
(mojo-ensure-emulator-is-running)
(mojo-cmd-with-target "palm-launch" (list "-c" (mojo-read-app-id)))) (mojo-cmd-with-target "palm-launch" (list "-c" (mojo-read-app-id))))
;;* launch interactive ;;* launch interactive
(defun mojo-inspect () (defun mojo-inspect ()
"Run the DOM inspector on the current application." "Run the DOM inspector on the current application."
(interactive) (interactive)
(mojo-ensure-emulator-is-running)
(mojo-cmd-with-target "palm-launch" (list "-i" (mojo-read-app-id)))) (mojo-cmd-with-target "palm-launch" (list "-i" (mojo-read-app-id))))
;;* emulator interactive ;;* emulator interactive
@ -299,6 +326,7 @@ NAME is the name of the scene."
"Package, install, and launch the current application for inspection." "Package, install, and launch the current application for inspection."
(interactive) (interactive)
(mojo-package) (mojo-package)
(mojo-ensure-emulator-is-running)
(mojo-cmd-with-target "palm-install" (list (expand-file-name (mojo-package-filename)))) (mojo-cmd-with-target "palm-install" (list (expand-file-name (mojo-package-filename))))
(mojo-cmd-with-target "palm-launch" (list "-i" (mojo-app-id)))) (mojo-cmd-with-target "palm-launch" (list "-i" (mojo-app-id))))
@ -307,6 +335,7 @@ NAME is the name of the scene."
"Package, install, and launch the current application." "Package, install, and launch the current application."
(interactive) (interactive)
(mojo-package) (mojo-package)
(mojo-ensure-emulator-is-running)
(mojo-cmd-with-target "palm-install" (list (expand-file-name (mojo-package-filename)))) (mojo-cmd-with-target "palm-install" (list (expand-file-name (mojo-package-filename))))
(mojo-cmd-with-target "palm-launch" (list (mojo-app-id)))) (mojo-cmd-with-target "palm-launch" (list (mojo-app-id))))
@ -484,6 +513,7 @@ The app id is stored in *mojo-app-id* unless it was blank."
(defun mojo-fetch-app-list () (defun mojo-fetch-app-list ()
"Fetch a fresh list of all applications." "Fetch a fresh list of all applications."
(mojo-ensure-emulator-is-running)
(let* ((raw-list (nthcdr 7 (split-string (mojo-cmd-to-string "palm-install" (list "--list"))))) (let* ((raw-list (nthcdr 7 (split-string (mojo-cmd-to-string "palm-install" (list "--list")))))
(apps (list)) (apps (list))
(appname-regex "^[^0-9][^.]+\\(\\.[^.]+\\)+$") (appname-regex "^[^0-9][^.]+\\(\\.[^.]+\\)+$")
@ -541,6 +571,17 @@ Sets `*mojo-target*' to \"usb\"."
Sets `*mojo-target*' to \"tcp\"." Sets `*mojo-target*' to \"tcp\"."
(setq *mojo-target* "tcp")) (setq *mojo-target* "tcp"))
(defun mojo-emulator-running-p ()
"Determine if the webOS emulator is running or not.
This command only works on Unix-like systems."
(= 0 (shell-command "ps x | fgrep 'Palm SDK' | fgrep -v fgrep >/dev/null 2>&1")))
(defun mojo-emulator-responsive-p ()
"Determine if the webOS emulator is able to respond to commands yet
(i.e. if it's done booting)."
(= 0 (shell-command "palm-install -d tcp --list >/dev/null 2>&1")))
(defun mojo-path-to-cmd (cmd) (defun mojo-path-to-cmd (cmd)
"Return the absolute path to a Mojo SDK command line program." "Return the absolute path to a Mojo SDK command line program."
(case system-type (case system-type