Skip to content

Commit

Permalink
improve(plugin): add editing apis & types
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 committed Jun 3, 2021
1 parent 166561d commit 06fa243
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
5 changes: 5 additions & 0 deletions libs/src/LSPlugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ interface IAppProxy {
getUserInfo: () => Promise<any>
getUserConfigs: () => Promise<AppUserConfigs>

// native
relaunch: () => Promise<void>
quit: () => Promise<void>

// router
pushState: (k: string, params?: {}) => void
replaceState: (k: string, params?: {}) => void
Expand All @@ -138,6 +142,7 @@ interface IEditorProxy {
checkEditing: () => Promise<BlockUUID | boolean>
insertAtEditingCursor: (content: string) => Promise<void>
restoreEditingCursor: () => Promise<void>
exitEditingMode: (selectBlock?: boolean) => Promise<void>
getEditingCursorPosition: () => Promise<BlockCursorPosition | null>
getCurrentPage: () => Promise<Partial<BlockEntity> | null>
getCurrentBlock: () => Promise<BlockEntity | null>
Expand Down
7 changes: 7 additions & 0 deletions src/electron/electron/handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@
(defmethod handle :getUserDefaultPlugins []
(get-ls-default-plugins))

(defmethod handle :relaunchApp []
(.relaunch app) (.quit app))

(defmethod handle :quitApp []
(.quit app))


(defmethod handle :default [args]
(println "Error: no ipc handler for: " (bean/->js args)))

Expand Down
28 changes: 22 additions & 6 deletions src/main/logseq/api.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@
(fn []
(bean/->js
(normalize-keyword-for-json
{:preferred-language (:preferred-language @state/state)
{:preferred-language (:preferred-language @state/state)
:preferred-theme-mode (:ui/theme @state/state)
:preferred-format (state/get-preferred-format)
:preferred-workflow (state/get-preferred-workflow)
:preferred-todo (state/get-preferred-todo)
:current-graph (state/get-current-repo)
:me (state/get-me)}))))
:preferred-format (state/get-preferred-format)
:preferred-workflow (state/get-preferred-workflow)
:preferred-todo (state/get-preferred-todo)
:current-graph (state/get-current-repo)
:me (state/get-me)}))))

(def ^:export show_themes
(fn []
Expand Down Expand Up @@ -144,6 +144,14 @@
pid cmd (assoc action 0 (keyword (first action)))))))

;; app
(def ^:export relaunch
(fn []
(ipc/ipc "relaunchApp")))

(def ^:export quit
(fn []
(ipc/ipc "quitApp")))

(def ^:export push_state
(fn [^js k ^js params]
(rfe/push-state
Expand All @@ -160,6 +168,14 @@
(if (state/get-edit-input-id)
(str (:block/uuid (state/get-edit-block))) false)))

(def ^:export exit_editing_mode
(fn [select?]
(when-let [block (state/get-edit-block)]
(if select?
(editor-handler/select-block! (:block/uuid block))
(state/clear-edit!)))
nil))

(def ^:export insert_at_editing_cursor
(fn [content]
(when-let [input-id (state/get-edit-input-id)]
Expand Down

0 comments on commit 06fa243

Please sign in to comment.