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

Show notifications about fetch library issues #7868

Merged
merged 1 commit into from Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion editor/src/clj/editor/app_view.clj
Expand Up @@ -2481,7 +2481,7 @@ If you do not specifically require different script states, consider changing th
render-install-progress! (make-render-task-progress :resource-sync)]
(render-install-progress! (progress/make "Installing updated libraries..."))
(ui/run-later
(workspace/install-validated-libraries! workspace library-uris lib-states)
(workspace/install-validated-libraries! workspace lib-states)
(disk/async-reload! render-install-progress! workspace [] changes-view
(fn [success]
(when success
Expand Down
19 changes: 1 addition & 18 deletions editor/src/clj/editor/boot_open_project.clj
Expand Up @@ -14,7 +14,6 @@

(ns editor.boot-open-project
(:require [cljfx.fx.v-box :as fx.v-box]
[clojure.string :as string]
[dynamo.graph :as g]
[editor.app-view :as app-view]
[editor.asset-browser :as asset-browser]
Expand Down Expand Up @@ -384,20 +383,6 @@
(ui/run-later (slog/smoke-log "stage-loaded"))
root))

(defn- show-missing-dependencies-alert! [dependencies]
(dialogs/make-info-dialog
{:title "Missing Dependencies"
:size :large
:icon :icon/triangle-error
:header "There are missing dependencies"
:content (string/join "\n" (concat ["The following dependencies are missing:"
""]
(map dialogs/indent-with-bullet
(sort-by str dependencies))
[""
"The project might not work without them."
"To download, connect to the internet and choose Fetch Libraries from the Project menu."]))}))

(defn open-project!
[^File game-project-file prefs render-progress! updater newly-created?]
(let [project-path (.getPath (.getParentFile (.getAbsoluteFile game-project-file)))
Expand All @@ -409,8 +394,6 @@
project (project/open-project! *project-graph* extensions workspace game-project-res render-progress!)]
(ui/run-now
(icons/initialize! workspace)
(load-stage! workspace project prefs updater newly-created?)
(when-let [missing-dependencies (not-empty (workspace/missing-dependencies workspace))]
(show-missing-dependencies-alert! missing-dependencies)))
(load-stage! workspace project prefs updater newly-created?))
(g/reset-undo! *project-graph*)
(log/info :message "project loaded")))
4 changes: 2 additions & 2 deletions editor/src/clj/editor/defold_project.clj
Expand Up @@ -948,8 +948,8 @@
;; Fetch+install libs if we have network, otherwise fallback to disk state
(if (workspace/dependencies-reachable? dependencies)
(->> (workspace/fetch-and-validate-libraries workspace-id dependencies (progress/nest-render-progress render-progress! @progress 4))
(workspace/install-validated-libraries! workspace-id dependencies))
(workspace/set-project-dependencies! workspace-id dependencies))
(workspace/install-validated-libraries! workspace-id))
(workspace/set-project-dependencies! workspace-id (library/current-library-state (workspace/project-path workspace-id) dependencies)))

(render-progress! (swap! progress progress/advance 4 "Syncing resources..."))
(workspace/resource-sync! workspace-id [] (progress/nest-render-progress render-progress! @progress))
Expand Down
10 changes: 0 additions & 10 deletions editor/src/clj/editor/engine.clj
Expand Up @@ -235,16 +235,6 @@
(let [unpack-dir (io/file project-directory "build" (:extender-platform engine-descriptor))]
(io/file unpack-dir (dmengine-filename (current-platform)))))

(defn copy-engine-executable! ^File [^File target-dmengine platform {:keys [^File dmengine ^File engine-archive] :as engine-descriptor}]
(assert (or dmengine engine-archive))
(cond
(some? dmengine)
(fs/copy-file! dmengine target-dmengine)

(some? engine-archive)
(unpack-dmengine! engine-archive (dmengine-filename platform) target-dmengine))
target-dmengine)

Comment on lines -238 to -247
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused.

