Skip to content

Commit

Permalink
修复webdav被关闭的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ipuppet committed Jun 26, 2024
1 parent 1ca0f3a commit 97f364b
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 69 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"info": {
"name": "CAIO",
"version": "2.2.10",
"version": "2.2.11",
"author": "ipuppet",
"module": false
},
Expand Down
2 changes: 1 addition & 1 deletion dist/CAIO-en.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/CAIO-zh-Hans.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/CAIO.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class AppKernelBase extends Kernel {
return this.#storage
}

get isWebdavEnabled() {
if ($app.env === $env.widget) {
// 在小组件中不启用 WebDAV
return false
}
return this.kernel.setting.get("webdav.status")
}

initComponents() {
// Clips
this.clips = new Clips(this)
Expand Down
117 changes: 58 additions & 59 deletions scripts/dao/action-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ActionsData {
// checkUserAction
this.checkUserAction()
// sync
this.initWebdavSync()
this.sync()
}

Expand All @@ -47,10 +48,6 @@ class ActionsData {
$cache.get("caio.action.isNew", isNew)
}

get isEnableWebDavSync() {
return this.kernel.setting.get("webdav.status")
}

#initActions() {
this.#actions = this.getActionCategories().map(category => {
return {
Expand All @@ -69,30 +66,6 @@ class ActionsData {
this.kernel.logger.info(`init actions`)
}

updatePinActions(from, to) {
KeyboardPinActions.shared.setKernel(this.kernel).updateAction(from, to)
TodayPinActions.shared.setKernel(this.kernel).updateAction(from, to)
}

setNeedReload(animate) {
this.#actions = undefined
this.#allActions = undefined

// 通知更新 UI
this.applySnapshotAnimatingDifferences(animate)

if (!this.isEnableWebDavSync) return
try {
this.webdavSync.needUpload()
} catch (error) {
$ui.alert({
title: $l10n("ALERT"),
message: $l10n("WEBDAV_ERROR_CLOSED")
})
this.kernel.setting.set("webdav.status", false)
}
}

importExampleAction() {
try {
Object.keys(__ACTIONS__).forEach(category => {
Expand Down Expand Up @@ -125,14 +98,6 @@ class ActionsData {
this.setNeedReload()
}

actionToString(category, dir) {
return JSON.stringify({
config: this.getActionConfigString(category, dir),
main: this.getActionMainJs(category, dir),
readme: this.getActionReadme(category, dir)
})
}

exportAction(action) {
const loading = UIKit.loading()
loading.start()
Expand Down Expand Up @@ -187,40 +152,74 @@ class ActionsData {
}
}

checkUserAction() {
if (!$file.exists(this.userActionPath) || $file.list(this.userActionPath).length === 0) {
$file.mkdir(this.userActionPath)
this.isNew = false
this.importExampleAction()
}
}

getLocalSyncDate() {
const localSyncDate = JSON.parse($file.read(this.localSyncFile)?.string ?? "{}")
return new Date(localSyncDate.timestamp)
}

async sync() {
if (!this.isEnableWebDavSync) return
if (!this.webdavSync) {
try {
this.webdavSync = new WebDavSyncAction({
kernel: this.kernel,
host: this.kernel.setting.get("webdav.host"),
user: this.kernel.setting.get("webdav.user"),
password: this.kernel.setting.get("webdav.password"),
basepath: this.kernel.setting.get("webdav.basepath")
})
await this.webdavSync.init()
} catch (error) {
this.kernel.logger.error(`${error}\n${error.stack}`)
throw error
}
} else {
this.webdavSync.sync()
async initWebdavSync() {
if (!this.kernel.isWebdavEnabled) return

try {
this.webdavSync = new WebDavSyncAction({
kernel: this.kernel,
host: this.kernel.setting.get("webdav.host"),
user: this.kernel.setting.get("webdav.user"),
password: this.kernel.setting.get("webdav.password"),
basepath: this.kernel.setting.get("webdav.basepath")
})
await this.webdavSync.init()
} catch (error) {
this.kernel.logger.error(`${error}\n${error.stack}`)
throw error
}
}

checkUserAction() {
if (!$file.exists(this.userActionPath) || $file.list(this.userActionPath).length === 0) {
$file.mkdir(this.userActionPath)
this.isNew = false
this.importExampleAction()
setNeedReload(animate) {
this.#actions = undefined
this.#allActions = undefined

// 通知更新 UI
this.applySnapshotAnimatingDifferences(animate)

if (!this.webdavSync) return
try {
this.webdavSync.needUpload()
} catch (error) {
$ui.alert({
title: $l10n("ALERT"),
message: $l10n("WEBDAV_ERROR_CLOSED")
})
this.kernel.setting.set("webdav.status", false)
}
}

async sync() {
if (!this.webdavSync) return
this.webdavSync.sync()
}

updatePinActions(from, to) {
KeyboardPinActions.shared.setKernel(this.kernel).updateAction(from, to)
TodayPinActions.shared.setKernel(this.kernel).updateAction(from, to)
}

actionToString(category, dir) {
return JSON.stringify({
config: this.getActionConfigString(category, dir),
main: this.getActionMainJs(category, dir),
readme: this.getActionReadme(category, dir)
})
}

defaultCategories() {
return ["uncategorized", "clipboard", "editor"]
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/dao/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Storage {
}

async initWebdavSync() {
if (!this.kernel.setting.get("webdav.status")) return
if (!this.kernel.isWebdavEnabled) return

try {
this.webdavSync = new WebDavSyncClip({
Expand Down

0 comments on commit 97f364b

Please sign in to comment.