Skip to content

Commit

Permalink
feat: #319 PicGO图形化配置界面-修复配置文件路径问题
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Feb 10, 2023
1 parent 0f18eda commit 359620a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 61 deletions.
24 changes: 16 additions & 8 deletions README.md
Expand Up @@ -23,30 +23,36 @@
<a title="Downloads" target="_blank" href="https://github.com/terwer/src-sy-post-publisher/releases"><img src="https://img.shields.io/github/downloads/terwer/src-sy-post-publisher/total.svg?label=extension-downloads&style=flat-square&color=blueviolet"></a>
<a title="Downloads" target="_blank" href="https://github.com/terwer/src-sy-post-publisher/releases"><img src="https://img.shields.io/github/downloads/terwer/sy-post-publisher/total.svg?label=widget-downloads&style=flat-square&color=blue"></a>

## v0.6.8 特性一览<sup>new</sup>
## v0.7.0 特性一览<sup>new</sup>

- 提供通用的集成接口,方便思源笔记主题集成本插件
- 重构数据存储方案,思源笔记内部使用 JSON 存储,解决多空间随机端口问题
### PicGO 相关

- 新增用户友好的 PicGO 图形化配置界面
- 优化 PicGO 配置,支持 PicGO 插件

### 系统配置相关

- 整合系统所有配置项,提供统一的配置入口

### 发布体验相关

## 快速上手

### 挂件版挂载菜单打开新窗口操作方式快速上手
### 挂件版挂载菜单打开新窗口操作方式快速上手 <sup>强烈推荐</sup> <sup>0.4.2+</sup>

首先在设置 - 集市 - 挂件 中下载 sy-post-publisher

点击设置 - 外观- 代码片段,代码片段加上下面的 `js` 片段,然后重启思源

```js
// 如果不喜欢这个菜单,直接去掉这个代码片段引用即可,去掉之后仍然可以通过挂件版通用方式使用
import("/widgets/sy-post-publisher/lib/siyuanhook.js")
```

点击按钮开始体验