(defn install-engine! ^File [^File project-directory {:keys [^File dmengine ^File engine-archive extender-platform] :as engine-descriptor}]
(assert (or dmengine engine-archive))
(cond
Expand Down
3 changes: 2 additions & 1 deletion editor/src/clj/editor/fs.clj
Expand Up @@ -427,7 +427,8 @@
Options:
:fail :silently will not throw an exception on failure, and instead return an empty vector.
:target :keep will not replace the target file if it exists.
:target :replace (default) will replace the target file if it exists."
:target :replace (default) will replace the target file if it exists.
Returns a vector of source+target pairs if successful"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source+target File pairs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes :)

([^File src ^File tgt]
(copy-file! src tgt {}))
([^File src ^File tgt opts]
Expand Down
5 changes: 3 additions & 2 deletions editor/src/clj/editor/library.clj
Expand Up @@ -183,8 +183,9 @@
(doseq [^File lib-file lib-files]
(fs/delete-file! lib-file {:fail :silently}))))

(defn- install-library! [project-directory {:keys [uri tag ^File new-file]}]
(fs/copy-file! new-file (library-file project-directory uri tag)))
(defn- install-library!
^File [project-directory {:keys [uri tag ^File new-file]}]
(second (first (fs/copy-file! new-file (library-file project-directory uri tag)))))

(defn- install-updated-library! [lib-state project-directory]
(merge lib-state
Expand Down
69 changes: 52 additions & 17 deletions editor/src/clj/editor/workspace.clj
Expand Up @@ -33,6 +33,8 @@ ordinary paths."
[editor.url :as url]
[editor.util :as util]
[internal.cache :as c]
[internal.util :as iutil]
[schema.core :as s]
[service.log :as log]
[util.coll :refer [pair]]
[util.digest :as digest])
Expand Down Expand Up @@ -401,25 +403,54 @@ ordinary paths."
(with-open [f (io/reader resource)]
(slurp f))))

(defn set-project-dependencies! [workspace library-uris]
(g/set-property! workspace :dependencies library-uris)
library-uris)
(defn- update-dependency-notifications! [workspace lib-states]
(let [{:keys [error missing]} (->> lib-states
(eduction
(keep (fn [{:keys [status file uri]}]
(cond
(= status :error) (pair :error uri)
(nil? file) (pair :missing uri)))))
(iutil/group-into {} [] key val))
notifications (notifications workspace)]
(if (pos? (count missing))
(notifications/show!
notifications
{:id ::dependencies-missing
:type :warning
:text (format "The following dependencies are missing:\n%s\nThe project might not work without them.\nTo download, connect to the internet and fetch libraries."
(string/join "\n" (map dialogs/indent-with-bullet missing)))
:actions [{:text "Fetch Libraries"
:on-action #(ui/execute-command
(ui/contexts (ui/main-scene))
:fetch-libraries
nil)}]})
(notifications/close! notifications ::dependencies-missing))
(if (pos? (count error))
(notifications/show!
notifications
{:id ::dependencies-error
:type :error
:text (format "Couldn't install following dependencies:\n%s"
(string/join "\n" (map dialogs/indent-with-bullet error)))
:actions [{:text "Open game.project"
:on-action #(ui/execute-command
(ui/contexts (ui/main-scene))
:open
{:resources [(find-resource workspace "/game.project")]})}]})
(notifications/close! notifications ::dependencies-error))))

(defn set-project-dependencies! [workspace lib-states]
(g/set-property! workspace :dependencies lib-states)
(update-dependency-notifications! workspace lib-states)
lib-states)

(defn dependencies [workspace]
(g/node-value workspace :dependencies))
(g/node-value workspace :dependency-uris))

(defn dependencies-reachable? [dependencies]
(let [hosts (into #{} (map url/strip-path) dependencies)]
(every? url/reachable? hosts)))

(defn missing-dependencies [workspace]
(let [project-directory (project-path workspace)
dependencies (g/node-value workspace :dependencies)]
(into #{}
(comp (remove :file)
(map :uri))
(library/current-library-state project-directory dependencies))))

(defn make-snapshot-info [workspace project-path dependencies snapshot-cache]
(let [snapshot-info (resource-watch/make-snapshot-info workspace project-path dependencies snapshot-cache)]
(assoc snapshot-info :map (resource-watch/make-resource-map (:snapshot snapshot-info)))))
Expand Down Expand Up @@ -713,9 +744,9 @@ ordinary paths."
(library/fetch-library-updates library/default-http-resolver render-fn)
(library/validate-updated-libraries)))

(defn install-validated-libraries! [workspace library-uris lib-states]
(set-project-dependencies! workspace library-uris)
(library/install-validated-libraries! (project-path workspace) lib-states))
(defn install-validated-libraries! [workspace lib-states]
(let [new-lib-states (library/install-validated-libraries! (project-path workspace) lib-states)]
(set-project-dependencies! workspace new-lib-states)))

(defn add-resource-listener! [workspace progress-span listener]
(swap! (g/node-value workspace :resource-listeners) conj [progress-span listener]))
Expand All @@ -729,11 +760,14 @@ ordinary paths."
(into [resource-listener-entry]
resource-listener-entries)))))

