Skip to content

Commit

Permalink
v0.6.1: client-side IPC; window manager moved from inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed Sep 15, 2017
1 parent 7b38f0c commit a6038ee
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 38 deletions.
20 changes: 2 additions & 18 deletions CHANGELOG.md
@@ -1,24 +1,8 @@
# Change Log
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).

## [Unreleased]
### Changed
- Add a new arity to `make-widget-async` to provide a different widget shape.

## [0.1.1] - 2017-09-15
## [0.6.1] - 2017-09-15
### Changed
- Documentation on how to make the widgets.

### Removed
- `make-widget-sync` - we're all async, all the time.

### Fixed
- Fixed widget maker to keep working when daylight savings switches over.

## 0.1.0 - 2017-09-15
### Added
- Files from the new template.
- Widget maker public API - `make-widget-sync`.
- IPC and window manager extracted from inspect

[Unreleased]: https://github.com/your-name/systems-toolbox-electron/compare/0.1.1...HEAD
[0.1.1]: https://github.com/your-name/systems-toolbox-electron/compare/0.1.0...0.1.1
7 changes: 3 additions & 4 deletions project.clj
@@ -1,10 +1,9 @@
(defproject matthiasn/systems-toolbox-electron "0.6.1"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:description "Building blocks for ClojureScript systems on top of Electron"
:url "https://github.com/matthiasn/systems-toolbox-electron"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[com.taoensso/timbre "4.10.0"]
[matthiasn/systems-toolbox "0.6.15"]
[org.clojure/clojure "1.9.0-alpha19"]
[org.clojure/clojurescript "1.9.908"]]
:dev-dependencies [])
[org.clojure/clojurescript "1.9.908"]])
2 changes: 1 addition & 1 deletion src/matthiasn/systems_toolbox_electron/ipc_main.cljs
Expand Up @@ -12,7 +12,7 @@
msg-type (first parsed)
{:keys [msg-payload msg-meta]} (second parsed)
msg (with-meta [msg-type msg-payload] msg-meta)]
(info "IPC relay:" (with-out-str (pp/pprint parsed)))
(debug "IPC relay:" msg-type)
(put-fn msg)))]
(.on ipcMain "relay" relay)
{:state state}))
Expand Down
11 changes: 8 additions & 3 deletions src/matthiasn/systems_toolbox_electron/ipc_renderer.cljs
Expand Up @@ -11,14 +11,19 @@
{:keys [msg-payload msg-meta]} (second parsed)
msg (with-meta [msg-type msg-payload] msg-meta)]
(debug "IPC received:" (str msg-type))

(put-fn msg)))]
(put-fn msg)))
id-handler (fn [ev window-id]
(info "IPC: window-id" window-id)
(swap! state assoc-in [:window-id] window-id))]
(.on ipcRenderer "relay" relay)
(.on ipcRenderer "window-id" id-handler)
(info "Starting IPC Component")
{:state state}))

(defn relay-msg [{:keys [current-state msg-type msg-meta msg-payload]}]
(let [serializable [msg-type {:msg-payload msg-payload :msg-meta msg-meta}]]
(let [msg-meta (assoc-in msg-meta [:window-id] (:window-id current-state))
serializable [msg-type {:msg-payload msg-payload
:msg-meta msg-meta}]]
(debug "Relay to MAIN:" (str msg-type) (str msg-payload))
(.send ipcRenderer "relay" (pr-str serializable)))
{})
Expand Down
26 changes: 14 additions & 12 deletions src/matthiasn/systems_toolbox_electron/window_manager.cljs
@@ -1,5 +1,5 @@
(ns matthiasn.systems-toolbox-electron.window-manager
(:require [taoensso.timbre :as timbre :refer-macros [info debug]]
(:require [taoensso.timbre :as timbre :refer-macros [info debug warn]]
[electron :refer [BrowserWindow]]
[matthiasn.systems-toolbox.component :as stc]))

Expand Down Expand Up @@ -32,7 +32,7 @@
ready (fn [_]
(info "ready" window-id)
(show)
(.send (.-webContents window) "window-id" window-id))]
(.send (.-webContents window) "window-id" (str window-id)))]
(info "Opening new window" url)
(.on window "focus" #(js/setTimeout focus 10))
(.once window "ready-to-show" ready)
Expand All @@ -55,7 +55,7 @@
web-contents (when window (.-webContents window))
serializable [msg-type {:msg-payload msg-payload :msg-meta msg-meta}]]
(when web-contents
(info "Relaying" msg-type window-id)
(debug "Relaying" msg-type window-id)
(.send web-contents "relay" (pr-str serializable))))))
{})

Expand All @@ -65,14 +65,16 @@
(.openDevTools (.-webContents active-window)))
{})

(defn close-window [{:keys [current-state]}]
(if-let [active-window (active-window current-state)]
(let [active (:active current-state)
new-state (update-in current-state [:windows] dissoc active)]
(info "Closing:" (:active current-state))
(.close active-window)
{:new-state new-state})
{}))
(defn close-window [{:keys [current-state msg-meta]}]
(let [window-id (or (:window-id msg-meta)
(:active current-state))]
(if-let [window (get-in current-state [:windows window-id])]
(let [new-state (update-in current-state [:windows] dissoc window-id)]
(info "Closing:" window-id window)
(.close window)
{:new-state new-state})
(do (warn "WM: no such window" window-id)
{}))))

(defn activate [{:keys [current-state]}]
(info "Activate APP")
Expand All @@ -82,7 +84,7 @@
(defn cmp-map [cmp-id relay-types app-path]
(let [relay-map (zipmap relay-types (repeat relay-msg))]
{:cmp-id cmp-id
:state-fn (fn [put-fn] {:state (atom {:app-path app-path})})
:state-fn (fn [put-fn] {:state (atom {:app-path app-path})})
:handler-map (merge relay-map
{:window/new new-window
:window/activate activate
Expand Down

0 comments on commit a6038ee

Please sign in to comment.