From cbdc494d2385f823600b4635bd8ff97065a82d47 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 23 Mar 2023 09:51:22 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20macOS=20=E7=AB=AF=E5=AF=B9=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E7=A9=BA=E9=97=B4=E6=94=BE=E7=BD=AE=E5=9C=A8=20iCloud?= =?UTF-8?q?=20=E8=B7=AF=E5=BE=84=E4=B8=8B=E5=81=9A=E6=A3=80=E6=9F=A5=20htt?= =?UTF-8?q?ps://github.com/siyuan-note/siyuan/issues/7747?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/electron/init.html | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/app/electron/init.html b/app/electron/init.html index 46b7dca65..2cbe4f509 100644 --- a/app/electron/init.html +++ b/app/electron/init.html @@ -361,7 +361,7 @@ if (isCloudDrivePath(initPath)) { let msg = '⚠️ This folder may be a cloud sync disk folder, please change to another path' if ('zh_CN' === currentLang) { - msg = '⚠️ 该文件夹可能是云同步盘文件夹,请更换其他路径' + msg = '⚠️ 该文件夹可能是云同步盘文件夹,请更换其他路径' } alert(msg) return @@ -388,9 +388,47 @@ const isCloudDrivePath = (absPath) => { const absPathLower = absPath.toLowerCase() + if (isICloudPath(absPathLower)) { + return true + } + return -1 < absPathLower.indexOf("onedrive") || -1 < absPathLower.indexOf("dropbox") || -1 < absPathLower.indexOf("google drive") || -1 < absPathLower.indexOf("pcloud") } + + const isICloudPath = (absPath) => { + const process = require('process') + if ('darwin' !== process.platform) { + return false + } + + // macOS 端对工作空间放置在 iCloud 路径下做检查 https://github.com/siyuan-note/siyuan/issues/7747 + const path = require('path') + const iCloudRoot = path.join(decodeURIComponent(getSearch('home')), 'Library', 'Mobile Documents') + const allFiles = walk(iCloudRoot) + for (const file of allFiles) { + console.log(file) + if (-1 < absPath.indexOf(file)) { + return true + } + } + return false + } + + const walk = (dir, files = []) => { + const fs = require('fs') + const dirFiles = fs.readdirSync(dir) + for (const f of dirFiles) { + const stat = fs.lstatSync(dir + path.sep + f) + if (stat.isDirectory()) { + walk(dir + path.sep + f, files) + } else { + files.push(dir + path.sep + f) + } + } + return files + } +