(g/deftype UriVec [URI])
(g/deftype Dependencies
[{:uri URI
(s/optional-key :file) File
s/Keyword s/Any}])

(g/defnode Workspace
(property root g/Str)
(property dependencies UriVec)
(property dependencies Dependencies)
(property opened-files g/Any (default (atom #{})))
(property resource-snapshot g/Any)
(property resource-listeners g/Any (default (atom [])))
Expand All @@ -748,6 +782,7 @@ ordinary paths."
(input code-preprocessors g/NodeID :cascade-delete)
(input notifications g/NodeID :cascade-delete)

(output dependency-uris g/Any (g/fnk [dependencies] (mapv :uri dependencies)))
(output resource-tree FileResource :cached produce-resource-tree)
(output resource-list g/Any :cached produce-resource-list)
(output resource-map g/Any :cached produce-resource-map))
Expand Down
2 changes: 1 addition & 1 deletion editor/test/integration/library_test.clj
Expand Up @@ -153,7 +153,7 @@
(defn- fetch-validate-install-libraries! [workspace library-uris render-fn]
(when (workspace/dependencies-reachable? library-uris)
(->> (workspace/fetch-and-validate-libraries workspace library-uris render-fn)
(workspace/install-validated-libraries! workspace library-uris))
(workspace/install-validated-libraries! workspace))
(workspace/resource-sync! workspace)))

(deftest fetch-libraries
Expand Down
8 changes: 4 additions & 4 deletions editor/test/integration/reload_test.clj
Expand Up @@ -545,7 +545,7 @@
(is (= initial-graph-nodes (graph-nodes project)))

;; actual test
(workspace/set-project-dependencies! workspace [imagelib1-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib1-uri}])
(let [images-dir-resource (workspace/find-resource workspace "/images")]
(asset-browser/rename images-dir-resource "graphics"))

Expand Down Expand Up @@ -587,7 +587,7 @@
(is (= (map g/override-original game_object>main-go-scripts)
[scripts>main]))

(workspace/set-project-dependencies! workspace [scriptlib-uri])
(workspace/set-project-dependencies! workspace [{:uri scriptlib-uri}])
(let [scripts-dir-resource (workspace/find-resource workspace "/scripts")]
(asset-browser/rename scripts-dir-resource "project_scripts"))

Expand Down Expand Up @@ -622,7 +622,7 @@
images>pow-resource (resource images>pow)
image>ball (project/get-resource-node project "/images/ball.png")
initial-graph-nodes (graph-nodes project)]
(workspace/set-project-dependencies! workspace [imagelib1-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib1-uri}])
(binding [dialogs/make-resolve-file-conflicts-dialog (fn [src-dest-pairs] :overwrite)]
(let [images-dir-resource (workspace/find-resource workspace "/images")]
(asset-browser/rename images-dir-resource "graphics")))
Expand Down Expand Up @@ -661,7 +661,7 @@
initial-graph-nodes (graph-nodes project)]
(is (= (map g/override-original game_object>main-scripts) [scripts>main]))

(workspace/set-project-dependencies! workspace [scriptlib-uri]) ; /scripts/main.script
(workspace/set-project-dependencies! workspace [{:uri scriptlib-uri}]) ; /scripts/main.script
(binding [dialogs/make-resolve-file-conflicts-dialog (fn [src-dest-pairs] :overwrite)]
(let [scripts-dir-resource (workspace/find-resource workspace "/scripts")]
(asset-browser/rename scripts-dir-resource "main")))
Expand Down
24 changes: 12 additions & 12 deletions editor/test/integration/resource_watch_test.clj
Expand Up @@ -86,39 +86,39 @@
(deftest only-load-specified-libraries
(with-clean-system
(let [[workspace project] (log/without-logging (setup world))]
(workspace/set-project-dependencies! workspace [imagelib1-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib1-uri}])
(workspace/resource-sync! workspace)
(is (= (workspace-resource-paths workspace) (set/union directory-resources imagelib1-resources)))
(workspace/set-project-dependencies! workspace [imagelib2-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib2-uri}])
(workspace/resource-sync! workspace)
(is (= (workspace-resource-paths workspace) (set/union directory-resources imagelib2-resources)))
(workspace/set-project-dependencies! workspace [scriptlib-uri])
(workspace/set-project-dependencies! workspace [{:uri scriptlib-uri}])
(workspace/resource-sync! workspace)
(is (= (workspace-resource-paths workspace) (set/union directory-resources scriptlib-resources)))
(workspace/set-project-dependencies! workspace [imagelib1-uri scriptlib-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib1-uri} {:uri scriptlib-uri}])
(workspace/resource-sync! workspace)
(is (= (workspace-resource-paths workspace) (set/union directory-resources imagelib1-resources scriptlib-resources))))))

