Skip to content

Commit

Permalink
v0.6.27: supporting for opening window at previous size and coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed Dec 26, 2018
1 parent 1877b25 commit f578f78
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).


## [0.6.27] - 2018-12-26
### Changed
- support for restoring window at the same size and position

## [0.6.26] - 2018-12-19
### Changed
- dependencies
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject matthiasn/systems-toolbox-electron "0.6.26"
(defproject matthiasn/systems-toolbox-electron "0.6.27"
:description "Building blocks for ClojureScript systems on top of Electron"
:url "https://github.com/matthiasn/systems-toolbox-electron"
:license {:name "Eclipse Public License"
Expand Down
25 changes: 14 additions & 11 deletions src/matthiasn/systems_toolbox_electron/window_manager.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
(t/write w serializable)))

(defn new-window [{:keys [current-state cmp-state msg-payload put-fn]}]
(let [{:keys [url width height window-id cached opts]} msg-payload]
(let [{:keys [url width height x y window-id cached opts]} msg-payload]
(if (get-in current-state [:windows window-id])
(do (info "WM: window id exists, not creating new one:" window-id) {})
(let [default-opts {:width (or width 1280)
:height (or height 800)
:show false
:webPreferences {:nodeIntegration true}}
window-opts (merge default-opts opts)
window-opts (merge default-opts (when (and x y) {:x x :y y}) opts)
load-new (fn [url]
(let [window (BrowserWindow. (clj->js window-opts))]
(info "WM load-new" url)
(info "WM load-new" url window-opts)
(.loadURL window url)
window))
spare (when cached (:spare current-state))
Expand All @@ -49,10 +49,7 @@
focus (fn [_]
(debug "Focused" window-id)
(swap! cmp-state assoc-in [:active] window-id))
blur (fn [_]
(debug "Blurred" window-id)
;(swap! cmp-state assoc-in [:active] nil)
)
blur (fn [_] (debug "Blurred" window-id))
close (fn [_]
(debug "Closed" window-id)
(swap! cmp-state assoc-in [:active] nil)
Expand All @@ -67,12 +64,18 @@
web-contents (.-webContents window)
handle-redirect (fn [ev url]
(.preventDefault ev)
(put-fn [:wm/open-external url]))]
(info "Opening new window" url window-id)
(put-fn [:wm/open-external url]))
resized-moved (fn [_]
(let [bounds (js->clj (.getContentBounds window)
:keywordize-keys true)]
(put-fn [:window/resized bounds])
(debug "resize" bounds)))]
(.on window "focus" #(js/setTimeout focus 10))
(.on window "resize" resized-moved)
(.on window "move" resized-moved)
(when cached (.on new-spare-wc "did-finish-load" new-spare-init))
(if spare
(do (info "WM using spare" spare)
(do (debug "WM using spare" spare)
(show)
(.send web-contents "window-id" (str window-id)))
(.on web-contents "did-finish-load" #(js/setTimeout show 10)))
Expand Down Expand Up @@ -105,7 +108,7 @@

(defn dev-tools [{:keys [current-state]}]
(when-let [active-window (active-window current-state)]
(info "Open dev-tools")
(debug "Open dev-tools")
(.openDevTools (.-webContents active-window)))
{})

Expand Down

0 comments on commit f578f78

Please sign in to comment.