Browse Source

improve(plugin): add get app config api

charlie 4 years ago
parent
commit
e57d382d3c
2 changed files with 27 additions and 1 deletions
  1. 16 1
      libs/src/LSPlugin.d.ts
  2. 11 0
      src/main/api.cljs

+ 16 - 1
libs/src/LSPlugin.d.ts

@@ -68,6 +68,14 @@ type BlockUUID = string
 
 type IEntityID = { id: BlockID }
 
+interface AppConfigs {
+  preferredFormat: 'markdown' | 'org'
+  preferredLanguage: string
+  preferredWorkflow: string
+
+  [key: string]: any
+}
+
 interface BlockEntity {
   id: number // db id
   uuid: string
@@ -94,11 +102,18 @@ type SlashCommandActionTag = 'editor/input' | 'editor/hook' | 'editor/clear-curr
 type SlashCommandAction = [SlashCommandActionTag, ...args: any]
 
 interface IAppProxy {
+  getUserState: () => Promise<any>
+  getAppConfigs: () => Promise<AppConfigs>
+
+  // router
   pushState: (k: string, params?: {}) => void
   replaceState: (k: string, params?: {}) => void
-  getUserState: () => Promise<any>
+
+  // ui
   showMsg: (content: string, status?: 'success' | 'warning' | string) => void
   setZoomFactor: (factor: number) => void
+
+  // events
   onThemeModeChanged: IUserHook
   onPageFileMounted: IUserSlotHook
   onBlockRendererMounted: IUserSlotHook

+ 11 - 0
src/main/api.cljs

@@ -43,6 +43,17 @@
         (js/console.error "[parse hiccup error]" e) input))))
 
 ;; base
+(def ^:export get_app_configs
+  (fn []
+    (bean/->js
+      (normalize-keyword-for-json
+        {:preferred-language (:preferred-language @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)}))))
+
 (def ^:export show_themes
   (fn []
     (plugins/open-select-theme!)))