(deftest skip-colliding-libraries
(with-clean-system
(let [[workspace project] (log/without-logging (setup world))]
(workspace/set-project-dependencies! workspace [imagelib1-uri imagelib2-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib1-uri} {:uri imagelib2-uri}])
(workspace/resource-sync! workspace)
(is (= (workspace-resource-paths workspace)
(clojure.set/union directory-resources imagelib1-resources))))))

(deftest skip-bad-lib-uris []
(with-clean-system
(let [[workspace projec†] (log/without-logging (setup world))]
(workspace/set-project-dependencies! workspace [imagelib1-uri bogus-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib1-uri} {:uri bogus-uri}])
(workspace/resource-sync! workspace)
(is (= (workspace-resource-paths workspace)
(clojure.set/union directory-resources imagelib1-resources))))))

(deftest resource-sync!-diff
(with-clean-system
(let [[workspace project] (log/without-logging (setup-scratch world))]
(workspace/set-project-dependencies! workspace [imagelib1-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib1-uri}])
(let [il1-diff (workspace/resource-sync! workspace)]
(is (= (resource-paths (:added il1-diff)) imagelib1-resources))
(is (empty? (:removed il1-diff)))
Expand All @@ -128,7 +128,7 @@
(is (empty? (:added remove-il1-diff)))
(is (= (resource-paths (:removed remove-il1-diff)) imagelib1-resources))
(is (empty? (:changed remove-il1-diff))))
(workspace/set-project-dependencies! workspace [imagelib1-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib1-uri}])
(workspace/resource-sync! workspace)
(let [project-directory (workspace/project-path workspace)]
;; this fakes having downloaded a different version of the library
Expand All @@ -146,12 +146,12 @@
(deftest exchange-of-zipresource-updates-corresponding-resource-node
(with-clean-system
(let [[workspace project] (log/without-logging (setup world))]
(workspace/set-project-dependencies! workspace [imagelib1-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib1-uri}])
(workspace/resource-sync! workspace)
(let [lib1-pow (project/get-resource-node project "/images/pow.png")
lib1-pow-resource (g/node-value lib1-pow :resource)]
(is (not (g/error? lib1-pow-resource)))
(workspace/set-project-dependencies! workspace [imagelib2-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib2-uri}])
(workspace/resource-sync! workspace)
(let [lib2-pow (project/get-resource-node project "/images/pow.png")
lib2-pow-resource (g/node-value lib2-pow :resource)]
Expand All @@ -162,11 +162,11 @@
(deftest delete-of-zipresource-marks-corresponding-resource-node-defective
(with-clean-system
(let [[workspace project] (log/without-logging (setup world))]
(workspace/set-project-dependencies! workspace [imagelib1-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib1-uri}])
(workspace/resource-sync! workspace)
(let [lib1-paddle (project/get-resource-node project "/images/paddle.png")]
(is (not (g/error? (g/node-value lib1-paddle :content))))
(workspace/set-project-dependencies! workspace [imagelib2-uri])
(workspace/set-project-dependencies! workspace [{:uri imagelib2-uri}])
(workspace/resource-sync! workspace)
(is (g/error? (g/node-value lib1-paddle :content))))))) ; removed, should emit errors

Expand Down
4 changes: 2 additions & 2 deletions editor/test/integration/test_util.clj
Expand Up @@ -180,7 +180,7 @@
(let [game-project-resource (workspace/find-resource workspace "/game.project")
dependencies (project/read-dependencies game-project-resource)]
(->> (workspace/fetch-and-validate-libraries workspace dependencies progress/null-render-progress!)
(workspace/install-validated-libraries! workspace dependencies))
(workspace/install-validated-libraries! workspace))
(workspace/resource-sync! workspace [] progress/null-render-progress!)))

(defn set-libraries! [workspace library-uris]
Expand All @@ -194,7 +194,7 @@
{:library-uris library-uris}))))
library-uris)]
(->> (workspace/fetch-and-validate-libraries workspace library-uris progress/null-render-progress!)
(workspace/install-validated-libraries! workspace library-uris))
(workspace/install-validated-libraries! workspace))
(workspace/resource-sync! workspace [] progress/null-render-progress!)))

(defn setup-project!
Expand Down