![](https://img1.terwer.space/api/public/20221228-175950.jpeg)

详情请参考: [挂件模式用挂载菜单的方式使用](https://docs.publish.terwer.space/post/the-pendant-mode-is-used-in-the-method-of-mounting-menu-169wrw.html)<sup>
强烈推荐</sup> <sup>0.4.2+</sup>
详情请参考: [挂件模式用挂载菜单的方式使用](https://docs.publish.terwer.space/post/the-pendant-mode-is-used-in-the-method-of-mounting-menu-169wrw.html)

### 挂件版通用方式快速上手

Expand All @@ -58,7 +64,9 @@ import("/widgets/sy-post-publisher/lib/siyuanhook.js")

然后选择你需要的平台然后进行设置

点击发布即可
点击发布即可。

温馨提示:0.7.0+ 之后通过通用版使用会自动激活菜单。

### 浏览器插件快速上手

Expand Down
15 changes: 1 addition & 14 deletions public/lib/siyuan/silot.js
Expand Up @@ -36,22 +36,9 @@ const initSlot = () => {
showPreviousWidgetsSlot()

function DocumentShowPreviousWidget() {
var syWin = window
var openDoc = syWin.document.querySelectorAll(
var openDoc = window.document.querySelectorAll(
".layout-tab-container>.fn__flex-1.protyle:not(.fn__none)"
)
// 挂件需要用parent
if (openDoc.length === 0) {
syWin = parent.window
openDoc = syWin.document.querySelectorAll(
".layout-tab-container>.fn__flex-1.protyle:not(.fn__none)"
)
}
// console.log("openDoc=>", openDoc)

// ===============================
// 上面判断完成后使用syWin代替Window
// ===============================

var allDocumentTitleElement = []
for (let index = 0; index < openDoc.length; index++) {
Expand Down
66 changes: 28 additions & 38 deletions public/lib/siyuanhook.js
Expand Up @@ -101,29 +101,6 @@ export const getSiyuanDataDir = () => {
}
}

/**
* 获取跨平台的配置文件路径
*/
const getCrossPlatformAppDataFolder = () => {
const syWin = getSiyuanWindow()
const path = syWin.require("path")

let configFilePath
if (syWin.process.platform === "darwin") {
configFilePath = path.join(
syWin.process.env.HOME,
"/Library/Application Support"
)
} else if (syWin.process.platform === "win32") {
// Roaming包含在APPDATA中了
configFilePath = syWin.process.env.APPDATA
} else if (syWin.process.platform === "linux") {
configFilePath = syWin.process.env.HOME
}

return configFilePath
}

/**
* 引入依赖
*
Expand Down Expand Up @@ -232,6 +209,8 @@ const initMethods = {
initPicgoExtension: (entryName) => {
const syWin = getSiyuanWindow()
const dataDir = getSiyuanDataDir()
console.log("initPicgoExtension=>", dataDir)
console.log("syWin=>", syWin)

// 防止重复挂载
if (syWin.SyPicgo) {
Expand All @@ -247,25 +226,29 @@ const initMethods = {
).default

// PicGO存储到配置目录,便于后面插件
const path = syWin.require("path")
const fs = syWin.require("fs")
const appDataFolder = picgoExtension.getCrossPlatformAppDataFolder()
console.log("appDataFolder=>", appDataFolder)

// 配置文件初始化与数据迁移
const appDataFolder = getCrossPlatformAppDataFolder()
const picgo_cfg_067 = `${dataDir}/widgets/sy-post-publisher/lib/picgo/picgo.cfg.json`
const picgo_cfg_folder_070 = path.join(appDataFolder, "sy-picgo")
if (!fs.existsSync(picgo_cfg_folder_070)) {
fs.mkdirSync(picgo_cfg_folder_070)
}
const picgo_cfg_070 = path.join(picgo_cfg_folder_070, "picgo.cfg.json")
if (fs.existsSync(picgo_cfg_067) && !fs.existsSync(picgo_cfg_070)) {
console.warn("检测到旧的PicGO配置文件,启动迁移")
fs.copyFileSync(picgo_cfg_067, picgo_cfg_070)
}
const picgo_cfg_folder_070 = picgoExtension.joinPath(
appDataFolder,
"sy-picgo"
)
const picgo_cfg_070 = picgoExtension.joinPath(
picgo_cfg_folder_070,
"picgo.cfg.json"
)
picgoExtension.upgradeCfg(
picgo_cfg_067,
picgo_cfg_folder_070,
picgo_cfg_070
)
console.warn("PicGO配置文件初始化为=>", picgo_cfg_070)

// 初始化
picgoExtension.initPicgo(picgo_cfg_070)
const syPicgo = picgoExtension.initPicgo(picgo_cfg_070)
syWin.SyPicgo = syPicgo
console.log("syPicgo=>", syPicgo)
},
}

Expand Down Expand Up @@ -344,4 +327,11 @@ const init = () => {
}

// 统一的初始化入口
init()
try {
init()
} catch (e) {
console.warn(
"初始化siyuanhook失败,可能导致扩展功能无法使用,请知悉。错误信息如下",
e
)
}
6 changes: 5 additions & 1 deletion utils/otherlib/picgoUtil.js
Expand Up @@ -375,7 +375,11 @@ export const deleteUploaderConfig = (type, id) => {
*/
const getPicgoCfgPath = () => {
const syWin = siyuanBrowserUtil.getSiyuanWindow()
const picgo = syWin.SyPicgo.getPicgoObj()
const picgo = syWin?.SyPicgo?.getPicgoObj()

if (!picgo) {
return "[PicGO未挂载]"
}

const picgo_cfg_070 = picgo.configPath
return picgo_cfg_070
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Expand Up @@ -256,6 +256,7 @@ export default defineConfig(({ command, mode, ssrBuild }) => {
"stat",
"readFile",
"fs",
"path",
"@electron/remote",
"/lib/siyuanhook.js",
],
Expand Down

0 comments on commit 359620a

Please sign in to comment.