Skip to content

Commit

Permalink
feat: #319 PicGO图形化配置界面-挂载SyCmd,调整日志级别
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Feb 14, 2023
1 parent 65837fb commit 01f18b4
Show file tree
Hide file tree
Showing 7 changed files with 146,318 additions and 373 deletions.
3 changes: 2 additions & 1 deletion .env.production.local.example
@@ -1,5 +1,6 @@
# 是否开启info日志,true | false,建议生产环境设置为false
VITE_LOG_INFO_ENABLED=false
VITE_LOG_INFO_ENABLED=true
VITE_DEBUG_MODE=false

# 思源笔记授权api
# VITE_SIYUAN_API_URL=http://127.0.0.1:6806
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -44,7 +44,7 @@

Q1:使用此思源笔记挂件或者浏览器插件有什么注意事项吗?

A1:有。 **特别提示:各种使用模式请不要混合使用,使用其中一种即可。避免因为混用导致配置同步问题。**
A1:有。 **特别提示:【自定义 JS 片段】请不要和【挂件通用版】混合使用,使用其中一种即可。避免因为混用导致配置同步问题。** 浏览器插件无限制。

Q2:有哪些方式可以使用?具体步骤是什么?

Expand Down Expand Up @@ -87,6 +87,10 @@ import("/widgets/sy-post-publisher/lib/siyuanhook.js")

参考 [浏览器插件快速上手指南](https://docs.publish.terwer.space/docs/getting-started/#%E6%B5%8F%E8%A7%88%E5%99%A8%E6%8F%92%E4%BB%B6%E6%96%B9%E5%BC%8F%E4%BD%BF%E7%94%A8)

Q3: `siyuanhook.js` 新增挂载了哪些对象?在哪些场景挂载?目的是什么?

A3:SyPicgo、syp、terwer(仅新窗口)、SyCmd。仅在 `Electron` 环境(即思源笔记内部挂载)。浏览器插件和自部署模式无此功能。目的是为了扩展思源笔记的功能。

## 支持平台

- [x] [Hugo](https://gohugo.io/) <sup>推荐</sup>
Expand Down
25 changes: 24 additions & 1 deletion components/picgo/setting/PicgoPluginSetting.vue
Expand Up @@ -46,7 +46,30 @@

<script lang="ts" setup>
import picgoUtil from "~/utils/otherlib/picgoUtil"
import { LogFactory } from "~/utils/logUtil"
import { ElMessage } from "element-plus"
const logger = LogFactory.getLogger(
"components/picgo/setting/PicgoPluginSetting.vue"
)
// register events
picgoUtil.ipcRegisterEvent("pluginList", (evt, data) => {
logger.info("PicgoPluginSetting接收到pluginList事件,data=>", data)
const rawArgs = data.rawArgs
if (rawArgs.success) {
// const list = rawArgs.list
// pluginList.value = list
// pluginNameList.value = list.map(item => item.fullName)
logger.info("插件已经成功安装.")
} else {
ElMessage.error(rawArgs.error)
}
})
// handles
function goAwesomeList() {
window.open("https://github.com/PicGo/Awesome-PicGo")
}
Expand Down
13 changes: 10 additions & 3 deletions utils/otherlib/shellUtil.js → public/lib/cmd/scriptUtil.js
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Terwer . All rights reserved.
* Copyright (c) 2022-2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@ import { isInSiyuanNewWinBrowser } from "~/utils/otherlib/siyuanBrowserUtil"
const { spawn } = isInSiyuanNewWinBrowser() ? require("child_process") : ""
const process = isInSiyuanNewWinBrowser() ? require("process") : ""

function cmd(...command) {
async function cmd(...command) {
let p = spawn(command[0], command.slice(1))
return new Promise((resolve, reject) => {
p.stdout.on("data", (x) => {
Expand All @@ -52,9 +52,16 @@ function cmd(...command) {
* @param shell
* @returns {Promise<undefined>}
*/
export async function execShellCmd(shell) {
async function execShellCmd(shell) {
console.log("exec shell=>", shell)
const ret = await cmd("bash", "-c", shell)
console.log("exec finished=>", ret)
return ret
}

const scriptUtil = {
cmd,
execShellCmd,
}

export default scriptUtil
146,597 changes: 146,230 additions & 367 deletions public/lib/picgo/syPicgo.js

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions public/lib/siyuanhook.js
Expand Up @@ -249,6 +249,26 @@ const initMethods = {
syWin.SyPicgo = syPicgo
console.log("syPicgo=>", syPicgo)
},

initCmder: () => {
const syWin = getSiyuanWindow()
const dataDir = getSiyuanDataDir()

// 防止重复挂载
if (syWin.SyCmd) {
console.warn("SyCmd已挂载,忽略", entryName)
return
}

// 挂载SyCmd到window
const syCmd = requireLib(
entryName,
`${dataDir}/widgets/sy-post-publisher/lib/cmd/scriptUtil.js`,
"sy-cmd"
).default
syWin.SyCmd = syCmd
console.log("syCmd=>", syCmd)
},
}

// iframe挂件
Expand All @@ -267,6 +287,9 @@ const initIframeWidaget = () => {

// 初始化PicGO配置
initMethods.initPicgoExtension("iframe挂件")

// 初始化SyCmd配置
initMethods.initCmder("iframe挂件")
}

// 新窗口打开
Expand All @@ -279,6 +302,9 @@ const initSiyuanNewWin = () => {

// 初始化PicGO配置
initMethods.initPicgoExtension("思源笔记新窗口")

// 初始化SyCmd配置
initMethods.initCmder("思源笔记新窗口")
}

// js片段
Expand All @@ -297,6 +323,9 @@ const initJsCode = () => {

// 初始化PicGO配置
initMethods.initPicgoExtension("自定义js片段")

// 初始化SyCmd配置
initMethods.initCmder("自定义js片段")
}

// init
Expand Down
18 changes: 18 additions & 0 deletions utils/otherlib/picgoUtil.js
Expand Up @@ -419,6 +419,8 @@ const getPicgoCfgFile = (filename) => {
*
* @param channel 频道
* @param args 参数
* @author terwer
* @since 0.7.0
*/
const ipcHandleEvent = (channel, args = {}) => {
const syWin = siyuanBrowserUtil.getSiyuanWindow()
Expand All @@ -427,6 +429,21 @@ const ipcHandleEvent = (channel, args = {}) => {
syPicgo.ipcMethods.handleEvent(channel, args)
}

/**
* 统一注册消息的入口
*
* @param channel 频道
* @param data 数据
* @author terwer
* @since 0.7.0
*/
const ipcRegisterEvent = (channel, data = {}) => {
const syWin = siyuanBrowserUtil.getSiyuanWindow()
const syPicgo = syWin?.SyPicgo

syPicgo.ipcMethods.registerEvent(channel, data)
}

/**
* PicGO相关操作统一访问入口
*/
Expand Down Expand Up @@ -458,5 +475,6 @@ const picgoUtil = {

// Ipc
ipcHandleEvent,
ipcRegisterEvent,
}
export default picgoUtil

0 comments on commit 01f18b4

Please sign in to comment.