Browse Source

improve(plugin): add openExternalLink api

charlie 4 years ago
parent
commit
ac5d4b4508
3 changed files with 8 additions and 2 deletions
  1. 1 1
      libs/package.json
  2. 1 0
      libs/src/LSPlugin.ts
  3. 6 1
      src/main/logseq/api.cljs

+ 1 - 1
libs/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@logseq/libs",
-  "version": "0.0.1-alpha.20",
+  "version": "0.0.1-alpha.21",
   "description": "Logseq SDK libraries",
   "main": "dist/lsplugin.user.js",
   "typings": "index.d.ts",

+ 1 - 0
libs/src/LSPlugin.ts

@@ -170,6 +170,7 @@ export interface IAppProxy {
   // native
   relaunch: () => Promise<void>
   quit: () => Promise<void>
+  openExternalLink: (url: string) => Promise<void>
 
   // graph
   getCurrentGraph: () => Promise<AppGraphInfo | null>

+ 6 - 1
src/main/logseq/api.cljs

@@ -67,7 +67,7 @@
   (fn []
     (when-let [repo (state/get-current-repo)]
       (when-not (= config/local-repo repo)
-        (bean/->js {:url repo
+        (bean/->js {:url  repo
                     :name (util/node-path.basename repo)
                     :path (config/get-repo-dir repo)})))))
 
@@ -162,6 +162,11 @@
   (fn []
     (ipc/ipc "quitApp")))
 
+(def ^:export open_external_link
+  (fn [url]
+    (when (re-find #"https?://" url)
+      (js/apis.openExternal url))))
+
 (def ^:export push_state
   (fn [^js k ^js params]
     (rfe/push-state