improve(plugin): add editing apis & types

pull/2085/head
charlie 2021-06-03 19:22:51 +08:00
parent 166561d98f
commit 06fa2434a6
3 changed files with 34 additions and 6 deletions

View File

@ -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
@ -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>

View File

@ -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)))

View File

@ -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 []
@ -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
@ -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)]