mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-05-13 11:01:16 +00:00
Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b337a05b5a | ||
|
|
9ea6bee9d1 | ||
|
|
9747c26d50 | ||
|
|
bb4b764586 | ||
|
|
279b4b41e5 | ||
|
|
b644fb791d | ||
|
|
ac9428e96b | ||
|
|
280d9e1dd9 | ||
|
|
f7209e566c | ||
|
|
4a9ab2d1de | ||
|
|
cb74b5ee93 | ||
|
|
60eecd7001 | ||
|
|
4bd7b54bcd | ||
|
|
8923c73d1b | ||
|
|
11e64b13e2 | ||
|
|
983d9248ed | ||
|
|
7240e84328 | ||
|
|
0d55ae2532 | ||
|
|
dbd284f5dd | ||
|
|
c000a02f4a | ||
|
|
79754f48d6 | ||
|
|
dd7a40630b | ||
|
|
14406f8213 | ||
|
|
3bbd9c048d | ||
|
|
d91c4f50b4 | ||
|
|
395b7fbc42 | ||
|
|
3773e57429 | ||
|
|
4835fce62a | ||
|
|
ff814be4a0 | ||
|
|
b271b63efa | ||
|
|
23419e476a | ||
|
|
b9bd1f17b8 | ||
|
|
bcce277c36 | ||
|
|
5acbbe479e | ||
|
|
c9f9d511e0 | ||
|
|
b8cb94c498 | ||
|
|
52c736f6b9 | ||
|
|
ebd1cb7777 | ||
|
|
10decb7909 | ||
|
|
d1aba87e37 | ||
|
|
db889f635e | ||
|
|
dd80e634f5 | ||
|
|
bec6fc1a74 |
@@ -66,7 +66,7 @@ Synchronization status is shown in statusbar.
|
|||||||
- ↓ Downloaded chunks and metadata
|
- ↓ Downloaded chunks and metadata
|
||||||
- ⏳ Number of pending processes
|
- ⏳ Number of pending processes
|
||||||
- 🧩 Number of files waiting for their chunks.
|
- 🧩 Number of files waiting for their chunks.
|
||||||
If you have deleted or renamed files, please wait until ⏳ icon disappeared.
|
If you have deleted or renamed files, please wait until ⏳ icon disappears.
|
||||||
|
|
||||||
|
|
||||||
## Hints
|
## Hints
|
||||||
|
|||||||
318
deploy_couchdb_to_flyio_v2_with_swap.ipynb
Normal file
318
deploy_couchdb_to_flyio_v2_with_swap.ipynb
Normal file
@@ -0,0 +1,318 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"colab_type": "text",
|
||||||
|
"id": "view-in-github"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"<a href=\"https://colab.research.google.com/gist/vrtmrz/37c3efd7842e49947aaaa7f665e5020a/deploy_couchdb_to_flyio_v2_with_swap.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "HiRV7G8Gk1Rs"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"History:\n",
|
||||||
|
"- 18, May, 2023: Initial.\n",
|
||||||
|
"- 19, Jun., 2023: Patched for enabling swap.\n",
|
||||||
|
"- 22, Aug., 2023: Generating Setup-URI implemented.\n",
|
||||||
|
"- 7, Nov., 2023: Fixed the issue of TOML editing."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "2Vh0mEQEZuAK"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Configurations\n",
|
||||||
|
"import os\n",
|
||||||
|
"os.environ['region']=\"nrt\"\n",
|
||||||
|
"os.environ['couchUser']=\"alkcsa93\"\n",
|
||||||
|
"os.environ['couchPwd']=\"c349usdfnv48fsasd\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "SPmbB0jZauQ1"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Delete once (Do not care about `cannot remove './fly.toml': No such file or directory`)\n",
|
||||||
|
"!rm ./fly.toml"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "Nze7QoxLZ7Yx"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Installation\n",
|
||||||
|
"# You have to set up your account in here.\n",
|
||||||
|
"!curl -L https://fly.io/install.sh | sh\n",
|
||||||
|
"!/root/.fly/bin/flyctl auth signup"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "MVJwsIYrbgtx"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Generate server\n",
|
||||||
|
"!/root/.fly/bin/flyctl launch --auto-confirm --generate-name --detach --no-deploy --region ${region}\n",
|
||||||
|
"!/root/.fly/bin/fly volumes create --region ${region} couchdata --size 2 --yes"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "2RSoO9o-i2TT"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Check the toml once.\n",
|
||||||
|
"!cat fly.toml"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "zUtPZLVnbvdQ"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Modify the TOML and generate Dockerfile\n",
|
||||||
|
"!pip install mergedeep\n",
|
||||||
|
"from mergedeep import merge\n",
|
||||||
|
"import toml\n",
|
||||||
|
"fly = toml.load('fly.toml')\n",
|
||||||
|
"override = {\n",
|
||||||
|
" \"http_service\":{\n",
|
||||||
|
" \"internal_port\":5984\n",
|
||||||
|
" },\n",
|
||||||
|
" \"build\":{\n",
|
||||||
|
" \"dockerfile\":\"./Dockerfile\"\n",
|
||||||
|
" },\n",
|
||||||
|
" \"mounts\":{\n",
|
||||||
|
" \"source\":\"couchdata\",\n",
|
||||||
|
" \"destination\":\"/opt/couchdb/data\"\n",
|
||||||
|
" },\n",
|
||||||
|
" \"env\":{\n",
|
||||||
|
" \"COUCHDB_USER\":os.environ['couchUser'],\n",
|
||||||
|
" \"ERL_FLAGS\":\"-couch_ini /opt/couchdb/etc/default.ini /opt/couchdb/etc/default.d/ /opt/couchdb/etc/local.d /opt/couchdb/etc/local.ini /opt/couchdb/data/persistence.ini\",\n",
|
||||||
|
" }\n",
|
||||||
|
"}\n",
|
||||||
|
"out = merge(fly,override)\n",
|
||||||
|
"with open('fly.toml', 'wt') as fp:\n",
|
||||||
|
" toml.dump(out, fp)\n",
|
||||||
|
" fp.close()\n",
|
||||||
|
"\n",
|
||||||
|
"# Make the Dockerfile to modify the permission of the ini file. If you want to use a specific version, you should change `latest` here.\n",
|
||||||
|
"dockerfile = '''FROM couchdb:latest\n",
|
||||||
|
"RUN sed -i '2itouch /opt/couchdb/data/persistence.ini && chmod +w /opt/couchdb/data/persistence.ini && fallocate -l 512M /swapfile && chmod 0600 /swapfile && mkswap /swapfile && echo 10 > /proc/sys/vm/swappiness && swapon /swapfile && echo 1 > /proc/sys/vm/overcommit_memory' /docker-entrypoint.sh\n",
|
||||||
|
"'''\n",
|
||||||
|
"with open(\"./Dockerfile\",\"wt\") as fp:\n",
|
||||||
|
" fp.write(dockerfile)\n",
|
||||||
|
" fp.close()\n",
|
||||||
|
"\n",
|
||||||
|
"!echo ------\n",
|
||||||
|
"!cat fly.toml\n",
|
||||||
|
"!echo ------\n",
|
||||||
|
"!cat Dockerfile"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "xWdsTCI6bzk2"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Configure password\n",
|
||||||
|
"!/root/.fly/bin/flyctl secrets set COUCHDB_PASSWORD=${couchPwd}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "k0WIQlShcXGa"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Deploy server\n",
|
||||||
|
"# Be sure to shutdown after the test.\n",
|
||||||
|
"!/root/.fly/bin/flyctl deploy --detach --remote-only\n",
|
||||||
|
"!/root/.fly/bin/flyctl status"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "0ySggkdlfq7M"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import subprocess, json\n",
|
||||||
|
"result = subprocess.run([\"/root/.fly/bin/flyctl\",\"status\",\"-j\"], capture_output=True, text=True)\n",
|
||||||
|
"if result.returncode==0:\n",
|
||||||
|
" hostname = json.loads(result.stdout)[\"Hostname\"]\n",
|
||||||
|
" os.environ['couchHost']=\"https://%s\" % (hostname)\n",
|
||||||
|
" print(\"Your couchDB server is https://%s/\" % (hostname))\n",
|
||||||
|
"else:\n",
|
||||||
|
" print(\"Something occured.\")\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "cGlSzVqlQG_z"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Finish setting up the CouchDB\n",
|
||||||
|
"# Please repeat until the request is completed without error messages\n",
|
||||||
|
"# i.e., You have to redo this block while \"curl: (35) OpenSSL SSL_connect: Connection reset by peer in connection to xxxx\" is showing.\n",
|
||||||
|
"#\n",
|
||||||
|
"# Note: A few minutes might be required to be booted.\n",
|
||||||
|
"!curl -X POST \"${couchHost}/_cluster_setup\" -H \"Content-Type: application/json\" -d \"{\\\"action\\\":\\\"enable_single_node\\\",\\\"username\\\":\\\"${couchUser}\\\",\\\"password\\\":\\\"${couchPwd}\\\",\\\"bind_address\\\":\\\"0.0.0.0\\\",\\\"port\\\":5984,\\\"singlenode\\\":true}\" --user \"${couchUser}:${couchPwd}\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "JePzrsHypY18"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Please repeat until all lines are completed without error messages\n",
|
||||||
|
"!curl -X PUT \"${couchHost}/_node/nonode@nohost/_config/chttpd/require_valid_user\" -H \"Content-Type: application/json\" -d '\"true\"' --user \"${couchUser}:${couchPwd}\"\n",
|
||||||
|
"!curl -X PUT \"${couchHost}/_node/nonode@nohost/_config/chttpd_auth/require_valid_user\" -H \"Content-Type: application/json\" -d '\"true\"' --user \"${couchUser}:${couchPwd}\"\n",
|
||||||
|
"!curl -X PUT \"${couchHost}/_node/nonode@nohost/_config/httpd/WWW-Authenticate\" -H \"Content-Type: application/json\" -d '\"Basic realm=\\\"couchdb\\\"\"' --user \"${couchUser}:${couchPwd}\"\n",
|
||||||
|
"!curl -X PUT \"${couchHost}/_node/nonode@nohost/_config/httpd/enable_cors\" -H \"Content-Type: application/json\" -d '\"true\"' --user \"${couchUser}:${couchPwd}\"\n",
|
||||||
|
"!curl -X PUT \"${couchHost}/_node/nonode@nohost/_config/chttpd/enable_cors\" -H \"Content-Type: application/json\" -d '\"true\"' --user \"${couchUser}:${couchPwd}\"\n",
|
||||||
|
"!curl -X PUT \"${couchHost}/_node/nonode@nohost/_config/chttpd/max_http_request_size\" -H \"Content-Type: application/json\" -d '\"4294967296\"' --user \"${couchUser}:${couchPwd}\"\n",
|
||||||
|
"!curl -X PUT \"${couchHost}/_node/nonode@nohost/_config/couchdb/max_document_size\" -H \"Content-Type: application/json\" -d '\"50000000\"' --user \"${couchUser}:${couchPwd}\"\n",
|
||||||
|
"!curl -X PUT \"${couchHost}/_node/nonode@nohost/_config/cors/credentials\" -H \"Content-Type: application/json\" -d '\"true\"' --user \"${couchUser}:${couchPwd}\"\n",
|
||||||
|
"!curl -X PUT \"${couchHost}/_node/nonode@nohost/_config/cors/origins\" -H \"Content-Type: application/json\" -d '\"app://obsidian.md,capacitor://localhost,http://localhost\"' --user \"${couchUser}:${couchPwd}\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "YfSOomsoXbGS"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"Now, our CouchDB has been surely installed and configured. Cheers!\n",
|
||||||
|
"\n",
|
||||||
|
"In the steps that follow, create a setup-URI.\n",
|
||||||
|
"\n",
|
||||||
|
"This URI could be imported directly into Self-hosted LiveSync, to configure the use of the CouchDB which we configured now."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "416YncOqXdNn"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Database config\n",
|
||||||
|
"import random, string\n",
|
||||||
|
"\n",
|
||||||
|
"def randomname(n):\n",
|
||||||
|
" return ''.join(random.choices(string.ascii_letters + string.digits, k=n))\n",
|
||||||
|
"\n",
|
||||||
|
"# The database name\n",
|
||||||
|
"os.environ['database']=\"obsidiannote\"\n",
|
||||||
|
"# The passphrase to E2EE\n",
|
||||||
|
"os.environ['passphrase']=randomname(20)\n",
|
||||||
|
"\n",
|
||||||
|
"print(\"Your database:\"+os.environ['database'])\n",
|
||||||
|
"print(\"Your passphrase:\"+os.environ['passphrase'])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "C4d7C0HAXgsr"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Install deno for make setup uri\n",
|
||||||
|
"!curl -fsSL https://deno.land/x/install/install.sh | sh"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "hQL_Dx-PXise"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Fetch module for encrypting a Setup URI\n",
|
||||||
|
"!curl -o encrypt.ts https://gist.githubusercontent.com/vrtmrz/f9d1d95ee2ca3afa1a924a2c6759b854/raw/d7a070d864a6f61403d8dc74208238d5741aeb5a/encrypt.ts"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "o0gX_thFXlIZ"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Make buttons!\n",
|
||||||
|
"from IPython.display import HTML\n",
|
||||||
|
"result = subprocess.run([\"/root/.deno/bin/deno\",\"run\",\"-A\",\"encrypt.ts\"], capture_output=True, text=True)\n",
|
||||||
|
"text=\"\"\n",
|
||||||
|
"if result.returncode==0:\n",
|
||||||
|
" text = result.stdout.strip()\n",
|
||||||
|
" result = HTML(f\"<button onclick=navigator.clipboard.writeText('{text}')>Copy setup uri</button><br>Importing passphrase is `welcome`. <br>If you want to synchronise in live mode, please apply a preset after setup.)\")\n",
|
||||||
|
"else:\n",
|
||||||
|
" result = \"Failed to encrypt the setup URI\"\n",
|
||||||
|
"result"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"colab": {
|
||||||
|
"include_colab_link": true,
|
||||||
|
"private_outputs": true,
|
||||||
|
"provenance": []
|
||||||
|
},
|
||||||
|
"gpuClass": "standard",
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"name": "python"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 0
|
||||||
|
}
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
# Quick setup
|
# Quick setup
|
||||||
|
|
||||||
|
[Japanese docs](./quick_setup_ja.md) - [Chinese docs](./quick_setup_cn.md).
|
||||||
|
|
||||||
The plugin has so many configuration options to deal with different circumstances. However, there are not so many settings that are actually used. Therefore, `The Setup wizard` has been implemented to simplify the initial setup.
|
The plugin has so many configuration options to deal with different circumstances. However, there are not so many settings that are actually used. Therefore, `The Setup wizard` has been implemented to simplify the initial setup.
|
||||||
|
|
||||||
Note: Subsequent devices are recommended to be set up using the `Copy setup URI` and `Open setup URI`.
|
Note: Subsequent devices are recommended to be set up using the `Copy setup URI` and `Open setup URI`.
|
||||||
|
|||||||
93
docs/quick_setup_cn.md
Normal file
93
docs/quick_setup_cn.md
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
# 快速配置 (Quick setup)
|
||||||
|
|
||||||
|
该插件有较多配置项, 可以应对不同的情况. 不过, 实际使用的设置并不多. 因此, 我们采用了 "设置向导 (The Setup wizard)" 来简化初始设置.
|
||||||
|
|
||||||
|
Note: 建议使用 `Copy setup URI` and `Open setup URI` 来设置后续设备.
|
||||||
|
|
||||||
|
## 设置向导 (The Setup wizard)
|
||||||
|
|
||||||
|
在设置对话框中打开 `🧙♂️ Setup wizard`. 如果之前未配置插件, 则会自动打开该页面.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- 放弃现有配置并进行设置
|
||||||
|
如果您先前有过任何设置, 此按钮允许您在设置前放弃所有更改.
|
||||||
|
|
||||||
|
- 保留现有配置和设置
|
||||||
|
快速重新配置. 请注意, 在向导模式下, 您无法看到所有已经配置过的配置项.
|
||||||
|
|
||||||
|
在上述选项中按下 `Next`, 配置对话框将进入向导模式 (wizard mode).
|
||||||
|
|
||||||
|
### 向导模式 (Wizard mode)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
接下来将介绍如何逐步使用向导模式.
|
||||||
|
|
||||||
|
## 配置远程数据库
|
||||||
|
|
||||||
|
### 开始配置远程数据库
|
||||||
|
|
||||||
|
输入已部署好的数据库的信息.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### 测试数据库连接并检查数据库配置
|
||||||
|
|
||||||
|
我们可以检查数据库的连接性和数据库设置.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### 测试数据库连接
|
||||||
|
|
||||||
|
检查是否能成功连接数据库. 如果连接失败, 可能是多种原因导致的, 但请先点击 `Check database configuration` 来检查数据库配置是否有问题.
|
||||||
|
|
||||||
|
#### 检查数据库配置
|
||||||
|
|
||||||
|
检查数据库设置并修复问题.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Config check 的显示内容可能因不同连接而异. 在上图情况下, 按下所有三个修复按钮.
|
||||||
|
如果修复按钮消失, 全部变为复选标记, 则表示修复完成.
|
||||||
|
|
||||||
|
### 加密配置
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
为您的数据库加密, 以防数据库意外曝光; 启用端到端加密后, 笔记内容在离开设备时就会被加密. 我们强烈建议启用该功能. `路径混淆 (Path Obfuscation)` 还能混淆文件名. 现已稳定并推荐使用.
|
||||||
|
加密基于 256 位 AES-GCM.
|
||||||
|
如果你在一个封闭的网络中, 而且很明显第三方不会访问你的文件, 则可以禁用这些设置.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### Next
|
||||||
|
|
||||||
|
转到同步设置.
|
||||||
|
|
||||||
|
#### 放弃现有数据库并继续
|
||||||
|
|
||||||
|
清除远程数据库的内容, 然后转到同步设置.
|
||||||
|
|
||||||
|
### 同步设置
|
||||||
|
|
||||||
|
最后, 选择一个同步预设完成向导.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
选择我们要使用的任何同步方法, 然后 `Apply` 初始化并按要求建立本地和远程数据库. 如果显示 `All done!`, 我们就完成了. `Copy setup URI` 将自动打开,并要求我们输入密码以加密 `Setup URI`.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
根据需要设置密码。.
|
||||||
|
设置 URI (Setup URI) 将被复制到剪贴板, 然后您可以通过某种方式将其传输到第二个及后续设备.
|
||||||
|
|
||||||
|
## 如何设置第二单元和后续单元 (the second and subsequent units)
|
||||||
|
|
||||||
|
在第一台设备上安装 Self-hosted LiveSync 后, 从命令面板上选择 `Open setup URI`, 然后输入您传输的设置 URI (Setup URI). 然后输入密码,安装向导就会打开.
|
||||||
|
在弹窗中选择以下内容.
|
||||||
|
|
||||||
|
- `Importing LiveSync's conf, OK?` 选择 `Yes`
|
||||||
|
- `How would you like to set it up?`. 选择 `Set it up as secondary or subsequent device`
|
||||||
|
|
||||||
|
然后, 配置将生效并开始复制. 您的文件很快就会同步! 您可能需要关闭设置对话框并重新打开, 才能看到设置字段正确填充, 但它们都将设置好.
|
||||||
@@ -280,7 +280,7 @@ Now the CouchDB is ready to use from Self-hosted LiveSync. We can use `https://b
|
|||||||
|
|
||||||
## Automatic setup using Colaboratory
|
## Automatic setup using Colaboratory
|
||||||
|
|
||||||
We can perform all these steps by using [this Colaboratory notebook](https://gist.github.com/vrtmrz/b437a539af25ef191bd452aae369242f) without installing anything.
|
We can perform all these steps by using [this Colaboratory notebook](/deploy_couchdb_to_flyio_v2_with_swap.ipynb) without installing anything.
|
||||||
|
|
||||||
## After testing / before creating a new instance
|
## After testing / before creating a new instance
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,9 @@ const terserOpt = {
|
|||||||
lhs_constants: true,
|
lhs_constants: true,
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
// if_return: true,
|
if_return: true,
|
||||||
|
ecma: 2018,
|
||||||
|
unused: true,
|
||||||
},
|
},
|
||||||
// mangle: {
|
// mangle: {
|
||||||
// // mangle options
|
// // mangle options
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "obsidian-livesync",
|
"id": "obsidian-livesync",
|
||||||
"name": "Self-hosted LiveSync",
|
"name": "Self-hosted LiveSync",
|
||||||
"version": "0.19.18",
|
"version": "0.21.2",
|
||||||
"minAppVersion": "0.9.12",
|
"minAppVersion": "0.9.12",
|
||||||
"description": "Community implementation of self-hosted livesync. Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
"description": "Community implementation of self-hosted livesync. Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
||||||
"author": "vorotamoroz",
|
"author": "vorotamoroz",
|
||||||
|
|||||||
18
package-lock.json
generated
18
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "obsidian-livesync",
|
"name": "obsidian-livesync",
|
||||||
"version": "0.19.18",
|
"version": "0.21.2",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "obsidian-livesync",
|
"name": "obsidian-livesync",
|
||||||
"version": "0.19.18",
|
"version": "0.21.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"diff-match-patch": "^1.0.5",
|
"diff-match-patch": "^1.0.5",
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
"eslint-config-airbnb-base": "^15.0.0",
|
"eslint-config-airbnb-base": "^15.0.0",
|
||||||
"eslint-plugin-import": "^2.28.0",
|
"eslint-plugin-import": "^2.28.0",
|
||||||
"events": "^3.3.0",
|
"events": "^3.3.0",
|
||||||
"obsidian": "^1.3.5",
|
"obsidian": "^1.4.11",
|
||||||
"postcss": "^8.4.27",
|
"postcss": "^8.4.27",
|
||||||
"postcss-load-config": "^4.0.1",
|
"postcss-load-config": "^4.0.1",
|
||||||
"pouchdb-adapter-http": "^8.0.1",
|
"pouchdb-adapter-http": "^8.0.1",
|
||||||
@@ -3223,9 +3223,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/obsidian": {
|
"node_modules/obsidian": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.11",
|
||||||
"resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.4.11.tgz",
|
||||||
"integrity": "sha512-fsZMPlxgflGSBSP6P4BjQi5+0MqZl3h6FEDEZ3CNnweNdDw0doyqN3FMO/PGWfuxPT77WicVwUxekuI3e6eCGg==",
|
"integrity": "sha512-BCVYTvaXxElJMl6MMbDdY/CGK+aq18SdtDY/7vH8v6BxCBQ6KF4kKxL0vG9UZ0o5qh139KpUoJHNm+6O5dllKA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/codemirror": "5.60.8",
|
"@types/codemirror": "5.60.8",
|
||||||
@@ -6913,9 +6913,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"obsidian": {
|
"obsidian": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.11",
|
||||||
"resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.4.11.tgz",
|
||||||
"integrity": "sha512-fsZMPlxgflGSBSP6P4BjQi5+0MqZl3h6FEDEZ3CNnweNdDw0doyqN3FMO/PGWfuxPT77WicVwUxekuI3e6eCGg==",
|
"integrity": "sha512-BCVYTvaXxElJMl6MMbDdY/CGK+aq18SdtDY/7vH8v6BxCBQ6KF4kKxL0vG9UZ0o5qh139KpUoJHNm+6O5dllKA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/codemirror": "5.60.8",
|
"@types/codemirror": "5.60.8",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "obsidian-livesync",
|
"name": "obsidian-livesync",
|
||||||
"version": "0.19.18",
|
"version": "0.21.2",
|
||||||
"description": "Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
"description": "Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -17,9 +17,9 @@
|
|||||||
"@types/diff-match-patch": "^1.0.32",
|
"@types/diff-match-patch": "^1.0.32",
|
||||||
"@types/node": "^20.2.5",
|
"@types/node": "^20.2.5",
|
||||||
"@types/pouchdb": "^6.4.0",
|
"@types/pouchdb": "^6.4.0",
|
||||||
"@types/pouchdb-browser": "^6.1.3",
|
|
||||||
"@types/pouchdb-adapter-http": "^6.1.3",
|
"@types/pouchdb-adapter-http": "^6.1.3",
|
||||||
"@types/pouchdb-adapter-idb": "^6.1.4",
|
"@types/pouchdb-adapter-idb": "^6.1.4",
|
||||||
|
"@types/pouchdb-browser": "^6.1.3",
|
||||||
"@types/pouchdb-core": "^7.0.11",
|
"@types/pouchdb-core": "^7.0.11",
|
||||||
"@types/pouchdb-mapreduce": "^6.1.7",
|
"@types/pouchdb-mapreduce": "^6.1.7",
|
||||||
"@types/pouchdb-replication": "^6.4.4",
|
"@types/pouchdb-replication": "^6.4.4",
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
"eslint-config-airbnb-base": "^15.0.0",
|
"eslint-config-airbnb-base": "^15.0.0",
|
||||||
"eslint-plugin-import": "^2.28.0",
|
"eslint-plugin-import": "^2.28.0",
|
||||||
"events": "^3.3.0",
|
"events": "^3.3.0",
|
||||||
"obsidian": "^1.3.5",
|
"obsidian": "^1.4.11",
|
||||||
"postcss": "^8.4.27",
|
"postcss": "^8.4.27",
|
||||||
"postcss-load-config": "^4.0.1",
|
"postcss-load-config": "^4.0.1",
|
||||||
"pouchdb-adapter-http": "^8.0.1",
|
"pouchdb-adapter-http": "^8.0.1",
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
import { Notice, type PluginManifest, parseYaml } from "./deps";
|
import { Notice, type PluginManifest, parseYaml, normalizePath } from "./deps";
|
||||||
|
|
||||||
import type { EntryDoc, LoadedEntry, InternalFileEntry, FilePathWithPrefix, FilePath, DocumentID, AnyEntry } from "./lib/src/types";
|
import type { EntryDoc, LoadedEntry, InternalFileEntry, FilePathWithPrefix, FilePath, DocumentID, AnyEntry, SavingEntry } from "./lib/src/types";
|
||||||
import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "./lib/src/types";
|
import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, MODE_SELECTIVE } from "./lib/src/types";
|
||||||
import { ICXHeader, PERIODIC_PLUGIN_SWEEP, } from "./types";
|
import { ICXHeader, PERIODIC_PLUGIN_SWEEP, } from "./types";
|
||||||
import { delay, getDocData } from "./lib/src/utils";
|
import { createTextBlob, delay, getDocData } from "./lib/src/utils";
|
||||||
import { Logger } from "./lib/src/logger";
|
import { Logger } from "./lib/src/logger";
|
||||||
import { WrappedNotice } from "./lib/src/wrapper";
|
import { WrappedNotice } from "./lib/src/wrapper";
|
||||||
import { base64ToArrayBuffer, arrayBufferToBase64, readString, crc32CKHash } from "./lib/src/strbin";
|
import { readString, crc32CKHash, decodeBinary, arrayBufferToBase64 } from "./lib/src/strbin";
|
||||||
import { runWithLock } from "./lib/src/lock";
|
import { serialized } from "./lib/src/lock";
|
||||||
import { LiveSyncCommands } from "./LiveSyncCommands";
|
import { LiveSyncCommands } from "./LiveSyncCommands";
|
||||||
import { stripAllPrefixes } from "./lib/src/path";
|
import { stripAllPrefixes } from "./lib/src/path";
|
||||||
import { PeriodicProcessor, askYesNo, disposeMemoObject, memoIfNotExist, memoObject, retrieveMemoObject, scheduleTask } from "./utils";
|
import { PeriodicProcessor, askYesNo, disposeMemoObject, memoIfNotExist, memoObject, retrieveMemoObject, scheduleTask } from "./utils";
|
||||||
@@ -16,12 +16,109 @@ import { PluginDialogModal } from "./dialogs";
|
|||||||
import { JsonResolveModal } from "./JsonResolveModal";
|
import { JsonResolveModal } from "./JsonResolveModal";
|
||||||
import { pipeGeneratorToGenerator, processAllGeneratorTasksWithConcurrencyLimit } from './lib/src/task';
|
import { pipeGeneratorToGenerator, processAllGeneratorTasksWithConcurrencyLimit } from './lib/src/task';
|
||||||
|
|
||||||
|
const d = "\u200b";
|
||||||
|
const d2 = "\n";
|
||||||
|
|
||||||
function serialize<T>(obj: T): string {
|
function serialize(data: PluginDataEx): string {
|
||||||
return JSON.stringify(obj, null, 1);
|
// For higher performance, create custom plug-in data strings.
|
||||||
|
// Self-hosted LiveSync uses `\n` to split chunks. Therefore, grouping together those with similar entropy would work nicely.
|
||||||
|
let ret = "";
|
||||||
|
ret += ":";
|
||||||
|
ret += data.category + d + data.name + d + data.term + d2;
|
||||||
|
ret += (data.version ?? "") + d2;
|
||||||
|
ret += data.mtime + d2;
|
||||||
|
for (const file of data.files) {
|
||||||
|
ret += file.filename + d + (file.displayName ?? "") + d + (file.version ?? "") + d2;
|
||||||
|
ret += file.mtime + d + file.size + d2;
|
||||||
|
for (const data of file.data ?? []) {
|
||||||
|
ret += data + d
|
||||||
|
}
|
||||||
|
ret += d2;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
function fetchToken(source: string, from: number): [next: number, token: string] {
|
||||||
|
const limitIdx = source.indexOf(d2, from);
|
||||||
|
const limit = limitIdx == -1 ? source.length : limitIdx;
|
||||||
|
const delimiterIdx = source.indexOf(d, from);
|
||||||
|
const delimiter = delimiterIdx == -1 ? source.length : delimiterIdx;
|
||||||
|
const tokenEnd = Math.min(limit, delimiter);
|
||||||
|
let next = tokenEnd;
|
||||||
|
if (limit < delimiter) {
|
||||||
|
next = tokenEnd;
|
||||||
|
} else {
|
||||||
|
next = tokenEnd + 1
|
||||||
|
}
|
||||||
|
return [next, source.substring(from, tokenEnd)];
|
||||||
|
}
|
||||||
|
function getTokenizer(source: string) {
|
||||||
|
const t = {
|
||||||
|
pos: 1,
|
||||||
|
next() {
|
||||||
|
const [next, token] = fetchToken(source, this.pos);
|
||||||
|
this.pos = next;
|
||||||
|
return token;
|
||||||
|
},
|
||||||
|
nextLine() {
|
||||||
|
const nextPos = source.indexOf(d2, this.pos);
|
||||||
|
if (nextPos == -1) {
|
||||||
|
this.pos = source.length;
|
||||||
|
} else {
|
||||||
|
this.pos = nextPos + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deserialize2(str: string): PluginDataEx {
|
||||||
|
const tokens = getTokenizer(str);
|
||||||
|
const ret = {} as PluginDataEx;
|
||||||
|
const category = tokens.next();
|
||||||
|
const name = tokens.next();
|
||||||
|
const term = tokens.next();
|
||||||
|
tokens.nextLine();
|
||||||
|
const version = tokens.next();
|
||||||
|
tokens.nextLine();
|
||||||
|
const mtime = Number(tokens.next());
|
||||||
|
tokens.nextLine();
|
||||||
|
const result: PluginDataEx = Object.assign(ret,
|
||||||
|
{ category, name, term, version, mtime, files: [] as PluginDataExFile[] })
|
||||||
|
let filename = "";
|
||||||
|
do {
|
||||||
|
filename = tokens.next();
|
||||||
|
if (!filename) break;
|
||||||
|
const displayName = tokens.next();
|
||||||
|
const version = tokens.next();
|
||||||
|
tokens.nextLine();
|
||||||
|
const mtime = Number(tokens.next());
|
||||||
|
const size = Number(tokens.next());
|
||||||
|
tokens.nextLine();
|
||||||
|
const data = [] as string[];
|
||||||
|
let piece = "";
|
||||||
|
do {
|
||||||
|
piece = tokens.next();
|
||||||
|
if (piece == "") break;
|
||||||
|
data.push(piece);
|
||||||
|
} while (piece != "");
|
||||||
|
result.files.push(
|
||||||
|
{
|
||||||
|
filename,
|
||||||
|
displayName,
|
||||||
|
version,
|
||||||
|
mtime,
|
||||||
|
size,
|
||||||
|
data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
tokens.nextLine();
|
||||||
|
} while (filename);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
function deserialize<T>(str: string, def: T) {
|
function deserialize<T>(str: string, def: T) {
|
||||||
try {
|
try {
|
||||||
|
if (str[0] == ":") return deserialize2(str);
|
||||||
return JSON.parse(str) as T;
|
return JSON.parse(str) as T;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
try {
|
try {
|
||||||
@@ -107,6 +204,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileCategory(filePath: string): "CONFIG" | "THEME" | "SNIPPET" | "PLUGIN_MAIN" | "PLUGIN_ETC" | "PLUGIN_DATA" | "" {
|
getFileCategory(filePath: string): "CONFIG" | "THEME" | "SNIPPET" | "PLUGIN_MAIN" | "PLUGIN_ETC" | "PLUGIN_DATA" | "" {
|
||||||
if (filePath.split("/").length == 2 && filePath.endsWith(".json")) return "CONFIG";
|
if (filePath.split("/").length == 2 && filePath.endsWith(".json")) return "CONFIG";
|
||||||
if (filePath.split("/").length == 4 && filePath.startsWith(`${this.app.vault.configDir}/themes/`)) return "THEME";
|
if (filePath.split("/").length == 4 && filePath.startsWith(`${this.app.vault.configDir}/themes/`)) return "THEME";
|
||||||
@@ -164,6 +262,46 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
pluginList.set(this.pluginList)
|
pluginList.set(this.pluginList)
|
||||||
await this.updatePluginList(showMessage);
|
await this.updatePluginList(showMessage);
|
||||||
}
|
}
|
||||||
|
async loadPluginData(path: FilePathWithPrefix): Promise<PluginDataExDisplay | false> {
|
||||||
|
const wx = await this.localDatabase.getDBEntry(path, null, false, false);
|
||||||
|
if (wx) {
|
||||||
|
const data = deserialize(getDocData(wx.data), {}) as PluginDataEx;
|
||||||
|
const xFiles = [] as PluginDataExFile[];
|
||||||
|
for (const file of data.files) {
|
||||||
|
const work = { ...file };
|
||||||
|
const tempStr = getDocData(work.data);
|
||||||
|
work.data = [crc32CKHash(tempStr)];
|
||||||
|
xFiles.push(work);
|
||||||
|
}
|
||||||
|
return ({
|
||||||
|
...data,
|
||||||
|
documentPath: this.getPath(wx),
|
||||||
|
files: xFiles
|
||||||
|
}) as PluginDataExDisplay;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
createMissingConfigurationEntry() {
|
||||||
|
let saveRequired = false;
|
||||||
|
for (const v of this.pluginList) {
|
||||||
|
const key = `${v.category}/${v.name}`;
|
||||||
|
if (!(key in this.plugin.settings.pluginSyncExtendedSetting)) {
|
||||||
|
this.plugin.settings.pluginSyncExtendedSetting[key] = {
|
||||||
|
key,
|
||||||
|
mode: MODE_SELECTIVE,
|
||||||
|
files: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.plugin.settings.pluginSyncExtendedSetting[key].files.sort().join(",").toLowerCase() !=
|
||||||
|
v.files.map(e => e.filename).sort().join(",").toLowerCase()) {
|
||||||
|
this.plugin.settings.pluginSyncExtendedSetting[key].files = v.files.map(e => e.filename).sort();
|
||||||
|
saveRequired = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (saveRequired) {
|
||||||
|
this.plugin.saveSettingData();
|
||||||
|
}
|
||||||
|
}
|
||||||
async updatePluginList(showMessage: boolean, updatedDocumentPath?: FilePathWithPrefix): Promise<void> {
|
async updatePluginList(showMessage: boolean, updatedDocumentPath?: FilePathWithPrefix): Promise<void> {
|
||||||
const logLevel = showMessage ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO;
|
const logLevel = showMessage ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO;
|
||||||
// pluginList.set([]);
|
// pluginList.set([]);
|
||||||
@@ -174,7 +312,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
await Promise.resolve(); // Just to prevent warning.
|
await Promise.resolve(); // Just to prevent warning.
|
||||||
scheduleTask("update-plugin-list-task", 200, async () => {
|
scheduleTask("update-plugin-list-task", 200, async () => {
|
||||||
await runWithLock("update-plugin-list", false, async () => {
|
await serialized("update-plugin-list", async () => {
|
||||||
try {
|
try {
|
||||||
const updatedDocumentId = updatedDocumentPath ? await this.path2id(updatedDocumentPath) : "";
|
const updatedDocumentId = updatedDocumentPath ? await this.path2id(updatedDocumentPath) : "";
|
||||||
const plugins = updatedDocumentPath ?
|
const plugins = updatedDocumentPath ?
|
||||||
@@ -193,22 +331,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
count++;
|
count++;
|
||||||
if (count % 10 == 0) Logger(`Enumerating files... ${count}`, logLevel, "get-plugins");
|
if (count % 10 == 0) Logger(`Enumerating files... ${count}`, logLevel, "get-plugins");
|
||||||
Logger(`plugin-${path}`, LOG_LEVEL_VERBOSE);
|
Logger(`plugin-${path}`, LOG_LEVEL_VERBOSE);
|
||||||
const wx = await this.localDatabase.getDBEntry(path, null, false, false);
|
return this.loadPluginData(path);
|
||||||
if (wx) {
|
|
||||||
const data = deserialize(getDocData(wx.data), {}) as PluginDataEx;
|
|
||||||
const xFiles = [] as PluginDataExFile[];
|
|
||||||
for (const file of data.files) {
|
|
||||||
const work = { ...file };
|
|
||||||
const tempStr = getDocData(work.data);
|
|
||||||
work.data = [crc32CKHash(tempStr)];
|
|
||||||
xFiles.push(work);
|
|
||||||
}
|
|
||||||
return ({
|
|
||||||
...data,
|
|
||||||
documentPath: this.getPath(wx),
|
|
||||||
files: xFiles
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// return entries;
|
// return entries;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
//TODO
|
//TODO
|
||||||
@@ -218,7 +341,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
return false;
|
return false;
|
||||||
}))) {
|
}))) {
|
||||||
if ("ok" in v) {
|
if ("ok" in v) {
|
||||||
if (v.ok != false) {
|
if (v.ok !== false) {
|
||||||
let newList = [...this.pluginList];
|
let newList = [...this.pluginList];
|
||||||
const item = v.ok;
|
const item = v.ok;
|
||||||
newList = newList.filter(x => x.documentPath != item.documentPath);
|
newList = newList.filter(x => x.documentPath != item.documentPath);
|
||||||
@@ -230,10 +353,13 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logger(`All files enumerated`, logLevel, "get-plugins");
|
Logger(`All files enumerated`, logLevel, "get-plugins");
|
||||||
|
pluginIsEnumerating.set(false);
|
||||||
|
this.createMissingConfigurationEntry();
|
||||||
} finally {
|
} finally {
|
||||||
pluginIsEnumerating.set(false);
|
pluginIsEnumerating.set(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
pluginIsEnumerating.set(false);
|
||||||
});
|
});
|
||||||
// return entries;
|
// return entries;
|
||||||
}
|
}
|
||||||
@@ -257,7 +383,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
const fileA = { ...pluginDataA.files[0], ctime: pluginDataA.files[0].mtime, _id: `${pluginDataA.documentPath}` as DocumentID };
|
const fileA = { ...pluginDataA.files[0], ctime: pluginDataA.files[0].mtime, _id: `${pluginDataA.documentPath}` as DocumentID };
|
||||||
const fileB = pluginDataB.files[0];
|
const fileB = pluginDataB.files[0];
|
||||||
const docAx = { ...docA, ...fileA } as LoadedEntry, docBx = { ...docB, ...fileB } as LoadedEntry
|
const docAx = { ...docA, ...fileA } as LoadedEntry, docBx = { ...docB, ...fileB } as LoadedEntry
|
||||||
return runWithLock("config:merge-data", false, () => new Promise((res) => {
|
return serialized("config:merge-data", () => new Promise((res) => {
|
||||||
Logger("Opening data-merging dialog", LOG_LEVEL_VERBOSE);
|
Logger("Opening data-merging dialog", LOG_LEVEL_VERBOSE);
|
||||||
// const docs = [docA, docB];
|
// const docs = [docA, docB];
|
||||||
const path = stripAllPrefixes(docAx.path.split("/").slice(-1).join("/") as FilePath);
|
const path = stripAllPrefixes(docAx.path.split("/").slice(-1).join("/") as FilePath);
|
||||||
@@ -291,10 +417,10 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
const path = `${baseDir}/${f.filename}`;
|
const path = `${baseDir}/${f.filename}`;
|
||||||
await this.ensureDirectoryEx(path);
|
await this.ensureDirectoryEx(path);
|
||||||
if (!content) {
|
if (!content) {
|
||||||
const dt = base64ToArrayBuffer(f.data);
|
const dt = decodeBinary(f.data);
|
||||||
await this.app.vault.adapter.writeBinary(path, dt);
|
await this.vaultAccess.adapterWrite(path, dt);
|
||||||
} else {
|
} else {
|
||||||
await this.app.vault.adapter.write(path, content);
|
await this.vaultAccess.adapterWrite(path, content);
|
||||||
}
|
}
|
||||||
Logger(`Applying ${f.filename} of ${data.displayName || data.name}.. Done`);
|
Logger(`Applying ${f.filename} of ${data.displayName || data.name}.. Done`);
|
||||||
|
|
||||||
@@ -411,15 +537,16 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
this.periodicPluginSweepProcessor.enable(this.settings.autoSweepPluginsPeriodic && !this.settings.watchInternalFileChanges ? (PERIODIC_PLUGIN_SWEEP * 1000) : 0);
|
this.periodicPluginSweepProcessor.enable(this.settings.autoSweepPluginsPeriodic && !this.settings.watchInternalFileChanges ? (PERIODIC_PLUGIN_SWEEP * 1000) : 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
recentProcessedInternalFiles = [] as string[];
|
recentProcessedInternalFiles = [] as string[];
|
||||||
async makeEntryFromFile(path: FilePath): Promise<false | PluginDataExFile> {
|
async makeEntryFromFile(path: FilePath): Promise<false | PluginDataExFile> {
|
||||||
const stat = await this.app.vault.adapter.stat(path);
|
const stat = await this.vaultAccess.adapterStat(path);
|
||||||
let version: string | undefined;
|
let version: string | undefined;
|
||||||
let displayName: string | undefined;
|
let displayName: string | undefined;
|
||||||
if (!stat) {
|
if (!stat) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const contentBin = await this.app.vault.adapter.readBinary(path);
|
const contentBin = await this.vaultAccess.adapterReadBinary(path);
|
||||||
let content: string[];
|
let content: string[];
|
||||||
try {
|
try {
|
||||||
content = await arrayBufferToBase64(contentBin);
|
content = await arrayBufferToBase64(contentBin);
|
||||||
@@ -470,7 +597,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const vf = this.filenameToUnifiedKey(path, term);
|
const vf = this.filenameToUnifiedKey(path, term);
|
||||||
return await runWithLock(`plugin-${vf}`, false, async () => {
|
return await serialized(`plugin-${vf}`, async () => {
|
||||||
const category = this.getFileCategory(path);
|
const category = this.getFileCategory(path);
|
||||||
let mtime = 0;
|
let mtime = 0;
|
||||||
let fileTargets = [] as FilePath[];
|
let fileTargets = [] as FilePath[];
|
||||||
@@ -525,10 +652,10 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = serialize(dt);
|
const content = createTextBlob(serialize(dt));
|
||||||
try {
|
try {
|
||||||
const old = await this.localDatabase.getDBEntryMeta(prefixedFileName, null, false);
|
const old = await this.localDatabase.getDBEntryMeta(prefixedFileName, null, false);
|
||||||
let saveData: LoadedEntry;
|
let saveData: SavingEntry;
|
||||||
if (old === false) {
|
if (old === false) {
|
||||||
saveData = {
|
saveData = {
|
||||||
_id: id,
|
_id: id,
|
||||||
@@ -537,7 +664,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
mtime,
|
mtime,
|
||||||
ctime: mtime,
|
ctime: mtime,
|
||||||
datatype: "newnote",
|
datatype: "newnote",
|
||||||
size: content.length,
|
size: content.size,
|
||||||
children: [],
|
children: [],
|
||||||
deleted: false,
|
deleted: false,
|
||||||
type: "newnote",
|
type: "newnote",
|
||||||
@@ -552,7 +679,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
...old,
|
...old,
|
||||||
data: content,
|
data: content,
|
||||||
mtime,
|
mtime,
|
||||||
size: content.length,
|
size: content.size,
|
||||||
datatype: "newnote",
|
datatype: "newnote",
|
||||||
children: [],
|
children: [],
|
||||||
deleted: false,
|
deleted: false,
|
||||||
@@ -574,10 +701,17 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
async watchVaultRawEventsAsync(path: FilePath) {
|
async watchVaultRawEventsAsync(path: FilePath) {
|
||||||
if (!this.settings.usePluginSync) return false;
|
if (!this.settings.usePluginSync) return false;
|
||||||
if (!this.isTargetPath(path)) return false;
|
if (!this.isTargetPath(path)) return false;
|
||||||
const stat = await this.app.vault.adapter.stat(path);
|
const stat = await this.vaultAccess.adapterStat(path);
|
||||||
// Make sure that target is a file.
|
// Make sure that target is a file.
|
||||||
if (stat && stat.type != "file")
|
if (stat && stat.type != "file")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
const configDir = normalizePath(this.app.vault.configDir);
|
||||||
|
const synchronisedInConfigSync = Object.values(this.settings.pluginSyncExtendedSetting).filter(e => e.mode != MODE_SELECTIVE).map(e => e.files).flat().map(e => `${configDir}/${e}`.toLowerCase());
|
||||||
|
if (synchronisedInConfigSync.some(e => e.startsWith(path.toLowerCase()))) {
|
||||||
|
Logger(`Customization file skipped: ${path}`, LOG_LEVEL_VERBOSE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const storageMTime = ~~((stat && stat.mtime || 0) / 1000);
|
const storageMTime = ~~((stat && stat.mtime || 0) / 1000);
|
||||||
const key = `${path}-${storageMTime}`;
|
const key = `${path}-${storageMTime}`;
|
||||||
if (this.recentProcessedInternalFiles.contains(key)) {
|
if (this.recentProcessedInternalFiles.contains(key)) {
|
||||||
@@ -618,7 +752,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
|
|
||||||
// const id = await this.path2id(prefixedFileName);
|
// const id = await this.path2id(prefixedFileName);
|
||||||
const mtime = new Date().getTime();
|
const mtime = new Date().getTime();
|
||||||
await runWithLock("file-x-" + prefixedFileName, false, async () => {
|
await serialized("file-x-" + prefixedFileName, async () => {
|
||||||
try {
|
try {
|
||||||
const old = await this.localDatabase.getDBEntryMeta(prefixedFileName, null, false) as InternalFileEntry | false;
|
const old = await this.localDatabase.getDBEntryMeta(prefixedFileName, null, false) as InternalFileEntry | false;
|
||||||
let saveData: InternalFileEntry;
|
let saveData: InternalFileEntry;
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { Notice, normalizePath, type PluginManifest } from "./deps";
|
import { normalizePath, type PluginManifest } from "./deps";
|
||||||
import { type EntryDoc, type LoadedEntry, type InternalFileEntry, type FilePathWithPrefix, type FilePath, LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "./lib/src/types";
|
import { type EntryDoc, type LoadedEntry, type InternalFileEntry, type FilePathWithPrefix, type FilePath, LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, MODE_SELECTIVE, MODE_PAUSED, type SavingEntry } from "./lib/src/types";
|
||||||
import { type InternalFileInfo, ICHeader, ICHeaderEnd } from "./types";
|
import { type InternalFileInfo, ICHeader, ICHeaderEnd } from "./types";
|
||||||
import { Parallels, delay, isDocContentSame } from "./lib/src/utils";
|
import { Parallels, createBinaryBlob, delay, isDocContentSame } from "./lib/src/utils";
|
||||||
import { Logger } from "./lib/src/logger";
|
import { Logger } from "./lib/src/logger";
|
||||||
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
||||||
import { disposeMemoObject, memoIfNotExist, memoObject, retrieveMemoObject, scheduleTask, isInternalMetadata, PeriodicProcessor } from "./utils";
|
import { scheduleTask, isInternalMetadata, PeriodicProcessor } from "./utils";
|
||||||
import { WrappedNotice } from "./lib/src/wrapper";
|
import { WrappedNotice } from "./lib/src/wrapper";
|
||||||
import { base64ToArrayBuffer, arrayBufferToBase64 } from "./lib/src/strbin";
|
import { decodeBinary, encodeBinary } from "./lib/src/strbin";
|
||||||
import { runWithLock } from "./lib/src/lock";
|
import { serialized } from "./lib/src/lock";
|
||||||
import { JsonResolveModal } from "./JsonResolveModal";
|
import { JsonResolveModal } from "./JsonResolveModal";
|
||||||
import { LiveSyncCommands } from "./LiveSyncCommands";
|
import { LiveSyncCommands } from "./LiveSyncCommands";
|
||||||
import { addPrefix, stripAllPrefixes } from "./lib/src/path";
|
import { addPrefix, stripAllPrefixes } from "./lib/src/path";
|
||||||
@@ -77,7 +77,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
|
|
||||||
procInternalFiles: string[] = [];
|
procInternalFiles: string[] = [];
|
||||||
async execInternalFile() {
|
async execInternalFile() {
|
||||||
await runWithLock("execInternal", false, async () => {
|
await serialized("execInternal", async () => {
|
||||||
const w = [...this.procInternalFiles];
|
const w = [...this.procInternalFiles];
|
||||||
this.procInternalFiles = [];
|
this.procInternalFiles = [];
|
||||||
Logger(`Applying hidden ${w.length} files change...`);
|
Logger(`Applying hidden ${w.length} files change...`);
|
||||||
@@ -95,7 +95,15 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
recentProcessedInternalFiles = [] as string[];
|
recentProcessedInternalFiles = [] as string[];
|
||||||
async watchVaultRawEventsAsync(path: FilePath) {
|
async watchVaultRawEventsAsync(path: FilePath) {
|
||||||
if (!this.settings.syncInternalFiles) return;
|
if (!this.settings.syncInternalFiles) return;
|
||||||
const stat = await this.app.vault.adapter.stat(path);
|
|
||||||
|
// Exclude files handled by customization sync
|
||||||
|
const configDir = normalizePath(this.app.vault.configDir);
|
||||||
|
const synchronisedInConfigSync = !this.settings.usePluginSync ? [] : Object.values(this.settings.pluginSyncExtendedSetting).filter(e => e.mode == MODE_SELECTIVE || e.mode == MODE_PAUSED).map(e => e.files).flat().map(e => `${configDir}/${e}`.toLowerCase());
|
||||||
|
if (synchronisedInConfigSync.some(e => e.startsWith(path.toLowerCase()))) {
|
||||||
|
Logger(`Hidden file skipped: ${path} is synchronized in customization sync.`, LOG_LEVEL_VERBOSE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const stat = await this.vaultAccess.adapterStat(path);
|
||||||
// sometimes folder is coming.
|
// sometimes folder is coming.
|
||||||
if (stat && stat.type != "file")
|
if (stat && stat.type != "file")
|
||||||
return;
|
return;
|
||||||
@@ -163,12 +171,12 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
if (result) {
|
if (result) {
|
||||||
Logger(`Object merge:${path}`, LOG_LEVEL_INFO);
|
Logger(`Object merge:${path}`, LOG_LEVEL_INFO);
|
||||||
const filename = stripAllPrefixes(path);
|
const filename = stripAllPrefixes(path);
|
||||||
const isExists = await this.app.vault.adapter.exists(filename);
|
const isExists = await this.plugin.vaultAccess.adapterExists(filename);
|
||||||
if (!isExists) {
|
if (!isExists) {
|
||||||
await this.ensureDirectoryEx(filename);
|
await this.ensureDirectoryEx(filename);
|
||||||
}
|
}
|
||||||
await this.app.vault.adapter.write(filename, result);
|
await this.plugin.vaultAccess.adapterWrite(filename, result);
|
||||||
const stat = await this.app.vault.adapter.stat(filename);
|
const stat = await this.vaultAccess.adapterStat(filename);
|
||||||
await this.storeInternalFileToDatabase({ path: filename, ...stat });
|
await this.storeInternalFileToDatabase({ path: filename, ...stat });
|
||||||
await this.extractInternalFileFromDatabase(filename);
|
await this.extractInternalFileFromDatabase(filename);
|
||||||
await this.localDatabase.removeRaw(id, revB);
|
await this.localDatabase.removeRaw(id, revB);
|
||||||
@@ -209,18 +217,24 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Tidy up. Even though it is experimental feature, So dirty...
|
//TODO: Tidy up. Even though it is experimental feature, So dirty...
|
||||||
async syncInternalFilesAndDatabase(direction: "push" | "pull" | "safe" | "pullForce" | "pushForce", showMessage: boolean, files: InternalFileInfo[] | false = false, targetFiles: string[] | false = false) {
|
async syncInternalFilesAndDatabase(direction: "push" | "pull" | "safe" | "pullForce" | "pushForce", showMessage: boolean, filesAll: InternalFileInfo[] | false = false, targetFiles: string[] | false = false) {
|
||||||
await this.resolveConflictOnInternalFiles();
|
await this.resolveConflictOnInternalFiles();
|
||||||
const logLevel = showMessage ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO;
|
const logLevel = showMessage ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO;
|
||||||
Logger("Scanning hidden files.", logLevel, "sync_internal");
|
Logger("Scanning hidden files.", logLevel, "sync_internal");
|
||||||
const ignorePatterns = this.settings.syncInternalFilesIgnorePatterns
|
const ignorePatterns = this.settings.syncInternalFilesIgnorePatterns
|
||||||
.replace(/\n| /g, "")
|
.replace(/\n| /g, "")
|
||||||
.split(",").filter(e => e).map(e => new RegExp(e, "i"));
|
.split(",").filter(e => e).map(e => new RegExp(e, "i"));
|
||||||
if (!files)
|
|
||||||
files = await this.scanInternalFiles();
|
const configDir = normalizePath(this.app.vault.configDir);
|
||||||
|
let files: InternalFileInfo[] =
|
||||||
|
filesAll ? filesAll : (await this.scanInternalFiles())
|
||||||
|
|
||||||
|
const synchronisedInConfigSync = !this.settings.usePluginSync ? [] : Object.values(this.settings.pluginSyncExtendedSetting).filter(e => e.mode == MODE_SELECTIVE || e.mode == MODE_PAUSED).map(e => e.files).flat().map(e => `${configDir}/${e}`.toLowerCase());
|
||||||
|
files = files.filter(file => synchronisedInConfigSync.every(filterFile => !file.path.toLowerCase().startsWith(filterFile)))
|
||||||
|
|
||||||
const filesOnDB = ((await this.localDatabase.allDocsRaw({ startkey: ICHeader, endkey: ICHeaderEnd, include_docs: true })).rows.map(e => e.doc) as InternalFileEntry[]).filter(e => !e.deleted);
|
const filesOnDB = ((await this.localDatabase.allDocsRaw({ startkey: ICHeader, endkey: ICHeaderEnd, include_docs: true })).rows.map(e => e.doc) as InternalFileEntry[]).filter(e => !e.deleted);
|
||||||
const allFileNamesSrc = [...new Set([...files.map(e => normalizePath(e.path)), ...filesOnDB.map(e => stripAllPrefixes(this.getPath(e)))])];
|
const allFileNamesSrc = [...new Set([...files.map(e => normalizePath(e.path)), ...filesOnDB.map(e => stripAllPrefixes(this.getPath(e)))])];
|
||||||
const allFileNames = allFileNamesSrc.filter(filename => !targetFiles || (targetFiles && targetFiles.indexOf(filename) !== -1));
|
const allFileNames = allFileNamesSrc.filter(filename => !targetFiles || (targetFiles && targetFiles.indexOf(filename) !== -1)).filter(path => synchronisedInConfigSync.every(filterFile => !path.toLowerCase().startsWith(filterFile)))
|
||||||
function compareMTime(a: number, b: number) {
|
function compareMTime(a: number, b: number) {
|
||||||
const wa = ~~(a / 1000);
|
const wa = ~~(a / 1000);
|
||||||
const wb = ~~(b / 1000);
|
const wb = ~~(b / 1000);
|
||||||
@@ -274,7 +288,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
if (ignorePatterns.some(e => filename.match(e)))
|
if (ignorePatterns.some(e => filename.match(e)))
|
||||||
continue;
|
continue;
|
||||||
if (await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
if (await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileOnStorage = filename in filesMap ? filesMap[filename] : undefined;
|
const fileOnStorage = filename in filesMap ? filesMap[filename] : undefined;
|
||||||
@@ -335,7 +349,6 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
|
|
||||||
// When files has been retrieved from the database. they must be reloaded.
|
// When files has been retrieved from the database. they must be reloaded.
|
||||||
if ((direction == "pull" || direction == "pullForce") && filesChanged != 0) {
|
if ((direction == "pull" || direction == "pullForce") && filesChanged != 0) {
|
||||||
const configDir = normalizePath(this.app.vault.configDir);
|
|
||||||
// Show notification to restart obsidian when something has been changed in configDir.
|
// Show notification to restart obsidian when something has been changed in configDir.
|
||||||
if (configDir in updatedFolders) {
|
if (configDir in updatedFolders) {
|
||||||
// Numbers of updated files that is below of configDir.
|
// Numbers of updated files that is below of configDir.
|
||||||
@@ -352,44 +365,18 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
updatedCount -= updatedFolders[manifest.dir];
|
updatedCount -= updatedFolders[manifest.dir];
|
||||||
const updatePluginId = manifest.id;
|
const updatePluginId = manifest.id;
|
||||||
const updatePluginName = manifest.name;
|
const updatePluginName = manifest.name;
|
||||||
const fragment = createFragment((doc) => {
|
this.plugin.askInPopup(`updated-${updatePluginId}`, `Files in ${updatePluginName} has been updated, Press {HERE} to reload ${updatePluginName}, or press elsewhere to dismiss this message.`, (anchor) => {
|
||||||
doc.createEl("span", null, (a) => {
|
anchor.text = "HERE";
|
||||||
a.appendText(`Files in ${updatePluginName} has been updated, Press `);
|
anchor.addEventListener("click", async () => {
|
||||||
a.appendChild(a.createEl("a", null, (anchor) => {
|
Logger(`Unloading plugin: ${updatePluginName}`, LOG_LEVEL_NOTICE, "plugin-reload-" + updatePluginId);
|
||||||
anchor.text = "HERE";
|
// @ts-ignore
|
||||||
anchor.addEventListener("click", async () => {
|
await this.app.plugins.unloadPlugin(updatePluginId);
|
||||||
Logger(`Unloading plugin: ${updatePluginName}`, LOG_LEVEL_NOTICE, "plugin-reload-" + updatePluginId);
|
// @ts-ignore
|
||||||
// @ts-ignore
|
await this.app.plugins.loadPlugin(updatePluginId);
|
||||||
await this.app.plugins.unloadPlugin(updatePluginId);
|
Logger(`Plugin reloaded: ${updatePluginName}`, LOG_LEVEL_NOTICE, "plugin-reload-" + updatePluginId);
|
||||||
// @ts-ignore
|
|
||||||
await this.app.plugins.loadPlugin(updatePluginId);
|
|
||||||
Logger(`Plugin reloaded: ${updatePluginName}`, LOG_LEVEL_NOTICE, "plugin-reload-" + updatePluginId);
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
a.appendText(` to reload ${updatePluginName}, or press elsewhere to dismiss this message.`);
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
const updatedPluginKey = "popupUpdated-" + updatePluginId;
|
|
||||||
scheduleTask(updatedPluginKey, 1000, async () => {
|
|
||||||
const popup = await memoIfNotExist(updatedPluginKey, () => new Notice(fragment, 0));
|
|
||||||
//@ts-ignore
|
|
||||||
const isShown = popup?.noticeEl?.isShown();
|
|
||||||
if (!isShown) {
|
|
||||||
memoObject(updatedPluginKey, new Notice(fragment, 0));
|
|
||||||
}
|
|
||||||
scheduleTask(updatedPluginKey + "-close", 20000, () => {
|
|
||||||
const popup = retrieveMemoObject<Notice>(updatedPluginKey);
|
|
||||||
if (!popup)
|
|
||||||
return;
|
|
||||||
//@ts-ignore
|
|
||||||
if (popup?.noticeEl?.isShown()) {
|
|
||||||
popup.hide();
|
|
||||||
}
|
|
||||||
disposeMemoObject(updatedPluginKey);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@@ -400,30 +387,11 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
|
|
||||||
// If something changes left, notify for reloading Obsidian.
|
// If something changes left, notify for reloading Obsidian.
|
||||||
if (updatedCount != 0) {
|
if (updatedCount != 0) {
|
||||||
const fragment = createFragment((doc) => {
|
this.plugin.askInPopup(`updated-any-hidden`, `Hidden files have been synchronized, Press {HERE} to reload Obsidian, or press elsewhere to dismiss this message.`, (anchor) => {
|
||||||
doc.createEl("span", null, (a) => {
|
anchor.text = "HERE";
|
||||||
a.appendText(`Hidden files have been synchronized, Press `);
|
anchor.addEventListener("click", () => {
|
||||||
a.appendChild(a.createEl("a", null, (anchor) => {
|
// @ts-ignore
|
||||||
anchor.text = "HERE";
|
this.app.commands.executeCommandById("app:reload");
|
||||||
anchor.addEventListener("click", () => {
|
|
||||||
// @ts-ignore
|
|
||||||
this.app.commands.executeCommandById("app:reload");
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
a.appendText(` to reload obsidian, or press elsewhere to dismiss this message.`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
scheduleTask("popupUpdated-" + configDir, 1000, () => {
|
|
||||||
//@ts-ignore
|
|
||||||
const isShown = this.confirmPopup?.noticeEl?.isShown();
|
|
||||||
if (!isShown) {
|
|
||||||
this.confirmPopup = new Notice(fragment, 0);
|
|
||||||
}
|
|
||||||
scheduleTask("popupClose" + configDir, 20000, () => {
|
|
||||||
this.confirmPopup?.hide();
|
|
||||||
this.confirmPopup = null;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -437,22 +405,23 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
if (await this.plugin.isIgnoredByIgnoreFiles(file.path)) {
|
if (await this.plugin.isIgnoredByIgnoreFiles(file.path)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = await this.path2id(file.path, ICHeader);
|
const id = await this.path2id(file.path, ICHeader);
|
||||||
const prefixedFileName = addPrefix(file.path, ICHeader);
|
const prefixedFileName = addPrefix(file.path, ICHeader);
|
||||||
const contentBin = await this.app.vault.adapter.readBinary(file.path);
|
const contentBin = await this.plugin.vaultAccess.adapterReadBinary(file.path);
|
||||||
let content: string[];
|
let content: Blob;
|
||||||
try {
|
try {
|
||||||
content = await arrayBufferToBase64(contentBin);
|
content = createBinaryBlob(contentBin);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
Logger(`The file ${file.path} could not be encoded`);
|
Logger(`The file ${file.path} could not be encoded`);
|
||||||
Logger(ex, LOG_LEVEL_VERBOSE);
|
Logger(ex, LOG_LEVEL_VERBOSE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const mtime = file.mtime;
|
const mtime = file.mtime;
|
||||||
return await runWithLock("file-" + prefixedFileName, false, async () => {
|
return await serialized("file-" + prefixedFileName, async () => {
|
||||||
try {
|
try {
|
||||||
const old = await this.localDatabase.getDBEntry(prefixedFileName, null, false, false);
|
const old = await this.localDatabase.getDBEntry(prefixedFileName, null, false, false);
|
||||||
let saveData: LoadedEntry;
|
let saveData: SavingEntry;
|
||||||
if (old === false) {
|
if (old === false) {
|
||||||
saveData = {
|
saveData = {
|
||||||
_id: id,
|
_id: id,
|
||||||
@@ -501,7 +470,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
if (await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
if (await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await runWithLock("file-" + prefixedFileName, false, async () => {
|
await serialized("file-" + prefixedFileName, async () => {
|
||||||
try {
|
try {
|
||||||
const old = await this.localDatabase.getDBEntryMeta(prefixedFileName, null, true) as InternalFileEntry | false;
|
const old = await this.localDatabase.getDBEntryMeta(prefixedFileName, null, true) as InternalFileEntry | false;
|
||||||
let saveData: InternalFileEntry;
|
let saveData: InternalFileEntry;
|
||||||
@@ -542,12 +511,12 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async extractInternalFileFromDatabase(filename: FilePath, force = false) {
|
async extractInternalFileFromDatabase(filename: FilePath, force = false) {
|
||||||
const isExists = await this.app.vault.adapter.exists(filename);
|
const isExists = await this.plugin.vaultAccess.adapterExists(filename);
|
||||||
const prefixedFileName = addPrefix(filename, ICHeader);
|
const prefixedFileName = addPrefix(filename, ICHeader);
|
||||||
if (await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
if (await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return await runWithLock("file-" + prefixedFileName, false, async () => {
|
return await serialized("file-" + prefixedFileName, async () => {
|
||||||
try {
|
try {
|
||||||
// Check conflicted status
|
// Check conflicted status
|
||||||
//TODO option
|
//TODO option
|
||||||
@@ -565,7 +534,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
Logger(`STORAGE <x- DB:${filename}: deleted (hidden) Deleted on DB, but the file is already not found on storage.`);
|
Logger(`STORAGE <x- DB:${filename}: deleted (hidden) Deleted on DB, but the file is already not found on storage.`);
|
||||||
} else {
|
} else {
|
||||||
Logger(`STORAGE <x- DB:${filename}: deleted (hidden).`);
|
Logger(`STORAGE <x- DB:${filename}: deleted (hidden).`);
|
||||||
await this.app.vault.adapter.remove(filename);
|
await this.plugin.vaultAccess.adapterRemove(filename);
|
||||||
try {
|
try {
|
||||||
//@ts-ignore internalAPI
|
//@ts-ignore internalAPI
|
||||||
await this.app.vault.adapter.reconcileInternalFile(filename);
|
await this.app.vault.adapter.reconcileInternalFile(filename);
|
||||||
@@ -578,7 +547,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
if (!isExists) {
|
if (!isExists) {
|
||||||
await this.ensureDirectoryEx(filename);
|
await this.ensureDirectoryEx(filename);
|
||||||
await this.app.vault.adapter.writeBinary(filename, base64ToArrayBuffer(fileOnDB.data), { mtime: fileOnDB.mtime, ctime: fileOnDB.ctime });
|
await this.plugin.vaultAccess.adapterWrite(filename, decodeBinary(fileOnDB.data), { mtime: fileOnDB.mtime, ctime: fileOnDB.ctime });
|
||||||
try {
|
try {
|
||||||
//@ts-ignore internalAPI
|
//@ts-ignore internalAPI
|
||||||
await this.app.vault.adapter.reconcileInternalFile(filename);
|
await this.app.vault.adapter.reconcileInternalFile(filename);
|
||||||
@@ -589,13 +558,13 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
Logger(`STORAGE <-- DB:${filename}: written (hidden,new${force ? ", force" : ""})`);
|
Logger(`STORAGE <-- DB:${filename}: written (hidden,new${force ? ", force" : ""})`);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
const contentBin = await this.app.vault.adapter.readBinary(filename);
|
const contentBin = await this.plugin.vaultAccess.adapterReadBinary(filename);
|
||||||
const content = await arrayBufferToBase64(contentBin);
|
const content = await encodeBinary(contentBin);
|
||||||
if (isDocContentSame(content, fileOnDB.data) && !force) {
|
if (isDocContentSame(content, fileOnDB.data) && !force) {
|
||||||
// Logger(`STORAGE <-- DB:${filename}: skipped (hidden) Not changed`, LOG_LEVEL_VERBOSE);
|
// Logger(`STORAGE <-- DB:${filename}: skipped (hidden) Not changed`, LOG_LEVEL_VERBOSE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
await this.app.vault.adapter.writeBinary(filename, base64ToArrayBuffer(fileOnDB.data), { mtime: fileOnDB.mtime, ctime: fileOnDB.ctime });
|
await this.plugin.vaultAccess.adapterWrite(filename, decodeBinary(fileOnDB.data), { mtime: fileOnDB.mtime, ctime: fileOnDB.ctime });
|
||||||
try {
|
try {
|
||||||
//@ts-ignore internalAPI
|
//@ts-ignore internalAPI
|
||||||
await this.app.vault.adapter.reconcileInternalFile(filename);
|
await this.app.vault.adapter.reconcileInternalFile(filename);
|
||||||
@@ -618,7 +587,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
|
|
||||||
|
|
||||||
showJSONMergeDialogAndMerge(docA: LoadedEntry, docB: LoadedEntry): Promise<boolean> {
|
showJSONMergeDialogAndMerge(docA: LoadedEntry, docB: LoadedEntry): Promise<boolean> {
|
||||||
return runWithLock("conflict:merge-data", false, () => new Promise((res) => {
|
return serialized("conflict:merge-data", () => new Promise((res) => {
|
||||||
Logger("Opening data-merging dialog", LOG_LEVEL_VERBOSE);
|
Logger("Opening data-merging dialog", LOG_LEVEL_VERBOSE);
|
||||||
const docs = [docA, docB];
|
const docs = [docA, docB];
|
||||||
const path = stripAllPrefixes(docA.path);
|
const path = stripAllPrefixes(docA.path);
|
||||||
@@ -644,12 +613,12 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!keep && result) {
|
if (!keep && result) {
|
||||||
const isExists = await this.app.vault.adapter.exists(filename);
|
const isExists = await this.plugin.vaultAccess.adapterExists(filename);
|
||||||
if (!isExists) {
|
if (!isExists) {
|
||||||
await this.ensureDirectoryEx(filename);
|
await this.ensureDirectoryEx(filename);
|
||||||
}
|
}
|
||||||
await this.app.vault.adapter.write(filename, result);
|
await this.plugin.vaultAccess.adapterWrite(filename, result);
|
||||||
const stat = await this.app.vault.adapter.stat(filename);
|
const stat = await this.plugin.vaultAccess.adapterStat(filename);
|
||||||
await this.storeInternalFileToDatabase({ path: filename, ...stat }, true);
|
await this.storeInternalFileToDatabase({ path: filename, ...stat }, true);
|
||||||
try {
|
try {
|
||||||
//@ts-ignore internalAPI
|
//@ts-ignore internalAPI
|
||||||
@@ -676,16 +645,19 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async scanInternalFiles(): Promise<InternalFileInfo[]> {
|
async scanInternalFiles(): Promise<InternalFileInfo[]> {
|
||||||
|
const configDir = normalizePath(this.app.vault.configDir);
|
||||||
const ignoreFilter = this.settings.syncInternalFilesIgnorePatterns
|
const ignoreFilter = this.settings.syncInternalFilesIgnorePatterns
|
||||||
.replace(/\n| /g, "")
|
.replace(/\n| /g, "")
|
||||||
.split(",").filter(e => e).map(e => new RegExp(e, "i"));
|
.split(",").filter(e => e).map(e => new RegExp(e, "i"));
|
||||||
|
const synchronisedInConfigSync = !this.settings.usePluginSync ? [] : Object.values(this.settings.pluginSyncExtendedSetting).filter(e => e.mode == MODE_SELECTIVE || e.mode == MODE_PAUSED).map(e => e.files).flat().map(e => `${configDir}/${e}`.toLowerCase());
|
||||||
const root = this.app.vault.getRoot();
|
const root = this.app.vault.getRoot();
|
||||||
const findRoot = root.path;
|
const findRoot = root.path;
|
||||||
|
|
||||||
const filenames = (await this.getFiles(findRoot, [], null, ignoreFilter)).filter(e => e.startsWith(".")).filter(e => !e.startsWith(".trash"));
|
const filenames = (await this.getFiles(findRoot, [], null, ignoreFilter)).filter(e => e.startsWith(".")).filter(e => !e.startsWith(".trash"));
|
||||||
const files = filenames.map(async (e) => {
|
const files = filenames.filter(path => synchronisedInConfigSync.every(filterFile => !path.toLowerCase().startsWith(filterFile))).map(async (e) => {
|
||||||
return {
|
return {
|
||||||
path: e as FilePath,
|
path: e as FilePath,
|
||||||
stat: await this.app.vault.adapter.stat(e)
|
stat: await this.plugin.vaultAccess.adapterStat(e)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const result: InternalFileInfo[] = [];
|
const result: InternalFileInfo[] = [];
|
||||||
@@ -716,7 +688,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
...w.files
|
...w.files
|
||||||
.filter((e) => !ignoreList.some((ee) => e.endsWith(ee)))
|
.filter((e) => !ignoreList.some((ee) => e.endsWith(ee)))
|
||||||
.filter((e) => !filter || filter.some((ee) => e.match(ee)))
|
.filter((e) => !filter || filter.some((ee) => e.match(ee)))
|
||||||
.filter((e) => !ignoreFilter || ignoreFilter.every((ee) => !e.match(ee))),
|
.filter((e) => !ignoreFilter || ignoreFilter.every((ee) => !e.match(ee)))
|
||||||
];
|
];
|
||||||
let files = [] as string[];
|
let files = [] as string[];
|
||||||
for (const file of filesSrc) {
|
for (const file of filesSrc) {
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { normalizePath, type PluginManifest } from "./deps";
|
import { normalizePath, type PluginManifest } from "./deps";
|
||||||
import type { DocumentID, EntryDoc, FilePathWithPrefix, LoadedEntry } from "./lib/src/types";
|
import type { DocumentID, EntryDoc, FilePathWithPrefix, LoadedEntry, SavingEntry } from "./lib/src/types";
|
||||||
import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "./lib/src/types";
|
import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "./lib/src/types";
|
||||||
import { type PluginDataEntry, PERIODIC_PLUGIN_SWEEP, type PluginList, type DevicePluginList, PSCHeader, PSCHeaderEnd } from "./types";
|
import { type PluginDataEntry, PERIODIC_PLUGIN_SWEEP, type PluginList, type DevicePluginList, PSCHeader, PSCHeaderEnd } from "./types";
|
||||||
import { getDocData, isDocContentSame } from "./lib/src/utils";
|
import { createTextBlob, getDocData, isDocContentSame } from "./lib/src/utils";
|
||||||
import { Logger } from "./lib/src/logger";
|
import { Logger } from "./lib/src/logger";
|
||||||
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
||||||
import { isPluginMetadata, PeriodicProcessor } from "./utils";
|
import { isPluginMetadata, PeriodicProcessor } from "./utils";
|
||||||
import { PluginDialogModal } from "./dialogs";
|
import { PluginDialogModal } from "./dialogs";
|
||||||
import { NewNotice } from "./lib/src/wrapper";
|
import { NewNotice } from "./lib/src/wrapper";
|
||||||
import { versionNumberString2Number } from "./lib/src/strbin";
|
import { versionNumberString2Number } from "./lib/src/strbin";
|
||||||
import { runWithLock } from "./lib/src/lock";
|
import { serialized, skipIfDuplicated } from "./lib/src/lock";
|
||||||
import { LiveSyncCommands } from "./LiveSyncCommands";
|
import { LiveSyncCommands } from "./LiveSyncCommands";
|
||||||
|
|
||||||
export class PluginAndTheirSettings extends LiveSyncCommands {
|
export class PluginAndTheirSettings extends LiveSyncCommands {
|
||||||
@@ -164,7 +164,7 @@ export class PluginAndTheirSettings extends LiveSyncCommands {
|
|||||||
if (specificPluginPath != "") {
|
if (specificPluginPath != "") {
|
||||||
specificPlugin = manifests.find(e => e.dir.endsWith("/" + specificPluginPath))?.id ?? "";
|
specificPlugin = manifests.find(e => e.dir.endsWith("/" + specificPluginPath))?.id ?? "";
|
||||||
}
|
}
|
||||||
await runWithLock("sweepplugin", true, async () => {
|
await skipIfDuplicated("sweepplugin", async () => {
|
||||||
const logLevel = showMessage ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO;
|
const logLevel = showMessage ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO;
|
||||||
if (!this.deviceAndVaultName) {
|
if (!this.deviceAndVaultName) {
|
||||||
Logger("You have to set your device name.", LOG_LEVEL_NOTICE);
|
Logger("You have to set your device name.", LOG_LEVEL_NOTICE);
|
||||||
@@ -186,18 +186,17 @@ export class PluginAndTheirSettings extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
Logger(`Reading plugin:${m.name}(${m.id})`, LOG_LEVEL_VERBOSE);
|
Logger(`Reading plugin:${m.name}(${m.id})`, LOG_LEVEL_VERBOSE);
|
||||||
const path = normalizePath(m.dir) + "/";
|
const path = normalizePath(m.dir) + "/";
|
||||||
const adapter = this.app.vault.adapter;
|
|
||||||
const files = ["manifest.json", "main.js", "styles.css", "data.json"];
|
const files = ["manifest.json", "main.js", "styles.css", "data.json"];
|
||||||
const pluginData: { [key: string]: string; } = {};
|
const pluginData: { [key: string]: string; } = {};
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const thePath = path + file;
|
const thePath = path + file;
|
||||||
if (await adapter.exists(thePath)) {
|
if (await this.plugin.vaultAccess.adapterExists(thePath)) {
|
||||||
pluginData[file] = await adapter.read(thePath);
|
pluginData[file] = await this.plugin.vaultAccess.adapterRead(thePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mtime = 0;
|
let mtime = 0;
|
||||||
if (await adapter.exists(path + "/data.json")) {
|
if (await this.plugin.vaultAccess.adapterExists(path + "/data.json")) {
|
||||||
mtime = (await adapter.stat(path + "/data.json")).mtime;
|
mtime = (await this.plugin.vaultAccess.adapterStat(path + "/data.json")).mtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
const p: PluginDataEntry = {
|
const p: PluginDataEntry = {
|
||||||
@@ -211,19 +210,20 @@ export class PluginAndTheirSettings extends LiveSyncCommands {
|
|||||||
mtime: mtime,
|
mtime: mtime,
|
||||||
type: "plugin",
|
type: "plugin",
|
||||||
};
|
};
|
||||||
const d: LoadedEntry = {
|
const blob = createTextBlob(JSON.stringify(p));
|
||||||
|
const d: SavingEntry = {
|
||||||
_id: p._id,
|
_id: p._id,
|
||||||
path: p._id as string as FilePathWithPrefix,
|
path: p._id as string as FilePathWithPrefix,
|
||||||
data: JSON.stringify(p),
|
data: blob,
|
||||||
ctime: mtime,
|
ctime: mtime,
|
||||||
mtime: mtime,
|
mtime: mtime,
|
||||||
size: 0,
|
size: blob.size,
|
||||||
children: [],
|
children: [],
|
||||||
datatype: "plain",
|
datatype: "plain",
|
||||||
type: "plain"
|
type: "plain"
|
||||||
};
|
};
|
||||||
Logger(`check diff:${m.name}(${m.id})`, LOG_LEVEL_VERBOSE);
|
Logger(`check diff:${m.name}(${m.id})`, LOG_LEVEL_VERBOSE);
|
||||||
await runWithLock("plugin-" + m.id, false, async () => {
|
await serialized("plugin-" + m.id, async () => {
|
||||||
const old = await this.localDatabase.getDBEntry(p._id as string as FilePathWithPrefix /* This also should be explained */, null, false, false);
|
const old = await this.localDatabase.getDBEntry(p._id as string as FilePathWithPrefix /* This also should be explained */, null, false, false);
|
||||||
if (old !== false) {
|
if (old !== false) {
|
||||||
const oldData = { data: old.data, deleted: old._deleted };
|
const oldData = { data: old.data, deleted: old._deleted };
|
||||||
@@ -266,9 +266,8 @@ export class PluginAndTheirSettings extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async applyPluginData(plugin: PluginDataEntry) {
|
async applyPluginData(plugin: PluginDataEntry) {
|
||||||
await runWithLock("plugin-" + plugin.manifest.id, false, async () => {
|
await serialized("plugin-" + plugin.manifest.id, async () => {
|
||||||
const pluginTargetFolderPath = normalizePath(plugin.manifest.dir) + "/";
|
const pluginTargetFolderPath = normalizePath(plugin.manifest.dir) + "/";
|
||||||
const adapter = this.app.vault.adapter;
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const stat = this.app.plugins.enabledPlugins.has(plugin.manifest.id) == true;
|
const stat = this.app.plugins.enabledPlugins.has(plugin.manifest.id) == true;
|
||||||
if (stat) {
|
if (stat) {
|
||||||
@@ -277,7 +276,7 @@ export class PluginAndTheirSettings extends LiveSyncCommands {
|
|||||||
Logger(`Unload plugin:${plugin.manifest.id}`, LOG_LEVEL_NOTICE);
|
Logger(`Unload plugin:${plugin.manifest.id}`, LOG_LEVEL_NOTICE);
|
||||||
}
|
}
|
||||||
if (plugin.dataJson)
|
if (plugin.dataJson)
|
||||||
await adapter.write(pluginTargetFolderPath + "data.json", plugin.dataJson);
|
await this.plugin.vaultAccess.adapterWrite(pluginTargetFolderPath + "data.json", plugin.dataJson);
|
||||||
Logger("wrote:" + pluginTargetFolderPath + "data.json", LOG_LEVEL_NOTICE);
|
Logger("wrote:" + pluginTargetFolderPath + "data.json", LOG_LEVEL_NOTICE);
|
||||||
if (stat) {
|
if (stat) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -288,7 +287,7 @@ export class PluginAndTheirSettings extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async applyPlugin(plugin: PluginDataEntry) {
|
async applyPlugin(plugin: PluginDataEntry) {
|
||||||
await runWithLock("plugin-" + plugin.manifest.id, false, async () => {
|
await serialized("plugin-" + plugin.manifest.id, async () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const stat = this.app.plugins.enabledPlugins.has(plugin.manifest.id) == true;
|
const stat = this.app.plugins.enabledPlugins.has(plugin.manifest.id) == true;
|
||||||
if (stat) {
|
if (stat) {
|
||||||
@@ -298,14 +297,13 @@ export class PluginAndTheirSettings extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pluginTargetFolderPath = normalizePath(plugin.manifest.dir) + "/";
|
const pluginTargetFolderPath = normalizePath(plugin.manifest.dir) + "/";
|
||||||
const adapter = this.app.vault.adapter;
|
if ((await this.plugin.vaultAccess.adapterExists(pluginTargetFolderPath)) === false) {
|
||||||
if ((await adapter.exists(pluginTargetFolderPath)) === false) {
|
await this.app.vault.adapter.mkdir(pluginTargetFolderPath);
|
||||||
await adapter.mkdir(pluginTargetFolderPath);
|
|
||||||
}
|
}
|
||||||
await adapter.write(pluginTargetFolderPath + "main.js", plugin.mainJs);
|
await this.plugin.vaultAccess.adapterWrite(pluginTargetFolderPath + "main.js", plugin.mainJs);
|
||||||
await adapter.write(pluginTargetFolderPath + "manifest.json", plugin.manifestJson);
|
await this.plugin.vaultAccess.adapterWrite(pluginTargetFolderPath + "manifest.json", plugin.manifestJson);
|
||||||
if (plugin.styleCss)
|
if (plugin.styleCss)
|
||||||
await adapter.write(pluginTargetFolderPath + "styles.css", plugin.styleCss);
|
await this.plugin.vaultAccess.adapterWrite(pluginTargetFolderPath + "styles.css", plugin.styleCss);
|
||||||
if (stat) {
|
if (stat) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
await this.app.plugins.loadPlugin(plugin.manifest.id);
|
await this.app.plugins.loadPlugin(plugin.manifest.id);
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ export class SetupLiveSync extends LiveSyncCommands {
|
|||||||
name: "Copy the setup URI",
|
name: "Copy the setup URI",
|
||||||
callback: this.command_copySetupURI.bind(this),
|
callback: this.command_copySetupURI.bind(this),
|
||||||
});
|
});
|
||||||
|
this.plugin.addCommand({
|
||||||
|
id: "livesync-copysetupuri-short",
|
||||||
|
name: "Copy the setup URI (With customization sync)",
|
||||||
|
callback: this.command_copySetupURIWithSync.bind(this),
|
||||||
|
});
|
||||||
|
|
||||||
this.plugin.addCommand({
|
this.plugin.addCommand({
|
||||||
id: "livesync-copysetupurifull",
|
id: "livesync-copysetupurifull",
|
||||||
@@ -41,11 +46,14 @@ export class SetupLiveSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
async realizeSettingSyncMode() { }
|
async realizeSettingSyncMode() { }
|
||||||
|
|
||||||
async command_copySetupURI() {
|
async command_copySetupURI(stripExtra = true) {
|
||||||
const encryptingPassphrase = await askString(this.app, "Encrypt your settings", "The passphrase to encrypt the setup URI", "", true);
|
const encryptingPassphrase = await askString(this.app, "Encrypt your settings", "The passphrase to encrypt the setup URI", "", true);
|
||||||
if (encryptingPassphrase === false)
|
if (encryptingPassphrase === false)
|
||||||
return;
|
return;
|
||||||
const setting = { ...this.settings, configPassphraseStore: "", encryptedCouchDBConnection: "", encryptedPassphrase: "" };
|
const setting = { ...this.settings, configPassphraseStore: "", encryptedCouchDBConnection: "", encryptedPassphrase: "" };
|
||||||
|
if (stripExtra) {
|
||||||
|
delete setting.pluginSyncExtendedSetting;
|
||||||
|
}
|
||||||
const keys = Object.keys(setting) as (keyof ObsidianLiveSyncSettings)[];
|
const keys = Object.keys(setting) as (keyof ObsidianLiveSyncSettings)[];
|
||||||
for (const k of keys) {
|
for (const k of keys) {
|
||||||
if (JSON.stringify(k in setting ? setting[k] : "") == JSON.stringify(k in DEFAULT_SETTINGS ? DEFAULT_SETTINGS[k] : "*")) {
|
if (JSON.stringify(k in setting ? setting[k] : "") == JSON.stringify(k in DEFAULT_SETTINGS ? DEFAULT_SETTINGS[k] : "*")) {
|
||||||
@@ -67,6 +75,9 @@ export class SetupLiveSync extends LiveSyncCommands {
|
|||||||
await navigator.clipboard.writeText(uri);
|
await navigator.clipboard.writeText(uri);
|
||||||
Logger("Setup URI copied to clipboard", LOG_LEVEL_NOTICE);
|
Logger("Setup URI copied to clipboard", LOG_LEVEL_NOTICE);
|
||||||
}
|
}
|
||||||
|
async command_copySetupURIWithSync() {
|
||||||
|
this.command_copySetupURI(false);
|
||||||
|
}
|
||||||
async command_openSetupURI() {
|
async command_openSetupURI() {
|
||||||
const setupURI = await askString(this.app, "Easy setup", "Set up URI", `${configURIBase}aaaaa`);
|
const setupURI = await askString(this.app, "Easy setup", "Set up URI", `${configURIBase}aaaaa`);
|
||||||
if (setupURI === false)
|
if (setupURI === false)
|
||||||
@@ -99,6 +110,7 @@ export class SetupLiveSync extends LiveSyncCommands {
|
|||||||
newSettingW.encryptedCouchDBConnection = "";
|
newSettingW.encryptedCouchDBConnection = "";
|
||||||
const setupJustImport = "Just import setting";
|
const setupJustImport = "Just import setting";
|
||||||
const setupAsNew = "Set it up as secondary or subsequent device";
|
const setupAsNew = "Set it up as secondary or subsequent device";
|
||||||
|
const setupAsMerge = "Secondary device but try keeping local changes";
|
||||||
const setupAgain = "Reconfigure and reconstitute the data";
|
const setupAgain = "Reconfigure and reconstitute the data";
|
||||||
const setupManually = "Leave everything to me";
|
const setupManually = "Leave everything to me";
|
||||||
newSettingW.syncInternalFiles = false;
|
newSettingW.syncInternalFiles = false;
|
||||||
@@ -108,7 +120,7 @@ export class SetupLiveSync extends LiveSyncCommands {
|
|||||||
newSettingW.useIndexedDBAdapter = true;
|
newSettingW.useIndexedDBAdapter = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const setupType = await askSelectString(this.app, "How would you like to set it up?", [setupAsNew, setupAgain, setupJustImport, setupManually]);
|
const setupType = await askSelectString(this.app, "How would you like to set it up?", [setupAsNew, setupAgain, setupAsMerge, setupJustImport, setupManually]);
|
||||||
if (setupType == setupJustImport) {
|
if (setupType == setupJustImport) {
|
||||||
this.plugin.settings = newSettingW;
|
this.plugin.settings = newSettingW;
|
||||||
this.plugin.usedPassphrase = "";
|
this.plugin.usedPassphrase = "";
|
||||||
@@ -117,6 +129,10 @@ export class SetupLiveSync extends LiveSyncCommands {
|
|||||||
this.plugin.settings = newSettingW;
|
this.plugin.settings = newSettingW;
|
||||||
this.plugin.usedPassphrase = "";
|
this.plugin.usedPassphrase = "";
|
||||||
await this.fetchLocal();
|
await this.fetchLocal();
|
||||||
|
} else if (setupType == setupAsMerge) {
|
||||||
|
this.plugin.settings = newSettingW;
|
||||||
|
this.plugin.usedPassphrase = "";
|
||||||
|
await this.fetchLocalWithKeepLocal();
|
||||||
} else if (setupType == setupAgain) {
|
} else if (setupType == setupAgain) {
|
||||||
const confirm = "I know this operation will rebuild all my databases with files on this device, and files that are on the remote database and I didn't synchronize to any other devices will be lost and want to proceed indeed.";
|
const confirm = "I know this operation will rebuild all my databases with files on this device, and files that are on the remote database and I didn't synchronize to any other devices will be lost and want to proceed indeed.";
|
||||||
if (await askSelectString(this.app, "Do you really want to do this?", ["Cancel", confirm]) != confirm) {
|
if (await askSelectString(this.app, "Do you really want to do this?", ["Cancel", confirm]) != confirm) {
|
||||||
@@ -285,6 +301,7 @@ Of course, we are able to disable these features.`
|
|||||||
this.plugin.settings.liveSync = false;
|
this.plugin.settings.liveSync = false;
|
||||||
this.plugin.settings.periodicReplication = false;
|
this.plugin.settings.periodicReplication = false;
|
||||||
this.plugin.settings.syncOnSave = false;
|
this.plugin.settings.syncOnSave = false;
|
||||||
|
this.plugin.settings.syncOnEditorSave = false;
|
||||||
this.plugin.settings.syncOnStart = false;
|
this.plugin.settings.syncOnStart = false;
|
||||||
this.plugin.settings.syncOnFileOpen = false;
|
this.plugin.settings.syncOnFileOpen = false;
|
||||||
this.plugin.settings.syncAfterMerge = false;
|
this.plugin.settings.syncAfterMerge = false;
|
||||||
@@ -302,13 +319,11 @@ Of course, we are able to disable these features.`
|
|||||||
Logger(`Database and storage reflection has been resumed!`, LOG_LEVEL_NOTICE);
|
Logger(`Database and storage reflection has been resumed!`, LOG_LEVEL_NOTICE);
|
||||||
this.plugin.settings.suspendParseReplicationResult = false;
|
this.plugin.settings.suspendParseReplicationResult = false;
|
||||||
this.plugin.settings.suspendFileWatching = false;
|
this.plugin.settings.suspendFileWatching = false;
|
||||||
|
await this.plugin.syncAllFiles(true);
|
||||||
|
await this.plugin.loadQueuedFiles();
|
||||||
|
this.plugin.procQueuedFiles();
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
if (this.plugin.settings.readChunksOnline) {
|
|
||||||
await this.plugin.syncAllFiles(true);
|
|
||||||
await this.plugin.loadQueuedFiles();
|
|
||||||
// Start processing
|
|
||||||
this.plugin.procQueuedFiles();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
async askUseNewAdapter() {
|
async askUseNewAdapter() {
|
||||||
if (!this.plugin.settings.useIndexedDBAdapter) {
|
if (!this.plugin.settings.useIndexedDBAdapter) {
|
||||||
@@ -353,6 +368,25 @@ Of course, we are able to disable these features.`
|
|||||||
await this.resumeReflectingDatabase();
|
await this.resumeReflectingDatabase();
|
||||||
await this.askHiddenFileConfiguration({ enableFetch: true });
|
await this.askHiddenFileConfiguration({ enableFetch: true });
|
||||||
}
|
}
|
||||||
|
async fetchLocalWithKeepLocal() {
|
||||||
|
this.suspendExtraSync();
|
||||||
|
this.askUseNewAdapter();
|
||||||
|
await this.suspendReflectingDatabase();
|
||||||
|
await this.plugin.realizeSettingSyncMode();
|
||||||
|
await this.plugin.resetLocalDatabase();
|
||||||
|
await delay(1000);
|
||||||
|
await this.plugin.initializeDatabase(true);
|
||||||
|
await this.plugin.markRemoteResolved();
|
||||||
|
await this.plugin.openDatabase();
|
||||||
|
this.plugin.isReady = true;
|
||||||
|
await delay(500);
|
||||||
|
await this.plugin.replicateAllFromServer(true);
|
||||||
|
await delay(1000);
|
||||||
|
await this.plugin.replicateAllFromServer(true);
|
||||||
|
await this.fetchRemoteChunks();
|
||||||
|
await this.resumeReflectingDatabase();
|
||||||
|
await this.askHiddenFileConfiguration({ enableFetch: true });
|
||||||
|
}
|
||||||
async rebuildRemote() {
|
async rebuildRemote() {
|
||||||
this.suspendExtraSync();
|
this.suspendExtraSync();
|
||||||
await this.plugin.realizeSettingSyncMode();
|
await this.plugin.realizeSettingSyncMode();
|
||||||
|
|||||||
@@ -18,10 +18,8 @@ export class ConflictResolveModal extends Modal {
|
|||||||
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
const { contentEl } = this;
|
const { contentEl } = this;
|
||||||
|
this.titleEl.setText("Conflicting changes");
|
||||||
contentEl.empty();
|
contentEl.empty();
|
||||||
|
|
||||||
contentEl.createEl("h2", { text: "This document has conflicted changes." });
|
|
||||||
contentEl.createEl("span", { text: this.filename });
|
contentEl.createEl("span", { text: this.filename });
|
||||||
const div = contentEl.createDiv("");
|
const div = contentEl.createDiv("");
|
||||||
div.addClass("op-scrollable");
|
div.addClass("op-scrollable");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { TFile, Modal, App, DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch } from "./deps";
|
import { TFile, Modal, App, DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch } from "./deps";
|
||||||
import { getPathFromTFile, isValidPath } from "./utils";
|
import { getPathFromTFile, isValidPath } from "./utils";
|
||||||
import { base64ToArrayBuffer, base64ToString, escapeStringToHTML } from "./lib/src/strbin";
|
import { decodeBinary, escapeStringToHTML, readString } from "./lib/src/strbin";
|
||||||
import ObsidianLiveSyncPlugin from "./main";
|
import ObsidianLiveSyncPlugin from "./main";
|
||||||
import { type DocumentID, type FilePathWithPrefix, type LoadedEntry, LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "./lib/src/types";
|
import { type DocumentID, type FilePathWithPrefix, type LoadedEntry, LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "./lib/src/types";
|
||||||
import { Logger } from "./lib/src/logger";
|
import { Logger } from "./lib/src/logger";
|
||||||
@@ -10,29 +10,29 @@ import { stripPrefix } from "./lib/src/path";
|
|||||||
|
|
||||||
export class DocumentHistoryModal extends Modal {
|
export class DocumentHistoryModal extends Modal {
|
||||||
plugin: ObsidianLiveSyncPlugin;
|
plugin: ObsidianLiveSyncPlugin;
|
||||||
range: HTMLInputElement;
|
range!: HTMLInputElement;
|
||||||
contentView: HTMLDivElement;
|
contentView!: HTMLDivElement;
|
||||||
info: HTMLDivElement;
|
info!: HTMLDivElement;
|
||||||
fileInfo: HTMLDivElement;
|
fileInfo!: HTMLDivElement;
|
||||||
showDiff = false;
|
showDiff = false;
|
||||||
id: DocumentID;
|
id?: DocumentID;
|
||||||
|
|
||||||
file: FilePathWithPrefix;
|
file: FilePathWithPrefix;
|
||||||
|
|
||||||
revs_info: PouchDB.Core.RevisionInfo[] = [];
|
revs_info: PouchDB.Core.RevisionInfo[] = [];
|
||||||
currentDoc: LoadedEntry;
|
currentDoc?: LoadedEntry;
|
||||||
currentText = "";
|
currentText = "";
|
||||||
currentDeleted = false;
|
currentDeleted = false;
|
||||||
initialRev: string;
|
initialRev?: string;
|
||||||
|
|
||||||
constructor(app: App, plugin: ObsidianLiveSyncPlugin, file: TFile | FilePathWithPrefix, id: DocumentID, revision?: string) {
|
constructor(app: App, plugin: ObsidianLiveSyncPlugin, file: TFile | FilePathWithPrefix, id?: DocumentID, revision?: string) {
|
||||||
super(app);
|
super(app);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.file = (file instanceof TFile) ? getPathFromTFile(file) : file;
|
this.file = (file instanceof TFile) ? getPathFromTFile(file) : file;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.initialRev = revision;
|
this.initialRev = revision;
|
||||||
if (!file) {
|
if (!file && id) {
|
||||||
this.file = this.plugin.id2path(id, null);
|
this.file = this.plugin.id2path(id);
|
||||||
}
|
}
|
||||||
if (localStorage.getItem("ols-history-highlightdiff") == "1") {
|
if (localStorage.getItem("ols-history-highlightdiff") == "1") {
|
||||||
this.showDiff = true;
|
this.showDiff = true;
|
||||||
@@ -46,8 +46,8 @@ export class DocumentHistoryModal extends Modal {
|
|||||||
const db = this.plugin.localDatabase;
|
const db = this.plugin.localDatabase;
|
||||||
try {
|
try {
|
||||||
const w = await db.localDatabase.get(this.id, { revs_info: true });
|
const w = await db.localDatabase.get(this.id, { revs_info: true });
|
||||||
this.revs_info = w._revs_info.filter((e) => e?.status == "available");
|
this.revs_info = w._revs_info?.filter((e) => e?.status == "available") ?? [];
|
||||||
this.range.max = `${this.revs_info.length - 1}`;
|
this.range.max = `${Math.max(this.revs_info.length - 1, 0)}`;
|
||||||
this.range.value = this.range.max;
|
this.range.value = this.range.max;
|
||||||
this.fileInfo.setText(`${this.file} / ${this.revs_info.length} revisions`);
|
this.fileInfo.setText(`${this.file} / ${this.revs_info.length} revisions`);
|
||||||
await this.loadRevs(initialRev);
|
await this.loadRevs(initialRev);
|
||||||
@@ -89,8 +89,8 @@ export class DocumentHistoryModal extends Modal {
|
|||||||
this.currentDoc = w;
|
this.currentDoc = w;
|
||||||
this.info.innerHTML = `Modified:${new Date(w.mtime).toLocaleString()}`;
|
this.info.innerHTML = `Modified:${new Date(w.mtime).toLocaleString()}`;
|
||||||
let result = "";
|
let result = "";
|
||||||
const w1data = w.datatype == "plain" ? getDocData(w.data) : base64ToString(w.data);
|
const w1data = w.datatype == "plain" ? getDocData(w.data) : readString(new Uint8Array(decodeBinary(w.data)));
|
||||||
this.currentDeleted = w.deleted;
|
this.currentDeleted = !!w.deleted;
|
||||||
this.currentText = w1data;
|
this.currentText = w1data;
|
||||||
if (this.showDiff) {
|
if (this.showDiff) {
|
||||||
const prevRevIdx = this.revs_info.length - 1 - ((this.range.value as any) / 1 - 1);
|
const prevRevIdx = this.revs_info.length - 1 - ((this.range.value as any) / 1 - 1);
|
||||||
@@ -99,7 +99,7 @@ export class DocumentHistoryModal extends Modal {
|
|||||||
const w2 = await db.getDBEntry(this.file, { rev: oldRev }, false, false, true);
|
const w2 = await db.getDBEntry(this.file, { rev: oldRev }, false, false, true);
|
||||||
if (w2 != false) {
|
if (w2 != false) {
|
||||||
const dmp = new diff_match_patch();
|
const dmp = new diff_match_patch();
|
||||||
const w2data = w2.datatype == "plain" ? getDocData(w2.data) : base64ToString(w2.data);
|
const w2data = w2.datatype == "plain" ? getDocData(w2.data) : readString(new Uint8Array(decodeBinary(w2.data)));
|
||||||
const diff = dmp.diff_main(w2data, w1data);
|
const diff = dmp.diff_main(w2data, w1data);
|
||||||
dmp.diff_cleanupSemantic(diff);
|
dmp.diff_cleanupSemantic(diff);
|
||||||
for (const v of diff) {
|
for (const v of diff) {
|
||||||
@@ -130,9 +130,8 @@ export class DocumentHistoryModal extends Modal {
|
|||||||
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
const { contentEl } = this;
|
const { contentEl } = this;
|
||||||
|
this.titleEl.setText("Document History");
|
||||||
contentEl.empty();
|
contentEl.empty();
|
||||||
contentEl.createEl("h2", { text: "Document History" });
|
|
||||||
this.fileInfo = contentEl.createDiv("");
|
this.fileInfo = contentEl.createDiv("");
|
||||||
this.fileInfo.addClass("op-info");
|
this.fileInfo.addClass("op-info");
|
||||||
const divView = contentEl.createDiv("");
|
const divView = contentEl.createDiv("");
|
||||||
@@ -201,11 +200,11 @@ export class DocumentHistoryModal extends Modal {
|
|||||||
Logger("Path is not valid to write content.", LOG_LEVEL_INFO);
|
Logger("Path is not valid to write content.", LOG_LEVEL_INFO);
|
||||||
}
|
}
|
||||||
if (this.currentDoc?.datatype == "plain") {
|
if (this.currentDoc?.datatype == "plain") {
|
||||||
await this.app.vault.adapter.write(pathToWrite, getDocData(this.currentDoc.data));
|
await this.plugin.vaultAccess.adapterWrite(pathToWrite, getDocData(this.currentDoc.data));
|
||||||
await focusFile(pathToWrite);
|
await focusFile(pathToWrite);
|
||||||
this.close();
|
this.close();
|
||||||
} else if (this.currentDoc?.datatype == "newnote") {
|
} else if (this.currentDoc?.datatype == "newnote") {
|
||||||
await this.app.vault.adapter.writeBinary(pathToWrite, base64ToArrayBuffer(this.currentDoc.data));
|
await this.plugin.vaultAccess.adapterWrite(pathToWrite, decodeBinary(this.currentDoc.data));
|
||||||
await focusFile(pathToWrite);
|
await focusFile(pathToWrite);
|
||||||
this.close();
|
this.close();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,12 +2,11 @@
|
|||||||
import ObsidianLiveSyncPlugin from "./main";
|
import ObsidianLiveSyncPlugin from "./main";
|
||||||
import { onDestroy, onMount } from "svelte";
|
import { onDestroy, onMount } from "svelte";
|
||||||
import type { AnyEntry, FilePathWithPrefix } from "./lib/src/types";
|
import type { AnyEntry, FilePathWithPrefix } from "./lib/src/types";
|
||||||
import { getDocData, isDocContentSame } from "./lib/src/utils";
|
import { createBinaryBlob, getDocData, isDocContentSame } from "./lib/src/utils";
|
||||||
import { diff_match_patch } from "./deps";
|
import { diff_match_patch } from "./deps";
|
||||||
import { DocumentHistoryModal } from "./DocumentHistoryModal";
|
import { DocumentHistoryModal } from "./DocumentHistoryModal";
|
||||||
import { isPlainText, stripAllPrefixes } from "./lib/src/path";
|
import { isPlainText, stripAllPrefixes } from "./lib/src/path";
|
||||||
import { TFile } from "./deps";
|
import { TFile } from "./deps";
|
||||||
import { arrayBufferToBase64 } from "./lib/src/strbin";
|
|
||||||
export let plugin: ObsidianLiveSyncPlugin;
|
export let plugin: ObsidianLiveSyncPlugin;
|
||||||
|
|
||||||
let showDiffInfo = false;
|
let showDiffInfo = false;
|
||||||
@@ -108,15 +107,15 @@
|
|||||||
}
|
}
|
||||||
if (rev == docA._rev) {
|
if (rev == docA._rev) {
|
||||||
if (checkStorageDiff) {
|
if (checkStorageDiff) {
|
||||||
const abs = plugin.app.vault.getAbstractFileByPath(stripAllPrefixes(plugin.getPath(docA)));
|
const abs = plugin.vaultAccess.getAbstractFileByPath(stripAllPrefixes(plugin.getPath(docA)));
|
||||||
if (abs instanceof TFile) {
|
if (abs instanceof TFile) {
|
||||||
let result = false;
|
let result = false;
|
||||||
if (isPlainText(docA.path)) {
|
if (isPlainText(docA.path)) {
|
||||||
const data = await plugin.app.vault.read(abs);
|
const data = await plugin.vaultAccess.adapterRead(abs);
|
||||||
result = isDocContentSame(data, doc.data);
|
result = isDocContentSame(data, doc.data);
|
||||||
} else {
|
} else {
|
||||||
const data = await plugin.app.vault.readBinary(abs);
|
const data = await plugin.vaultAccess.adapterReadBinary(abs);
|
||||||
const dataEEncoded = await arrayBufferToBase64(data);
|
const dataEEncoded = createBinaryBlob(data);
|
||||||
result = isDocContentSame(dataEEncoded, doc.data);
|
result = isDocContentSame(dataEEncoded, doc.data);
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export class JsonResolveModal extends Modal {
|
|||||||
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
const { contentEl } = this;
|
const { contentEl } = this;
|
||||||
|
this.titleEl.setText("Conflicted Setting");
|
||||||
contentEl.empty();
|
contentEl.empty();
|
||||||
|
|
||||||
if (this.component == null) {
|
if (this.component == null) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { type Diff, DIFF_DELETE, DIFF_INSERT, diff_match_patch } from "./deps";
|
import { type Diff, DIFF_DELETE, DIFF_INSERT, diff_match_patch } from "./deps";
|
||||||
import type { FilePath, LoadedEntry } from "./lib/src/types";
|
import type { FilePath, LoadedEntry } from "./lib/src/types";
|
||||||
import { base64ToString } from "./lib/src/strbin";
|
import { decodeBinary, readString } from "./lib/src/strbin";
|
||||||
import { getDocData } from "./lib/src/utils";
|
import { getDocData } from "./lib/src/utils";
|
||||||
import { mergeObject } from "./utils";
|
import { mergeObject } from "./utils";
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
let mode: SelectModes = defaultSelect as SelectModes;
|
let mode: SelectModes = defaultSelect as SelectModes;
|
||||||
|
|
||||||
function docToString(doc: LoadedEntry) {
|
function docToString(doc: LoadedEntry) {
|
||||||
return doc.datatype == "plain" ? getDocData(doc.data) : base64ToString(doc.data);
|
return doc.datatype == "plain" ? getDocData(doc.data) : readString(new Uint8Array(decodeBinary(doc.data)));
|
||||||
}
|
}
|
||||||
function revStringToRevNumber(rev: string) {
|
function revStringToRevNumber(rev: string) {
|
||||||
return rev.split("-")[0];
|
return rev.split("-")[0];
|
||||||
@@ -104,7 +104,6 @@
|
|||||||
] as ["" | "A" | "B" | "AB" | "BA", string][];
|
] as ["" | "A" | "B" | "AB" | "BA", string][];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1>Conflicted settings</h1>
|
|
||||||
<h2>{filename}</h2>
|
<h2>{filename}</h2>
|
||||||
{#if !docA || !docB}
|
{#if !docA || !docB}
|
||||||
<div class="message">Just for a minute, please!</div>
|
<div class="message">Just for a minute, please!</div>
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ export abstract class LiveSyncCommands {
|
|||||||
get localDatabase() {
|
get localDatabase() {
|
||||||
return this.plugin.localDatabase;
|
return this.plugin.localDatabase;
|
||||||
}
|
}
|
||||||
|
get vaultAccess() {
|
||||||
|
return this.plugin.vaultAccess;
|
||||||
|
}
|
||||||
id2path(id: DocumentID, entry?: EntryHasPath, stripPrefix?: boolean): FilePathWithPrefix {
|
id2path(id: DocumentID, entry?: EntryHasPath, stripPrefix?: boolean): FilePathWithPrefix {
|
||||||
return this.plugin.id2path(id, entry, stripPrefix);
|
return this.plugin.id2path(id, entry, stripPrefix);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ export class LogDisplayModal extends Modal {
|
|||||||
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
const { contentEl } = this;
|
const { contentEl } = this;
|
||||||
|
this.titleEl.setText("Sync status");
|
||||||
|
|
||||||
contentEl.empty();
|
contentEl.empty();
|
||||||
contentEl.createEl("h2", { text: "Sync Status" });
|
|
||||||
const div = contentEl.createDiv("");
|
const div = contentEl.createDiv("");
|
||||||
div.addClass("op-scrollable");
|
div.addClass("op-scrollable");
|
||||||
div.addClass("op-pre");
|
div.addClass("op-pre");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { App, PluginSettingTab, Setting, sanitizeHTMLToDom, TextAreaComponent, MarkdownRenderer, stringifyYaml } from "./deps";
|
import { App, PluginSettingTab, Setting, sanitizeHTMLToDom, TextAreaComponent, MarkdownRenderer, stringifyYaml } from "./deps";
|
||||||
import { DEFAULT_SETTINGS, type ObsidianLiveSyncSettings, type ConfigPassphraseStore, type RemoteDBSettings, type FilePathWithPrefix, type HashAlgorithm, type DocumentID, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "./lib/src/types";
|
import { DEFAULT_SETTINGS, type ObsidianLiveSyncSettings, type ConfigPassphraseStore, type RemoteDBSettings, type FilePathWithPrefix, type HashAlgorithm, type DocumentID, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, LOG_LEVEL_INFO } from "./lib/src/types";
|
||||||
import { delay } from "./lib/src/utils";
|
import { delay } from "./lib/src/utils";
|
||||||
import { Semaphore } from "./lib/src/semaphore";
|
import { Semaphore } from "./lib/src/semaphore";
|
||||||
import { versionNumberString2Number } from "./lib/src/strbin";
|
import { versionNumberString2Number } from "./lib/src/strbin";
|
||||||
@@ -120,6 +120,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
if (this.plugin.settings.periodicReplication) return true;
|
if (this.plugin.settings.periodicReplication) return true;
|
||||||
if (this.plugin.settings.syncOnFileOpen) return true;
|
if (this.plugin.settings.syncOnFileOpen) return true;
|
||||||
if (this.plugin.settings.syncOnSave) return true;
|
if (this.plugin.settings.syncOnSave) return true;
|
||||||
|
if (this.plugin.settings.syncOnEditorSave) return true;
|
||||||
if (this.plugin.settings.syncOnStart) return true;
|
if (this.plugin.settings.syncOnStart) return true;
|
||||||
if (this.plugin.settings.syncAfterMerge) return true;
|
if (this.plugin.settings.syncAfterMerge) return true;
|
||||||
if (this.plugin.replicator.syncStatus == "CONNECTED") return true;
|
if (this.plugin.replicator.syncStatus == "CONNECTED") return true;
|
||||||
@@ -157,6 +158,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
this.plugin.settings.liveSync = false;
|
this.plugin.settings.liveSync = false;
|
||||||
this.plugin.settings.periodicReplication = false;
|
this.plugin.settings.periodicReplication = false;
|
||||||
this.plugin.settings.syncOnSave = false;
|
this.plugin.settings.syncOnSave = false;
|
||||||
|
this.plugin.settings.syncOnEditorSave = false;
|
||||||
this.plugin.settings.syncOnStart = false;
|
this.plugin.settings.syncOnStart = false;
|
||||||
this.plugin.settings.syncOnFileOpen = false;
|
this.plugin.settings.syncOnFileOpen = false;
|
||||||
this.plugin.settings.syncAfterMerge = false;
|
this.plugin.settings.syncAfterMerge = false;
|
||||||
@@ -216,7 +218,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
syncLive.forEach((e) => {
|
syncLive.forEach((e) => {
|
||||||
e.setDisabled(false).setTooltip("");
|
e.setDisabled(false).setTooltip("");
|
||||||
});
|
});
|
||||||
} else if (this.plugin.settings.syncOnFileOpen || this.plugin.settings.syncOnSave || this.plugin.settings.syncOnStart || this.plugin.settings.periodicReplication || this.plugin.settings.syncAfterMerge) {
|
} else if (this.plugin.settings.syncOnFileOpen || this.plugin.settings.syncOnSave || this.plugin.settings.syncOnEditorSave || this.plugin.settings.syncOnStart || this.plugin.settings.periodicReplication || this.plugin.settings.syncAfterMerge) {
|
||||||
syncNonLive.forEach((e) => {
|
syncNonLive.forEach((e) => {
|
||||||
e.setDisabled(false).setTooltip("");
|
e.setDisabled(false).setTooltip("");
|
||||||
});
|
});
|
||||||
@@ -301,46 +303,44 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
.setDisabled(false)
|
.setDisabled(false)
|
||||||
.onClick(async () => {
|
.onClick(async () => {
|
||||||
const checkConfig = async () => {
|
const checkConfig = async () => {
|
||||||
|
Logger(`Checking database configuration`, LOG_LEVEL_INFO);
|
||||||
|
|
||||||
|
const emptyDiv = createDiv();
|
||||||
|
emptyDiv.innerHTML = "<span></span>";
|
||||||
|
checkResultDiv.replaceChildren(...[emptyDiv]);
|
||||||
|
const addResult = (msg: string, classes?: string[]) => {
|
||||||
|
const tmpDiv = createDiv();
|
||||||
|
tmpDiv.addClass("ob-btn-config-fix");
|
||||||
|
if (classes) {
|
||||||
|
tmpDiv.addClasses(classes);
|
||||||
|
}
|
||||||
|
tmpDiv.innerHTML = `${msg}`;
|
||||||
|
checkResultDiv.appendChild(tmpDiv);
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (isCloudantURI(this.plugin.settings.couchDB_URI)) {
|
if (isCloudantURI(this.plugin.settings.couchDB_URI)) {
|
||||||
Logger("This feature cannot be used with IBM Cloudant.", LOG_LEVEL_NOTICE);
|
Logger("This feature cannot be used with IBM Cloudant.", LOG_LEVEL_NOTICE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const r = await requestToCouchDB(this.plugin.settings.couchDB_URI, this.plugin.settings.couchDB_USER, this.plugin.settings.couchDB_PASSWORD, window.origin);
|
const r = await requestToCouchDB(this.plugin.settings.couchDB_URI, this.plugin.settings.couchDB_USER, this.plugin.settings.couchDB_PASSWORD, window.origin);
|
||||||
|
|
||||||
Logger(JSON.stringify(r.json, null, 2));
|
|
||||||
|
|
||||||
const responseConfig = r.json;
|
const responseConfig = r.json;
|
||||||
|
|
||||||
const emptyDiv = createDiv();
|
|
||||||
emptyDiv.innerHTML = "<span></span>";
|
|
||||||
checkResultDiv.replaceChildren(...[emptyDiv]);
|
|
||||||
const addResult = (msg: string, classes?: string[]) => {
|
|
||||||
const tmpDiv = createDiv();
|
|
||||||
tmpDiv.addClass("ob-btn-config-fix");
|
|
||||||
if (classes) {
|
|
||||||
tmpDiv.addClasses(classes);
|
|
||||||
}
|
|
||||||
tmpDiv.innerHTML = `${msg}`;
|
|
||||||
checkResultDiv.appendChild(tmpDiv);
|
|
||||||
};
|
|
||||||
const addConfigFixButton = (title: string, key: string, value: string) => {
|
const addConfigFixButton = (title: string, key: string, value: string) => {
|
||||||
const tmpDiv = createDiv();
|
const tmpDiv = createDiv();
|
||||||
tmpDiv.addClass("ob-btn-config-fix");
|
tmpDiv.addClass("ob-btn-config-fix");
|
||||||
tmpDiv.innerHTML = `<label>${title}</label><button>Fix</button>`;
|
tmpDiv.innerHTML = `<label>${title}</label><button>Fix</button>`;
|
||||||
const x = checkResultDiv.appendChild(tmpDiv);
|
const x = checkResultDiv.appendChild(tmpDiv);
|
||||||
x.querySelector("button").addEventListener("click", async () => {
|
x.querySelector("button").addEventListener("click", async () => {
|
||||||
console.dir({ key, value });
|
Logger(`CouchDB Configuration: ${title} -> Set ${key} to ${value}`)
|
||||||
const res = await requestToCouchDB(this.plugin.settings.couchDB_URI, this.plugin.settings.couchDB_USER, this.plugin.settings.couchDB_PASSWORD, undefined, key, value);
|
const res = await requestToCouchDB(this.plugin.settings.couchDB_URI, this.plugin.settings.couchDB_USER, this.plugin.settings.couchDB_PASSWORD, undefined, key, value);
|
||||||
console.dir(res);
|
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
Logger(`${title} successfully updated`, LOG_LEVEL_NOTICE);
|
Logger(`CouchDB Configuration: ${title} successfully updated`, LOG_LEVEL_NOTICE);
|
||||||
checkResultDiv.removeChild(x);
|
checkResultDiv.removeChild(x);
|
||||||
checkConfig();
|
checkConfig();
|
||||||
} else {
|
} else {
|
||||||
Logger(`${title} failed`, LOG_LEVEL_NOTICE);
|
Logger(`CouchDB Configuration: ${title} failed`, LOG_LEVEL_NOTICE);
|
||||||
Logger(res.text);
|
Logger(res.text, LOG_LEVEL_VERBOSE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -350,7 +350,6 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
["ob-btn-config-info"]
|
["ob-btn-config-info"]
|
||||||
);
|
);
|
||||||
|
|
||||||
addResult("Your configuration is dumped to Log", ["ob-btn-config-info"]);
|
|
||||||
addResult("--Config check--", ["ob-btn-config-head"]);
|
addResult("--Config check--", ["ob-btn-config-head"]);
|
||||||
|
|
||||||
// Admin check
|
// Admin check
|
||||||
@@ -451,9 +450,16 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
}
|
}
|
||||||
addResult("--Done--", ["ob-btn-config-head"]);
|
addResult("--Done--", ["ob-btn-config-head"]);
|
||||||
addResult("If you have some trouble with Connection-check even though all Config-check has been passed, Please check your reverse proxy's configuration.", ["ob-btn-config-info"]);
|
addResult("If you have some trouble with Connection-check even though all Config-check has been passed, Please check your reverse proxy's configuration.", ["ob-btn-config-info"]);
|
||||||
|
Logger(`Checking configuration done`, LOG_LEVEL_INFO);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
Logger(`Checking configuration failed`, LOG_LEVEL_NOTICE);
|
if (ex?.status == 401) {
|
||||||
Logger(ex);
|
addResult(`❗ Access forbidden.`);
|
||||||
|
addResult(`We could not continue the test.`);
|
||||||
|
Logger(`Checking configuration done`, LOG_LEVEL_INFO);
|
||||||
|
} else {
|
||||||
|
Logger(`Checking configuration failed`, LOG_LEVEL_NOTICE);
|
||||||
|
Logger(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await checkConfig();
|
await checkConfig();
|
||||||
@@ -891,6 +897,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
liveSync: false,
|
liveSync: false,
|
||||||
periodicReplication: false,
|
periodicReplication: false,
|
||||||
syncOnSave: false,
|
syncOnSave: false,
|
||||||
|
syncOnEditorSave: false,
|
||||||
syncOnStart: false,
|
syncOnStart: false,
|
||||||
syncOnFileOpen: false,
|
syncOnFileOpen: false,
|
||||||
syncAfterMerge: false,
|
syncAfterMerge: false,
|
||||||
@@ -904,6 +911,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
batchSave: true,
|
batchSave: true,
|
||||||
periodicReplication: true,
|
periodicReplication: true,
|
||||||
syncOnSave: false,
|
syncOnSave: false,
|
||||||
|
syncOnEditorSave: false,
|
||||||
syncOnStart: true,
|
syncOnStart: true,
|
||||||
syncOnFileOpen: true,
|
syncOnFileOpen: true,
|
||||||
syncAfterMerge: true,
|
syncAfterMerge: true,
|
||||||
@@ -1014,6 +1022,17 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
applyDisplayEnabled();
|
applyDisplayEnabled();
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
new Setting(containerSyncSettingEl)
|
||||||
|
.setName("Sync on Editor Save")
|
||||||
|
.setDesc("When you save file on the editor, sync automatically")
|
||||||
|
.setClass("wizardHidden")
|
||||||
|
.addToggle((toggle) =>
|
||||||
|
toggle.setValue(this.plugin.settings.syncOnEditorSave).onChange(async (value) => {
|
||||||
|
this.plugin.settings.syncOnEditorSave = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
applyDisplayEnabled();
|
||||||
|
})
|
||||||
|
)
|
||||||
new Setting(containerSyncSettingEl)
|
new Setting(containerSyncSettingEl)
|
||||||
.setName("Sync on File Open")
|
.setName("Sync on File Open")
|
||||||
.setDesc("When you open file, sync automatically")
|
.setDesc("When you open file, sync automatically")
|
||||||
@@ -1168,26 +1187,27 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
new Setting(containerSyncSettingEl)
|
if (!this.plugin.settings.watchInternalFileChanges) {
|
||||||
.setName("Scan for hidden files before replication")
|
new Setting(containerSyncSettingEl)
|
||||||
.setDesc("This configuration will be ignored if monitoring changes is enabled.")
|
.setName("Scan for hidden files before replication")
|
||||||
.setClass("wizardHidden")
|
.setClass("wizardHidden")
|
||||||
.addToggle((toggle) =>
|
.addToggle((toggle) =>
|
||||||
toggle.setValue(this.plugin.settings.syncInternalFilesBeforeReplication).onChange(async (value) => {
|
toggle.setValue(this.plugin.settings.syncInternalFilesBeforeReplication).onChange(async (value) => {
|
||||||
this.plugin.settings.syncInternalFilesBeforeReplication = value;
|
this.plugin.settings.syncInternalFilesBeforeReplication = value;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
}
|
||||||
new Setting(containerSyncSettingEl)
|
new Setting(containerSyncSettingEl)
|
||||||
.setName("Scan hidden files periodically")
|
.setName("Scan hidden files periodically")
|
||||||
.setDesc("Seconds, 0 to disable. This configuration will be ignored if monitoring changes is enabled.")
|
.setDesc("Seconds, 0 to disable")
|
||||||
.setClass("wizardHidden")
|
.setClass("wizardHidden")
|
||||||
.addText((text) => {
|
.addText((text) => {
|
||||||
text.setPlaceholder("")
|
text.setPlaceholder("")
|
||||||
.setValue(this.plugin.settings.syncInternalFilesInterval + "")
|
.setValue(this.plugin.settings.syncInternalFilesInterval + "")
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
let v = Number(value);
|
let v = Number(value);
|
||||||
if (isNaN(v) || v < 10) {
|
if (v !== 0 && (isNaN(v) || v < 10)) {
|
||||||
v = 10;
|
v = 10;
|
||||||
}
|
}
|
||||||
this.plugin.settings.syncInternalFilesInterval = v;
|
this.plugin.settings.syncInternalFilesInterval = v;
|
||||||
@@ -1199,7 +1219,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
const defaultSkipPattern = "\\/node_modules\\/, \\/\\.git\\/, \\/obsidian-livesync\\/";
|
const defaultSkipPattern = "\\/node_modules\\/, \\/\\.git\\/, \\/obsidian-livesync\\/";
|
||||||
const defaultSkipPatternXPlat = defaultSkipPattern + ",\\/workspace$ ,\\/workspace.json$";
|
const defaultSkipPatternXPlat = defaultSkipPattern + ",\\/workspace$ ,\\/workspace.json$";
|
||||||
new Setting(containerSyncSettingEl)
|
new Setting(containerSyncSettingEl)
|
||||||
.setName("Skip patterns")
|
.setName("Folders and files to ignore")
|
||||||
.setDesc(
|
.setDesc(
|
||||||
"Regular expression, If you use hidden file sync between desktop and mobile, adding `workspace$` is recommended."
|
"Regular expression, If you use hidden file sync between desktop and mobile, adding `workspace$` is recommended."
|
||||||
)
|
)
|
||||||
@@ -1250,7 +1270,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
|
|
||||||
new Setting(containerSyncSettingEl)
|
new Setting(containerSyncSettingEl)
|
||||||
.setName("Enhance chunk size")
|
.setName("Enhance chunk size")
|
||||||
.setDesc("Enhance chunk size for binary files (0.1MBytes). This cannot be increased when using IBM Cloudant.")
|
.setDesc("Enhance chunk size for binary files (Ratio). This cannot be increased when using IBM Cloudant.")
|
||||||
.setClass("wizardHidden")
|
.setClass("wizardHidden")
|
||||||
.addText((text) => {
|
.addText((text) => {
|
||||||
text.setPlaceholder("")
|
text.setPlaceholder("")
|
||||||
@@ -1258,7 +1278,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
let v = Number(value);
|
let v = Number(value);
|
||||||
if (isNaN(v) || v < 1) {
|
if (isNaN(v) || v < 1) {
|
||||||
v = 1;
|
v = 0;
|
||||||
}
|
}
|
||||||
this.plugin.settings.customChunkSize = v;
|
this.plugin.settings.customChunkSize = v;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
@@ -1493,10 +1513,12 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
pluginConfig.passphrase = REDACTED;
|
pluginConfig.passphrase = REDACTED;
|
||||||
pluginConfig.encryptedPassphrase = REDACTED;
|
pluginConfig.encryptedPassphrase = REDACTED;
|
||||||
pluginConfig.encryptedCouchDBConnection = REDACTED;
|
pluginConfig.encryptedCouchDBConnection = REDACTED;
|
||||||
|
pluginConfig.pluginSyncExtendedSetting = {};
|
||||||
|
|
||||||
const msgConfig = `----remote config----
|
const msgConfig = `----remote config----
|
||||||
${stringifyYaml(responseConfig)}
|
${stringifyYaml(responseConfig)}
|
||||||
---- Plug-in config ---
|
---- Plug-in config ---
|
||||||
|
version:${manifestVersion}
|
||||||
${stringifyYaml(pluginConfig)}`;
|
${stringifyYaml(pluginConfig)}`;
|
||||||
console.log(msgConfig);
|
console.log(msgConfig);
|
||||||
await navigator.clipboard.writeText(msgConfig);
|
await navigator.clipboard.writeText(msgConfig);
|
||||||
@@ -1635,6 +1657,22 @@ ${stringifyYaml(pluginConfig)}`;
|
|||||||
}
|
}
|
||||||
Logger(`Converting finished`, LOG_LEVEL_NOTICE);
|
Logger(`Converting finished`, LOG_LEVEL_NOTICE);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
new Setting(containerHatchEl)
|
||||||
|
.setName("Delete all customization sync data")
|
||||||
|
.addButton((button) =>
|
||||||
|
button
|
||||||
|
.setButtonText("Delete")
|
||||||
|
.setDisabled(false)
|
||||||
|
.setWarning()
|
||||||
|
.onClick(async () => {
|
||||||
|
Logger(`Deleting customization sync data`, LOG_LEVEL_NOTICE);
|
||||||
|
const entriesToDelete = (await this.plugin.localDatabase.allDocsRaw({ startkey: "ix:", endkey: "ix:\u{10ffff}", include_docs: true }));
|
||||||
|
const newData = entriesToDelete.rows.map(e => ({ ...e.doc, _deleted: true }));
|
||||||
|
const r = await this.plugin.localDatabase.bulkDocsRaw(newData as any[]);
|
||||||
|
// Do not care about the result.
|
||||||
|
Logger(`${r.length} items have been removed, to confirm how many items are left, please perform it again.`, LOG_LEVEL_NOTICE);
|
||||||
|
}))
|
||||||
new Setting(containerHatchEl)
|
new Setting(containerHatchEl)
|
||||||
.setName("Suspend file watching")
|
.setName("Suspend file watching")
|
||||||
.setDesc("Stop watching for file change.")
|
.setDesc("Stop watching for file change.")
|
||||||
@@ -1777,8 +1815,8 @@ ${stringifyYaml(pluginConfig)}`;
|
|||||||
dropdown
|
dropdown
|
||||||
.addOptions({ "": "Old Algorithm", "xxhash32": "xxhash32 (Fast)", "xxhash64": "xxhash64 (Fastest)" } as Record<HashAlgorithm, string>)
|
.addOptions({ "": "Old Algorithm", "xxhash32": "xxhash32 (Fast)", "xxhash64": "xxhash64 (Fastest)" } as Record<HashAlgorithm, string>)
|
||||||
.setValue(this.plugin.settings.hashAlg)
|
.setValue(this.plugin.settings.hashAlg)
|
||||||
.onChange(async (value: HashAlgorithm) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.hashAlg = value;
|
this.plugin.settings.hashAlg = value as HashAlgorithm;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -1844,16 +1882,18 @@ ${stringifyYaml(pluginConfig)}`;
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
new Setting(containerPluginSettings)
|
if (!this.plugin.settings.watchInternalFileChanges) {
|
||||||
.setName("Scan customization periodically")
|
new Setting(containerPluginSettings)
|
||||||
.setDesc("Scan customization every 1 minute. This configuration will be ignored if monitoring changes of hidden files has been enabled.")
|
.setName("Scan customization periodically")
|
||||||
.addToggle((toggle) =>
|
.setDesc("Scan customization every 1 minute.")
|
||||||
toggle.setValue(this.plugin.settings.autoSweepPluginsPeriodic).onChange(async (value) => {
|
.addToggle((toggle) =>
|
||||||
this.plugin.settings.autoSweepPluginsPeriodic = value;
|
toggle.setValue(this.plugin.settings.autoSweepPluginsPeriodic).onChange(async (value) => {
|
||||||
updateDisabledOfDeviceAndVaultName();
|
this.plugin.settings.autoSweepPluginsPeriodic = value;
|
||||||
await this.plugin.saveSettings();
|
updateDisabledOfDeviceAndVaultName();
|
||||||
})
|
await this.plugin.saveSettings();
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
new Setting(containerPluginSettings)
|
new Setting(containerPluginSettings)
|
||||||
.setName("Notify customized")
|
.setName("Notify customized")
|
||||||
|
|||||||
@@ -108,7 +108,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.reduce((p, c) => p | c, 0);
|
.reduce((p, c) => p | (c as number), 0 as number);
|
||||||
if (matchingStatus == 0b0000100) {
|
if (matchingStatus == 0b0000100) {
|
||||||
equivalency = "⚖️ Same";
|
equivalency = "⚖️ Same";
|
||||||
canApply = false;
|
canApply = false;
|
||||||
@@ -207,21 +207,21 @@
|
|||||||
const local = list.find((e) => e.term == thisTerm);
|
const local = list.find((e) => e.term == thisTerm);
|
||||||
const selectedItem = list.find((e) => e.term == selected);
|
const selectedItem = list.find((e) => e.term == selected);
|
||||||
if (selectedItem && (await applyData(selectedItem))) {
|
if (selectedItem && (await applyData(selectedItem))) {
|
||||||
scheduleTask("update-plugin-list", 250, () => addOn.updatePluginList(true, local.documentPath));
|
addOn.updatePluginList(true, local?.documentPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function compareSelected() {
|
async function compareSelected() {
|
||||||
const local = list.find((e) => e.term == thisTerm);
|
const local = list.find((e) => e.term == thisTerm);
|
||||||
const selectedItem = list.find((e) => e.term == selected);
|
const selectedItem = list.find((e) => e.term == selected);
|
||||||
if (local && selectedItem && (await compareData(local, selectedItem))) {
|
if (local && selectedItem && (await compareData(local, selectedItem))) {
|
||||||
scheduleTask("update-plugin-list", 250, () => addOn.updatePluginList(true, local.documentPath));
|
addOn.updatePluginList(true, local.documentPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function deleteSelected() {
|
async function deleteSelected() {
|
||||||
const selectedItem = list.find((e) => e.term == selected);
|
const selectedItem = list.find((e) => e.term == selected);
|
||||||
// const deletedPath = selectedItem.documentPath;
|
// const deletedPath = selectedItem.documentPath;
|
||||||
if (selectedItem && (await deleteData(selectedItem))) {
|
if (selectedItem && (await deleteData(selectedItem))) {
|
||||||
scheduleTask("update-plugin-list", 250, () => addOn.reloadPluginList(true));
|
addOn.reloadPluginList(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function duplicateItem() {
|
async function duplicateItem() {
|
||||||
@@ -274,7 +274,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<span class="spacer" />
|
<span class="spacer" />
|
||||||
<span class="message even">All devices are even</span>
|
<span class="message even">All the same or non-existent</span>
|
||||||
<button disabled />
|
<button disabled />
|
||||||
<button disabled />
|
<button disabled />
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -3,9 +3,13 @@
|
|||||||
import ObsidianLiveSyncPlugin from "./main";
|
import ObsidianLiveSyncPlugin from "./main";
|
||||||
import { type PluginDataExDisplay, pluginIsEnumerating, pluginList } from "./CmdConfigSync";
|
import { type PluginDataExDisplay, pluginIsEnumerating, pluginList } from "./CmdConfigSync";
|
||||||
import PluginCombo from "./PluginCombo.svelte";
|
import PluginCombo from "./PluginCombo.svelte";
|
||||||
|
import { Menu } from "obsidian";
|
||||||
|
import { unique } from "./lib/src/utils";
|
||||||
|
import { MODE_SELECTIVE, MODE_AUTOMATIC, MODE_PAUSED, type SYNC_MODE, type PluginSyncSettingEntry } from "./lib/src/types";
|
||||||
|
import { normalizePath } from "./deps";
|
||||||
export let plugin: ObsidianLiveSyncPlugin;
|
export let plugin: ObsidianLiveSyncPlugin;
|
||||||
|
|
||||||
$: hideNotApplicable = true;
|
$: hideNotApplicable = false;
|
||||||
$: thisTerm = plugin.deviceAndVaultName;
|
$: thisTerm = plugin.deviceAndVaultName;
|
||||||
|
|
||||||
const addOn = plugin.addOnConfigSync;
|
const addOn = plugin.addOnConfigSync;
|
||||||
@@ -13,7 +17,7 @@
|
|||||||
let list: PluginDataExDisplay[] = [];
|
let list: PluginDataExDisplay[] = [];
|
||||||
|
|
||||||
let selectNewestPulse = 0;
|
let selectNewestPulse = 0;
|
||||||
let hideEven = true;
|
let hideEven = false;
|
||||||
let loading = false;
|
let loading = false;
|
||||||
let applyAllPluse = 0;
|
let applyAllPluse = 0;
|
||||||
let isMaintenanceMode = false;
|
let isMaintenanceMode = false;
|
||||||
@@ -80,6 +84,54 @@
|
|||||||
async function deleteData(data: PluginDataExDisplay): Promise<boolean> {
|
async function deleteData(data: PluginDataExDisplay): Promise<boolean> {
|
||||||
return await addOn.deleteData(data);
|
return await addOn.deleteData(data);
|
||||||
}
|
}
|
||||||
|
function askMode(evt: MouseEvent, title: string, key: string) {
|
||||||
|
const menu = new Menu();
|
||||||
|
menu.addItem((item) => item.setTitle(title).setIsLabel(true));
|
||||||
|
menu.addSeparator();
|
||||||
|
const prevMode = automaticList.get(key) ?? MODE_SELECTIVE;
|
||||||
|
for (const mode of [MODE_SELECTIVE, MODE_AUTOMATIC, MODE_PAUSED]) {
|
||||||
|
menu.addItem((item) => {
|
||||||
|
item.setTitle(`${getIcon(mode as SYNC_MODE)}:${TITLES[mode]}`)
|
||||||
|
.onClick((e) => {
|
||||||
|
if (mode === MODE_AUTOMATIC) {
|
||||||
|
askOverwriteModeForAutomatic(evt, key);
|
||||||
|
} else {
|
||||||
|
setMode(key, mode as SYNC_MODE);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setChecked(prevMode == mode)
|
||||||
|
.setDisabled(prevMode == mode);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
menu.showAtMouseEvent(evt);
|
||||||
|
}
|
||||||
|
function applyAutomaticSync(key: string, direction: "pushForce" | "pullForce" | "safe") {
|
||||||
|
setMode(key, MODE_AUTOMATIC);
|
||||||
|
const configDir = normalizePath(plugin.app.vault.configDir);
|
||||||
|
const files = (plugin.settings.pluginSyncExtendedSetting[key]?.files ?? []).map((e) => `${configDir}/${e}`);
|
||||||
|
plugin.addOnHiddenFileSync.syncInternalFilesAndDatabase(direction, true, false, files);
|
||||||
|
}
|
||||||
|
function askOverwriteModeForAutomatic(evt: MouseEvent, key: string) {
|
||||||
|
const menu = new Menu();
|
||||||
|
menu.addItem((item) => item.setTitle("Initial Action").setIsLabel(true));
|
||||||
|
menu.addSeparator();
|
||||||
|
menu.addItem((item) => {
|
||||||
|
item.setTitle(`↑: Overwrite Remote`).onClick((e) => {
|
||||||
|
applyAutomaticSync(key, "pushForce");
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.addItem((item) => {
|
||||||
|
item.setTitle(`↓: Overwrite Local`).onClick((e) => {
|
||||||
|
applyAutomaticSync(key, "pullForce");
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.addItem((item) => {
|
||||||
|
item.setTitle(`⇅: Use newer`).onClick((e) => {
|
||||||
|
applyAutomaticSync(key, "safe");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
menu.showAtMouseEvent(evt);
|
||||||
|
}
|
||||||
|
|
||||||
$: options = {
|
$: options = {
|
||||||
thisTerm,
|
thisTerm,
|
||||||
@@ -92,11 +144,84 @@
|
|||||||
plugin,
|
plugin,
|
||||||
isMaintenanceMode,
|
isMaintenanceMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ICON_EMOJI_PAUSED = `⛔`;
|
||||||
|
const ICON_EMOJI_AUTOMATIC = `✨`;
|
||||||
|
const ICON_EMOJI_SELECTIVE = `🔀`;
|
||||||
|
|
||||||
|
const ICONS: { [key: number]: string } = {
|
||||||
|
[MODE_SELECTIVE]: ICON_EMOJI_SELECTIVE,
|
||||||
|
[MODE_PAUSED]: ICON_EMOJI_PAUSED,
|
||||||
|
[MODE_AUTOMATIC]: ICON_EMOJI_AUTOMATIC,
|
||||||
|
};
|
||||||
|
const TITLES: { [key: number]: string } = {
|
||||||
|
[MODE_SELECTIVE]: "Selective",
|
||||||
|
[MODE_PAUSED]: "Ignore",
|
||||||
|
[MODE_AUTOMATIC]: "Automatic",
|
||||||
|
};
|
||||||
|
const PREFIX_PLUGIN_ALL = "PLUGIN_ALL";
|
||||||
|
const PREFIX_PLUGIN_DATA = "PLUGIN_DATA";
|
||||||
|
const PREFIX_PLUGIN_MAIN = "PLUGIN_MAIN";
|
||||||
|
function setMode(key: string, mode: SYNC_MODE) {
|
||||||
|
if (key.startsWith(PREFIX_PLUGIN_ALL + "/")) {
|
||||||
|
setMode(PREFIX_PLUGIN_DATA + key.substring(PREFIX_PLUGIN_ALL.length), mode);
|
||||||
|
setMode(PREFIX_PLUGIN_MAIN + key.substring(PREFIX_PLUGIN_ALL.length), mode);
|
||||||
|
}
|
||||||
|
const files = unique(
|
||||||
|
list
|
||||||
|
.filter((e) => `${e.category}/${e.name}` == key)
|
||||||
|
.map((e) => e.files)
|
||||||
|
.flat()
|
||||||
|
.map((e) => e.filename)
|
||||||
|
);
|
||||||
|
automaticList.set(key, mode);
|
||||||
|
automaticListDisp = automaticList;
|
||||||
|
if (!(key in plugin.settings.pluginSyncExtendedSetting)) {
|
||||||
|
plugin.settings.pluginSyncExtendedSetting[key] = {
|
||||||
|
key,
|
||||||
|
mode,
|
||||||
|
files: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
plugin.settings.pluginSyncExtendedSetting[key].files = files;
|
||||||
|
plugin.settings.pluginSyncExtendedSetting[key].mode = mode;
|
||||||
|
plugin.saveSettingData();
|
||||||
|
}
|
||||||
|
function getIcon(mode: SYNC_MODE) {
|
||||||
|
if (mode in ICONS) {
|
||||||
|
return ICONS[mode];
|
||||||
|
} else {
|
||||||
|
("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let automaticList = new Map<string, SYNC_MODE>();
|
||||||
|
let automaticListDisp = new Map<string, SYNC_MODE>();
|
||||||
|
|
||||||
|
// apply current configuration to the dialogue
|
||||||
|
for (const { key, mode } of Object.values(plugin.settings.pluginSyncExtendedSetting)) {
|
||||||
|
automaticList.set(key, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
automaticListDisp = automaticList;
|
||||||
|
|
||||||
|
let displayKeys: Record<string, string[]> = {};
|
||||||
|
|
||||||
|
$: {
|
||||||
|
const extraKeys = Object.keys(plugin.settings.pluginSyncExtendedSetting);
|
||||||
|
displayKeys = [
|
||||||
|
...list,
|
||||||
|
...extraKeys
|
||||||
|
.map((e) => `${e}///`.split("/"))
|
||||||
|
.filter((e) => e[0] && e[1])
|
||||||
|
.map((e) => ({ category: e[0], name: e[1], displayName: e[1] })),
|
||||||
|
]
|
||||||
|
.sort((a, b) => (a.displayName ?? a.name).localeCompare(b.displayName ?? b.name))
|
||||||
|
.reduce((p, c) => ({ ...p, [c.category]: unique(c.category in p ? [...p[c.category], c.displayName ?? c.name] : [c.displayName ?? c.name]) }), {} as Record<string, string[]>);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<h1>Customization sync</h1>
|
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button on:click={() => scanAgain()}>Scan changes</button>
|
<button on:click={() => scanAgain()}>Scan changes</button>
|
||||||
<button on:click={() => replicate()}>Sync once</button>
|
<button on:click={() => replicate()}>Sync once</button>
|
||||||
@@ -119,15 +244,24 @@
|
|||||||
{#if list.length == 0}
|
{#if list.length == 0}
|
||||||
<div class="center">No Items.</div>
|
<div class="center">No Items.</div>
|
||||||
{:else}
|
{:else}
|
||||||
{#each Object.entries(displays) as [key, label]}
|
{#each Object.entries(displays).filter(([key, _]) => key in displayKeys) as [key, label]}
|
||||||
<div>
|
<div>
|
||||||
<h3>{label}</h3>
|
<h3>{label}</h3>
|
||||||
{#each groupBy(filterList(list, [key]), "name") as [name, listX]}
|
{#each displayKeys[key] as name}
|
||||||
|
{@const bindKey = `${key}/${name}`}
|
||||||
|
{@const mode = automaticListDisp.get(bindKey) ?? MODE_SELECTIVE}
|
||||||
<div class="labelrow {hideEven ? 'hideeven' : ''}">
|
<div class="labelrow {hideEven ? 'hideeven' : ''}">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
{name}
|
<button class="status" on:click={(evt) => askMode(evt, `${key}/${name}`, bindKey)}>
|
||||||
|
{getIcon(mode)}
|
||||||
|
</button>
|
||||||
|
<span class="name">{name}</span>
|
||||||
</div>
|
</div>
|
||||||
<PluginCombo {...options} list={listX} hidden={false} />
|
{#if mode == MODE_SELECTIVE}
|
||||||
|
<PluginCombo {...options} list={list.filter((e) => e.category == key && e.name == name)} hidden={false} />
|
||||||
|
{:else}
|
||||||
|
<div class="statusnote">{TITLES[mode]}</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
@@ -135,20 +269,55 @@
|
|||||||
<div>
|
<div>
|
||||||
<h3>Plugins</h3>
|
<h3>Plugins</h3>
|
||||||
{#each groupBy(filterList(list, ["PLUGIN_MAIN", "PLUGIN_DATA", "PLUGIN_ETC"]), "name") as [name, listX]}
|
{#each groupBy(filterList(list, ["PLUGIN_MAIN", "PLUGIN_DATA", "PLUGIN_ETC"]), "name") as [name, listX]}
|
||||||
|
{@const bindKeyAll = `${PREFIX_PLUGIN_ALL}/${name}`}
|
||||||
|
{@const modeAll = automaticListDisp.get(bindKeyAll) ?? MODE_SELECTIVE}
|
||||||
|
{@const bindKeyMain = `${PREFIX_PLUGIN_MAIN}/${name}`}
|
||||||
|
{@const modeMain = automaticListDisp.get(bindKeyMain) ?? MODE_SELECTIVE}
|
||||||
|
{@const bindKeyData = `${PREFIX_PLUGIN_DATA}/${name}`}
|
||||||
|
{@const modeData = automaticListDisp.get(bindKeyData) ?? MODE_SELECTIVE}
|
||||||
<div class="labelrow {hideEven ? 'hideeven' : ''}">
|
<div class="labelrow {hideEven ? 'hideeven' : ''}">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
{name}
|
<button class="status" on:click={(evt) => askMode(evt, `${PREFIX_PLUGIN_ALL}/${name}`, bindKeyAll)}>
|
||||||
|
{getIcon(modeAll)}
|
||||||
|
</button>
|
||||||
|
<span class="name">{name}</span>
|
||||||
</div>
|
</div>
|
||||||
<PluginCombo {...options} list={listX} hidden={true} />
|
{#if modeAll == MODE_SELECTIVE}
|
||||||
</div>
|
<PluginCombo {...options} list={listX} hidden={true} />
|
||||||
<div class="filerow {hideEven ? 'hideeven' : ''}">
|
{/if}
|
||||||
<div class="filetitle">Main</div>
|
|
||||||
<PluginCombo {...options} list={filterList(listX, ["PLUGIN_MAIN"])} hidden={false} />
|
|
||||||
</div>
|
|
||||||
<div class="filerow {hideEven ? 'hideeven' : ''}">
|
|
||||||
<div class="filetitle">Data</div>
|
|
||||||
<PluginCombo {...options} list={filterList(listX, ["PLUGIN_DATA"])} hidden={false} />
|
|
||||||
</div>
|
</div>
|
||||||
|
{#if modeAll == MODE_SELECTIVE}
|
||||||
|
<div class="filerow {hideEven ? 'hideeven' : ''}">
|
||||||
|
<div class="filetitle">
|
||||||
|
<button class="status" on:click={(evt) => askMode(evt, `${PREFIX_PLUGIN_MAIN}/${name}/MAIN`, bindKeyMain)}>
|
||||||
|
{getIcon(modeMain)}
|
||||||
|
</button>
|
||||||
|
<span class="name">MAIN</span>
|
||||||
|
</div>
|
||||||
|
{#if modeMain == MODE_SELECTIVE}
|
||||||
|
<PluginCombo {...options} list={filterList(listX, ["PLUGIN_MAIN"])} hidden={false} />
|
||||||
|
{:else}
|
||||||
|
<div class="statusnote">{TITLES[modeMain]}</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="filerow {hideEven ? 'hideeven' : ''}">
|
||||||
|
<div class="filetitle">
|
||||||
|
<button class="status" on:click={(evt) => askMode(evt, `${PREFIX_PLUGIN_DATA}/${name}`, bindKeyData)}>
|
||||||
|
{getIcon(modeData)}
|
||||||
|
</button>
|
||||||
|
<span class="name">DATA</span>
|
||||||
|
</div>
|
||||||
|
{#if modeData == MODE_SELECTIVE}
|
||||||
|
<PluginCombo {...options} list={filterList(listX, ["PLUGIN_DATA"])} hidden={false} />
|
||||||
|
{:else}
|
||||||
|
<div class="statusnote">{TITLES[modeData]}</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="noterow">
|
||||||
|
<div class="statusnote">{TITLES[modeAll]}</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -162,6 +331,15 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
span.spacer {
|
||||||
|
min-width: 1px;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
h3 {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
background-color: var(--modal-background);
|
||||||
|
}
|
||||||
.labelrow {
|
.labelrow {
|
||||||
margin-left: 0.4em;
|
margin-left: 0.4em;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -183,6 +361,24 @@
|
|||||||
.labelrow.hideeven:has(.even) {
|
.labelrow.hideeven:has(.even) {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
.noterow {
|
||||||
|
min-height: 2em;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
button.status {
|
||||||
|
flex-grow: 0;
|
||||||
|
margin: 2px 4px;
|
||||||
|
min-width: 3em;
|
||||||
|
max-width: 4em;
|
||||||
|
}
|
||||||
|
.statusnote {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
padding-right: var(--size-4-12);
|
||||||
|
align-items: center;
|
||||||
|
min-width: 10em;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
color: var(--text-normal);
|
color: var(--text-normal);
|
||||||
|
|||||||
118
src/SerializedFileAccess.ts
Normal file
118
src/SerializedFileAccess.ts
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
import { type App, TFile, type DataWriteOptions, TFolder, TAbstractFile } from "./deps";
|
||||||
|
import { serialized } from "./lib/src/lock";
|
||||||
|
import type { FilePath } from "./lib/src/types";
|
||||||
|
function getFileLockKey(file: TFile | TFolder | string) {
|
||||||
|
return `fl:${typeof (file) == "string" ? file : file.path}`;
|
||||||
|
}
|
||||||
|
function toArrayBuffer(arr: Uint8Array | ArrayBuffer | DataView): ArrayBufferLike {
|
||||||
|
if (arr instanceof Uint8Array) {
|
||||||
|
return arr.buffer;
|
||||||
|
}
|
||||||
|
if (arr instanceof DataView) {
|
||||||
|
return arr.buffer;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SerializedFileAccess {
|
||||||
|
app: App
|
||||||
|
constructor(app: App) {
|
||||||
|
this.app = app;
|
||||||
|
}
|
||||||
|
|
||||||
|
async adapterStat(file: TFile | string) {
|
||||||
|
const path = file instanceof TFile ? file.path : file;
|
||||||
|
return await serialized(getFileLockKey(path), () => this.app.vault.adapter.stat(path));
|
||||||
|
}
|
||||||
|
async adapterExists(file: TFile | string) {
|
||||||
|
const path = file instanceof TFile ? file.path : file;
|
||||||
|
return await serialized(getFileLockKey(path), () => this.app.vault.adapter.exists(path));
|
||||||
|
}
|
||||||
|
async adapterRemove(file: TFile | string) {
|
||||||
|
const path = file instanceof TFile ? file.path : file;
|
||||||
|
return await serialized(getFileLockKey(path), () => this.app.vault.adapter.remove(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
async adapterRead(file: TFile | string) {
|
||||||
|
const path = file instanceof TFile ? file.path : file;
|
||||||
|
return await serialized(getFileLockKey(path), () => this.app.vault.adapter.read(path));
|
||||||
|
}
|
||||||
|
async adapterReadBinary(file: TFile | string) {
|
||||||
|
const path = file instanceof TFile ? file.path : file;
|
||||||
|
return await serialized(getFileLockKey(path), () => this.app.vault.adapter.readBinary(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
async adapterWrite(file: TFile | string, data: string | ArrayBuffer | Uint8Array, options?: DataWriteOptions) {
|
||||||
|
const path = file instanceof TFile ? file.path : file;
|
||||||
|
if (typeof (data) === "string") {
|
||||||
|
return await serialized(getFileLockKey(path), () => this.app.vault.adapter.write(path, data, options));
|
||||||
|
} else {
|
||||||
|
return await serialized(getFileLockKey(path), () => this.app.vault.adapter.writeBinary(path, toArrayBuffer(data), options));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async vaultCacheRead(file: TFile) {
|
||||||
|
return await serialized(getFileLockKey(file), () => this.app.vault.cachedRead(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
async vaultRead(file: TFile) {
|
||||||
|
return await serialized(getFileLockKey(file), () => this.app.vault.read(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
async vaultReadBinary(file: TFile) {
|
||||||
|
return await serialized(getFileLockKey(file), () => this.app.vault.readBinary(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
async vaultModify(file: TFile, data: string | ArrayBuffer | Uint8Array, options?: DataWriteOptions) {
|
||||||
|
if (typeof (data) === "string") {
|
||||||
|
return await serialized(getFileLockKey(file), () => this.app.vault.modify(file, data, options));
|
||||||
|
} else {
|
||||||
|
return await serialized(getFileLockKey(file), () => this.app.vault.modifyBinary(file, toArrayBuffer(data), options));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async vaultCreate(path: string, data: string | ArrayBuffer | Uint8Array, options?: DataWriteOptions): Promise<TFile> {
|
||||||
|
if (typeof (data) === "string") {
|
||||||
|
return await serialized(getFileLockKey(path), () => this.app.vault.create(path, data, options));
|
||||||
|
} else {
|
||||||
|
return await serialized(getFileLockKey(path), () => this.app.vault.createBinary(path, toArrayBuffer(data), options));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async delete(file: TFile | TFolder, force = false) {
|
||||||
|
return await serialized(getFileLockKey(file), () => this.app.vault.delete(file, force));
|
||||||
|
}
|
||||||
|
async trash(file: TFile | TFolder, force = false) {
|
||||||
|
return await serialized(getFileLockKey(file), () => this.app.vault.trash(file, force));
|
||||||
|
}
|
||||||
|
|
||||||
|
getAbstractFileByPath(path: FilePath | string): TAbstractFile | null {
|
||||||
|
// Disabled temporary.
|
||||||
|
return this.app.vault.getAbstractFileByPath(path);
|
||||||
|
// // Hidden API but so useful.
|
||||||
|
// // @ts-ignore
|
||||||
|
// if ("getAbstractFileByPathInsensitive" in app.vault && (app.vault.adapter?.insensitive ?? false)) {
|
||||||
|
// // @ts-ignore
|
||||||
|
// return app.vault.getAbstractFileByPathInsensitive(path);
|
||||||
|
// } else {
|
||||||
|
// return app.vault.getAbstractFileByPath(path);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
touchedFiles: string[] = [];
|
||||||
|
|
||||||
|
|
||||||
|
touch(file: TFile | FilePath) {
|
||||||
|
const f = file instanceof TFile ? file : this.getAbstractFileByPath(file) as TFile;
|
||||||
|
const key = `${f.path}-${f.stat.mtime}-${f.stat.size}`;
|
||||||
|
this.touchedFiles.unshift(key);
|
||||||
|
this.touchedFiles = this.touchedFiles.slice(0, 100);
|
||||||
|
}
|
||||||
|
recentlyTouched(file: TFile) {
|
||||||
|
const key = `${file.path}-${file.stat.mtime}-${file.stat.size}`;
|
||||||
|
if (this.touchedFiles.indexOf(key) == -1) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
clearTouched() {
|
||||||
|
this.touchedFiles = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
|
import type { SerializedFileAccess } from "./SerializedFileAccess";
|
||||||
import { Plugin, TAbstractFile, TFile, TFolder } from "./deps";
|
import { Plugin, TAbstractFile, TFile, TFolder } from "./deps";
|
||||||
import { isPlainText, shouldBeIgnored } from "./lib/src/path";
|
import { isPlainText, shouldBeIgnored } from "./lib/src/path";
|
||||||
import { getGlobalStore } from "./lib/src/store";
|
import { getGlobalStore } from "./lib/src/store";
|
||||||
import { type FilePath, type ObsidianLiveSyncSettings } from "./lib/src/types";
|
import { type FilePath, type ObsidianLiveSyncSettings } from "./lib/src/types";
|
||||||
import { type FileEventItem, type FileEventType, type FileInfo, type InternalFileInfo, type queueItem } from "./types";
|
import { type FileEventItem, type FileEventType, type FileInfo, type InternalFileInfo, type queueItem } from "./types";
|
||||||
import { recentlyTouched } from "./utils";
|
|
||||||
|
|
||||||
|
|
||||||
export abstract class StorageEventManager {
|
export abstract class StorageEventManager {
|
||||||
@@ -16,9 +16,10 @@ type LiveSyncForStorageEventManager = Plugin &
|
|||||||
{
|
{
|
||||||
settings: ObsidianLiveSyncSettings
|
settings: ObsidianLiveSyncSettings
|
||||||
ignoreFiles: string[],
|
ignoreFiles: string[],
|
||||||
|
vaultAccess: SerializedFileAccess
|
||||||
} & {
|
} & {
|
||||||
isTargetFile: (file: string | TAbstractFile) => Promise<boolean>,
|
isTargetFile: (file: string | TAbstractFile) => Promise<boolean>,
|
||||||
procFileEvent: (applyBatch?: boolean) => Promise<boolean>,
|
procFileEvent: (applyBatch?: boolean) => Promise<any>,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -105,15 +106,14 @@ export class StorageEventManagerObsidian extends StorageEventManager {
|
|||||||
let cache: null | string | ArrayBuffer;
|
let cache: null | string | ArrayBuffer;
|
||||||
// new file or something changed, cache the changes.
|
// new file or something changed, cache the changes.
|
||||||
if (file instanceof TFile && (type == "CREATE" || type == "CHANGED")) {
|
if (file instanceof TFile && (type == "CREATE" || type == "CHANGED")) {
|
||||||
if (recentlyTouched(file)) {
|
if (this.plugin.vaultAccess.recentlyTouched(file)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!isPlainText(file.name)) {
|
if (!isPlainText(file.name)) {
|
||||||
cache = await this.plugin.app.vault.readBinary(file);
|
cache = await this.plugin.vaultAccess.vaultReadBinary(file);
|
||||||
} else {
|
} else {
|
||||||
// cache = await this.app.vault.read(file);
|
cache = await this.plugin.vaultAccess.vaultCacheRead(file);
|
||||||
cache = await this.plugin.app.vault.cachedRead(file);
|
if (!cache) cache = await this.plugin.vaultAccess.vaultRead(file);
|
||||||
if (!cache) cache = await this.plugin.app.vault.read(file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type == "DELETE" || type == "RENAME") {
|
if (type == "DELETE" || type == "RENAME") {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export {
|
|||||||
addIcon, App, debounce, Editor, FuzzySuggestModal, MarkdownRenderer, MarkdownView, Modal, Notice, Platform, Plugin, PluginSettingTab, requestUrl, sanitizeHTMLToDom, Setting, stringifyYaml, TAbstractFile, TextAreaComponent, TFile, TFolder,
|
addIcon, App, debounce, Editor, FuzzySuggestModal, MarkdownRenderer, MarkdownView, Modal, Notice, Platform, Plugin, PluginSettingTab, requestUrl, sanitizeHTMLToDom, Setting, stringifyYaml, TAbstractFile, TextAreaComponent, TFile, TFolder,
|
||||||
parseYaml, ItemView, WorkspaceLeaf
|
parseYaml, ItemView, WorkspaceLeaf
|
||||||
} from "obsidian";
|
} from "obsidian";
|
||||||
export type { DataWriteOptions, PluginManifest, RequestUrlParam, RequestUrlResponse } from "obsidian";
|
export type { DataWriteOptions, PluginManifest, RequestUrlParam, RequestUrlResponse, MarkdownFileInfo } from "obsidian";
|
||||||
import {
|
import {
|
||||||
normalizePath as normalizePath_
|
normalizePath as normalizePath_
|
||||||
} from "obsidian";
|
} from "obsidian";
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export class PluginDialogModal extends Modal {
|
|||||||
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
const { contentEl } = this;
|
const { contentEl } = this;
|
||||||
|
this.titleEl.setText("Customization Sync (Beta2)")
|
||||||
if (this.component == null) {
|
if (this.component == null) {
|
||||||
this.component = new PluginPane({
|
this.component = new PluginPane({
|
||||||
target: contentEl,
|
target: contentEl,
|
||||||
@@ -38,7 +39,7 @@ export class PluginDialogModal extends Modal {
|
|||||||
|
|
||||||
export class InputStringDialog extends Modal {
|
export class InputStringDialog extends Modal {
|
||||||
result: string | false = false;
|
result: string | false = false;
|
||||||
onSubmit: (result: string | boolean) => void;
|
onSubmit: (result: string | false) => void;
|
||||||
title: string;
|
title: string;
|
||||||
key: string;
|
key: string;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
@@ -56,10 +57,8 @@ export class InputStringDialog extends Modal {
|
|||||||
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
const { contentEl } = this;
|
const { contentEl } = this;
|
||||||
|
this.titleEl.setText(this.title);
|
||||||
contentEl.createEl("h1", { text: this.title });
|
const formEl = contentEl.createDiv();
|
||||||
// For enter to submit
|
|
||||||
const formEl = contentEl.createEl("form");
|
|
||||||
new Setting(formEl).setName(this.key).setClass(this.isPassword ? "password-input" : "normal-input").addText((text) =>
|
new Setting(formEl).setName(this.key).setClass(this.isPassword ? "password-input" : "normal-input").addText((text) =>
|
||||||
text.onChange((value) => {
|
text.onChange((value) => {
|
||||||
this.result = value;
|
this.result = value;
|
||||||
@@ -144,7 +143,7 @@ export class MessageBox extends Modal {
|
|||||||
timer: ReturnType<typeof setInterval> = undefined;
|
timer: ReturnType<typeof setInterval> = undefined;
|
||||||
defaultButtonComponent: ButtonComponent | undefined;
|
defaultButtonComponent: ButtonComponent | undefined;
|
||||||
|
|
||||||
onSubmit: (result: string | boolean) => void;
|
onSubmit: (result: string | false) => void;
|
||||||
|
|
||||||
constructor(plugin: Plugin, title: string, contentMd: string, buttons: string[], defaultAction: (typeof buttons)[number], timeout: number, onSubmit: (result: (typeof buttons)[number] | false) => void) {
|
constructor(plugin: Plugin, title: string, contentMd: string, buttons: string[], defaultAction: (typeof buttons)[number], timeout: number, onSubmit: (result: (typeof buttons)[number] | false) => void) {
|
||||||
super(plugin.app);
|
super(plugin.app);
|
||||||
@@ -175,13 +174,13 @@ export class MessageBox extends Modal {
|
|||||||
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
const { contentEl } = this;
|
const { contentEl } = this;
|
||||||
|
this.titleEl.setText(this.title);
|
||||||
contentEl.addEventListener("click", () => {
|
contentEl.addEventListener("click", () => {
|
||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
clearInterval(this.timer);
|
clearInterval(this.timer);
|
||||||
this.timer = undefined;
|
this.timer = undefined;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
contentEl.createEl("h1", { text: this.title });
|
|
||||||
const div = contentEl.createDiv();
|
const div = contentEl.createDiv();
|
||||||
MarkdownRenderer.render(this.plugin.app, this.contentMd, div, "/", this.plugin);
|
MarkdownRenderer.render(this.plugin.app, this.contentMd, div, "/", this.plugin);
|
||||||
const buttonSetting = new Setting(contentEl);
|
const buttonSetting = new Setting(contentEl);
|
||||||
|
|||||||
2
src/lib
2
src/lib
Submodule src/lib updated: 8872807f47...7e79c27035
589
src/main.ts
589
src/main.ts
File diff suppressed because it is too large
Load Diff
54
src/utils.ts
54
src/utils.ts
@@ -1,11 +1,12 @@
|
|||||||
import { type DataWriteOptions, normalizePath, TFile, Platform, TAbstractFile, App, Plugin, type RequestUrlParam, requestUrl } from "./deps";
|
import { normalizePath, TFile, Platform, TAbstractFile, App, Plugin, type RequestUrlParam, requestUrl } from "./deps";
|
||||||
import { path2id_base, id2path_base, isValidFilenameInLinux, isValidFilenameInDarwin, isValidFilenameInWidows, isValidFilenameInAndroid, stripAllPrefixes } from "./lib/src/path";
|
import { path2id_base, id2path_base, isValidFilenameInLinux, isValidFilenameInDarwin, isValidFilenameInWidows, isValidFilenameInAndroid, stripAllPrefixes } from "./lib/src/path";
|
||||||
|
|
||||||
import { Logger } from "./lib/src/logger";
|
import { Logger } from "./lib/src/logger";
|
||||||
import { LOG_LEVEL_VERBOSE, type AnyEntry, type DocumentID, type EntryHasPath, type FilePath, type FilePathWithPrefix } from "./lib/src/types";
|
import { LOG_LEVEL_VERBOSE, type AnyEntry, type DocumentID, type EntryHasPath, type FilePath, type FilePathWithPrefix } from "./lib/src/types";
|
||||||
import { CHeader, ICHeader, ICHeaderLength, PSCHeader } from "./types";
|
import { CHeader, ICHeader, ICHeaderLength, ICXHeader, PSCHeader } from "./types";
|
||||||
import { InputStringDialog, PopoverSelectString } from "./dialogs";
|
import { InputStringDialog, PopoverSelectString } from "./dialogs";
|
||||||
import ObsidianLiveSyncPlugin from "./main";
|
import ObsidianLiveSyncPlugin from "./main";
|
||||||
|
import { writeString } from "./lib/src/strbin";
|
||||||
|
|
||||||
// For backward compatibility, using the path for determining id.
|
// For backward compatibility, using the path for determining id.
|
||||||
// Only CouchDB unacceptable ID (that starts with an underscore) has been prefixed with "/".
|
// Only CouchDB unacceptable ID (that starts with an underscore) has been prefixed with "/".
|
||||||
@@ -302,20 +303,6 @@ export function flattenObject(obj: Record<string | number | symbol, any>, path:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function modifyFile(file: TFile, data: string | ArrayBuffer, options?: DataWriteOptions) {
|
|
||||||
if (typeof (data) === "string") {
|
|
||||||
return app.vault.modify(file, data, options);
|
|
||||||
} else {
|
|
||||||
return app.vault.modifyBinary(file, data, options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export function createFile(path: string, data: string | ArrayBuffer, options?: DataWriteOptions): Promise<TFile> {
|
|
||||||
if (typeof (data) === "string") {
|
|
||||||
return app.vault.create(path, data, options);
|
|
||||||
} else {
|
|
||||||
return app.vault.createBinary(path, data, options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isValidPath(filename: string) {
|
export function isValidPath(filename: string) {
|
||||||
if (Platform.isDesktop) {
|
if (Platform.isDesktop) {
|
||||||
@@ -331,38 +318,10 @@ export function isValidPath(filename: string) {
|
|||||||
return isValidFilenameInWidows(filename);
|
return isValidFilenameInWidows(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
let touchedFiles: string[] = [];
|
|
||||||
|
|
||||||
export function getAbstractFileByPath(path: FilePath): TAbstractFile | null {
|
|
||||||
// Disabled temporary.
|
|
||||||
return app.vault.getAbstractFileByPath(path);
|
|
||||||
// // Hidden API but so useful.
|
|
||||||
// // @ts-ignore
|
|
||||||
// if ("getAbstractFileByPathInsensitive" in app.vault && (app.vault.adapter?.insensitive ?? false)) {
|
|
||||||
// // @ts-ignore
|
|
||||||
// return app.vault.getAbstractFileByPathInsensitive(path);
|
|
||||||
// } else {
|
|
||||||
// return app.vault.getAbstractFileByPath(path);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
export function trimPrefix(target: string, prefix: string) {
|
export function trimPrefix(target: string, prefix: string) {
|
||||||
return target.startsWith(prefix) ? target.substring(prefix.length) : target;
|
return target.startsWith(prefix) ? target.substring(prefix.length) : target;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function touch(file: TFile | FilePath) {
|
|
||||||
const f = file instanceof TFile ? file : getAbstractFileByPath(file) as TFile;
|
|
||||||
const key = `${f.path}-${f.stat.mtime}-${f.stat.size}`;
|
|
||||||
touchedFiles.unshift(key);
|
|
||||||
touchedFiles = touchedFiles.slice(0, 100);
|
|
||||||
}
|
|
||||||
export function recentlyTouched(file: TFile) {
|
|
||||||
const key = `${file.path}-${file.stat.mtime}-${file.stat.size}`;
|
|
||||||
if (touchedFiles.indexOf(key) == -1) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
export function clearTouched() {
|
|
||||||
touchedFiles = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns is internal chunk of file
|
* returns is internal chunk of file
|
||||||
@@ -387,6 +346,9 @@ export function isChunk(str: string): boolean {
|
|||||||
export function isPluginMetadata(str: string): boolean {
|
export function isPluginMetadata(str: string): boolean {
|
||||||
return str.startsWith(PSCHeader);
|
return str.startsWith(PSCHeader);
|
||||||
}
|
}
|
||||||
|
export function isCustomisationSyncMetadata(str: string): boolean {
|
||||||
|
return str.startsWith(ICXHeader);
|
||||||
|
}
|
||||||
|
|
||||||
export const askYesNo = (app: App, message: string): Promise<"yes" | "no"> => {
|
export const askYesNo = (app: App, message: string): Promise<"yes" | "no"> => {
|
||||||
return new Promise((res) => {
|
return new Promise((res) => {
|
||||||
@@ -440,7 +402,7 @@ export class PeriodicProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const _requestToCouchDBFetch = async (baseUri: string, username: string, password: string, path?: string, body?: string | any, method?: string) => {
|
export const _requestToCouchDBFetch = async (baseUri: string, username: string, password: string, path?: string, body?: string | any, method?: string) => {
|
||||||
const utf8str = String.fromCharCode.apply(null, new TextEncoder().encode(`${username}:${password}`));
|
const utf8str = String.fromCharCode.apply(null, [...writeString(`${username}:${password}`)]);
|
||||||
const encoded = window.btoa(utf8str);
|
const encoded = window.btoa(utf8str);
|
||||||
const authHeader = "Basic " + encoded;
|
const authHeader = "Basic " + encoded;
|
||||||
const transformedHeaders: Record<string, string> = { authorization: authHeader, "content-type": "application/json" };
|
const transformedHeaders: Record<string, string> = { authorization: authHeader, "content-type": "application/json" };
|
||||||
@@ -456,7 +418,7 @@ export const _requestToCouchDBFetch = async (baseUri: string, username: string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const _requestToCouchDB = async (baseUri: string, username: string, password: string, origin: string, path?: string, body?: any, method?: string) => {
|
export const _requestToCouchDB = async (baseUri: string, username: string, password: string, origin: string, path?: string, body?: any, method?: string) => {
|
||||||
const utf8str = String.fromCharCode.apply(null, new TextEncoder().encode(`${username}:${password}`));
|
const utf8str = String.fromCharCode.apply(null, [...writeString(`${username}:${password}`)]);
|
||||||
const encoded = window.btoa(utf8str);
|
const encoded = window.btoa(utf8str);
|
||||||
const authHeader = "Basic " + encoded;
|
const authHeader = "Basic " + encoded;
|
||||||
const transformedHeaders: Record<string, string> = { authorization: authHeader, origin: origin };
|
const transformedHeaders: Record<string, string> = { authorization: authHeader, origin: origin };
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
// "importsNotUsedAsValues": "error",
|
// "importsNotUsedAsValues": "error",
|
||||||
"importHelpers": false,
|
"importHelpers": false,
|
||||||
"alwaysStrict": true,
|
"alwaysStrict": true,
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
"lib": [
|
"lib": [
|
||||||
"es2018",
|
"es2018",
|
||||||
"DOM",
|
"DOM",
|
||||||
|
|||||||
69
updates.md
69
updates.md
@@ -1,50 +1,31 @@
|
|||||||
### 0.19.0
|
### 0.21.0
|
||||||
|
The E2EE encryption V2 format has been reverted. That was probably the cause of the glitch.
|
||||||
#### Customization sync
|
Instead, to maintain efficiency, files are treated with Blob until just before saving. Along with this, the old-fashioned encryption format has also been discontinued.
|
||||||
|
There are both forward and backwards compatibilities, with recent versions. However, unfortunately, we lost compatibility with filesystem-livesync or some.
|
||||||
Since `Plugin and their settings` have been broken, so I tried to fix it, not just fix it, but fix it the way it should be.
|
It will be addressed soon. Please be patient if you are using filesystem-livesync with E2EE.
|
||||||
|
|
||||||
Now, we have `Customization sync`.
|
|
||||||
|
|
||||||
It is a real shame that the compatibility between these features has been broken. However, this new feature is surely useful and I believe that worth getting over the pain.
|
|
||||||
We can use the new feature with the same configuration. Only the menu on the command palette has been changed. The dialog can be opened by `Show customization sync dialog`.
|
|
||||||
|
|
||||||
I hope you will give it a try.
|
|
||||||
|
|
||||||
|
|
||||||
#### Minors
|
#### Version history
|
||||||
|
- 0.21.2
|
||||||
- 0.19.1 to 0.19.14 has been moved into the updates_old.md
|
- IMPORTANT NOTICE: **0.21.1 CONTAINS A BUG WHILE REBUILDING THE DATABASE. IF YOU HAVE BEEN REBUILT, PLEASE MAKE SURE THAT ALL FILES ARE SANE.**
|
||||||
- 0.19.15
|
- This has been fixed in this version.
|
||||||
- Fixed:
|
- Fixed:
|
||||||
- Now storing files after cleaning up is correct works.
|
- No longer files are broken while rebuilding.
|
||||||
- Improved:
|
- Now, Large binary files can be written correctly on a mobile platform.
|
||||||
- Cleaning the local database up got incredibly fastened.
|
- Any decoding errors now make zero-byte files.
|
||||||
Now we can clean instead of fetching again when synchronising with the remote which has been cleaned up.
|
- Modified:
|
||||||
- 0.19.16
|
- All files are processed sequentially for each.
|
||||||
- Many upgrades on this release. I have tried not to let that happen, if something got corrupted, please feel free to notify me.
|
- 0.21.1
|
||||||
- New feature:
|
|
||||||
- (Beta) ignore files handling
|
|
||||||
We can use `.gitignore`, `.dockerignore`, and anything you like to filter the synchronising files.
|
|
||||||
- Fixed:
|
- Fixed:
|
||||||
- Buttons on lock-detected-dialogue now can be shown in narrow-width devices.
|
- No more infinity loops on larger files.
|
||||||
- Improved:
|
- Show message on decode error.
|
||||||
- Some constant has been flattened to be evaluated.
|
- Refactored:
|
||||||
- The usage of the deprecated API of obsidian has been reduced.
|
- Fixed to avoid obsolete global variables.
|
||||||
- Now the indexedDB adapter will be enabled while the importing configuration.
|
- 0.21.0
|
||||||
- Misc:
|
- Changes and performance improvements:
|
||||||
- Compiler, framework, and dependencies have been upgraded.
|
- Now the saving files are processed by Blob.
|
||||||
- Due to standing for these impacts (especially in esbuild and svelte,) terser has been introduced.
|
- The V2-Format has been reverted.
|
||||||
Feel free to notify your opinion to me! I do not like to obfuscate the code too.
|
- New encoding format has been enabled in default.
|
||||||
- 0.19.17
|
- WARNING: Since this version, the compatibilities with older Filesystem LiveSync have been lost.
|
||||||
- Fixed:
|
|
||||||
- Now nested ignore files could be parsed correctly.
|
|
||||||
- The unexpected deletion of hidden files in some cases has been corrected.
|
|
||||||
- Hidden file change is no longer reflected on the device which has made the change itself.
|
|
||||||
- Behaviour changed:
|
|
||||||
- From this version, the file which has `:` in its name should be ignored even if on Linux devices.
|
|
||||||
- 0.19.18
|
|
||||||
- Fixed:
|
|
||||||
- Now the empty (or deleted) file could be conflict-resolved.
|
|
||||||
|
|
||||||
... To continue on to `updates_old.md`.
|
... To continue on to `updates_old.md`.
|
||||||
146
updates_old.md
146
updates_old.md
@@ -1,3 +1,72 @@
|
|||||||
|
## 0.20.0
|
||||||
|
At 0.20.0, Self-hosted LiveSync has changed the binary file format and encrypting format, for efficient synchronisation.
|
||||||
|
The dialogue will be shown and asks us to decide whether to keep v1 or use v2. Once we have enabled v2, all subsequent edits will be saved in v2. Therefore, devices running 0.19 or below cannot understand this and they might say that decryption error. Please update all devices.
|
||||||
|
Then we will have an impressive performance.
|
||||||
|
|
||||||
|
Of course, these are very impactful changes. If you have any questions or troubled things, please feel free to open an issue and mention me.
|
||||||
|
|
||||||
|
Note: if you want to roll it back to v1, please enable `Use binary and encryption version 1` on the `Hatch` pane and perform the `rebuild everything` once.
|
||||||
|
|
||||||
|
Extra but notable information:
|
||||||
|
|
||||||
|
This format change gives us the ability to detect some `marks` in the binary files as same as text files. Therefore, we can split binary files and some specific sort of them (i.e., PDF files) at the specific character. It means that editing the middle of files could be detected with marks.
|
||||||
|
|
||||||
|
Now only a few chunks are transferred, even if we add a comment to the PDF or put new files into the ZIP archives.
|
||||||
|
|
||||||
|
|
||||||
|
- 0.20.7
|
||||||
|
- Fixed
|
||||||
|
- To better replication, path obfuscation is now deterministic even if with E2EE.
|
||||||
|
Note: Compatible with previous database without any conversion. Only new files will be obfuscated in deterministic.
|
||||||
|
- 0.20.6
|
||||||
|
- Fixed
|
||||||
|
- Now empty file could be decoded.
|
||||||
|
- Local files are no longer pre-saved before fetching from a remote database.
|
||||||
|
- No longer deadlock while applying customisation sync.
|
||||||
|
- Configuration with multiple files is now able to be applied correctly.
|
||||||
|
- Deleting folder propagation now works without enabling the use of a trash bin.
|
||||||
|
- 0.20.5
|
||||||
|
- Fixed
|
||||||
|
- Now the files which having digit or character prefixes in the path will not be ignored.
|
||||||
|
- 0.20.4
|
||||||
|
- Fixed
|
||||||
|
- The text-input-dialogue is no longer broken.
|
||||||
|
- Finally, we can use the Setup URI again on mobile.
|
||||||
|
- 0.20.3
|
||||||
|
- New feature:
|
||||||
|
- We can launch Customization sync from the Ribbon if we enabled it.
|
||||||
|
- Fixed:
|
||||||
|
- Setup URI is now back to the previous spec; be encrypted by V1.
|
||||||
|
- It may avoid the trouble with iOS 17.
|
||||||
|
- The Settings dialogue is now registered at the beginning of the start-up process.
|
||||||
|
- We can change the configuration even though LiveSync could not be launched in normal.
|
||||||
|
- Improved:
|
||||||
|
- Enumerating documents has been faster.
|
||||||
|
- 0.20.2
|
||||||
|
- New feature:
|
||||||
|
- We can delete all data of customization sync from the `Delete all customization sync data` on the `Hatch` pane.
|
||||||
|
- Fixed:
|
||||||
|
- Prevent keep restarting on iOS by yielding microtasks.
|
||||||
|
- 0.20.1
|
||||||
|
- Fixed:
|
||||||
|
- No more UI freezing and keep restarting on iOS.
|
||||||
|
- Diff of Non-markdown documents are now shown correctly.
|
||||||
|
- Improved:
|
||||||
|
- Performance has been a bit improved.
|
||||||
|
- Customization sync has gotten faster.
|
||||||
|
- However, We lost forward compatibility again (only for this feature). Please update all devices.
|
||||||
|
- Misc
|
||||||
|
- Terser configuration has been more aggressive.
|
||||||
|
- 0.20.0
|
||||||
|
- Improved:
|
||||||
|
- A New binary file handling implemented
|
||||||
|
- A new encrypted format has been implemented
|
||||||
|
- Now the chunk sizes will be adjusted for efficient sync
|
||||||
|
- Fixed:
|
||||||
|
- levels of exception in some logs have been fixed
|
||||||
|
- Tidied:
|
||||||
|
- Some Lint warnings have been suppressed.
|
||||||
|
|
||||||
### 0.19.0
|
### 0.19.0
|
||||||
|
|
||||||
#### Customization sync
|
#### Customization sync
|
||||||
@@ -113,6 +182,83 @@ I hope you will give it a try.
|
|||||||
- Improved:
|
- Improved:
|
||||||
- Now progress is reported while the cleaning up and fetch process.
|
- Now progress is reported while the cleaning up and fetch process.
|
||||||
- Cancelled replication is now detected.
|
- Cancelled replication is now detected.
|
||||||
|
- 0.19.15
|
||||||
|
- Fixed:
|
||||||
|
- Now storing files after cleaning up is correct works.
|
||||||
|
- Improved:
|
||||||
|
- Cleaning the local database up got incredibly fastened.
|
||||||
|
Now we can clean instead of fetching again when synchronising with the remote which has been cleaned up.
|
||||||
|
- 0.19.16
|
||||||
|
- Many upgrades on this release. I have tried not to let that happen, if something got corrupted, please feel free to notify me.
|
||||||
|
- New feature:
|
||||||
|
- (Beta) ignore files handling
|
||||||
|
We can use `.gitignore`, `.dockerignore`, and anything you like to filter the synchronising files.
|
||||||
|
- Fixed:
|
||||||
|
- Buttons on lock-detected-dialogue now can be shown in narrow-width devices.
|
||||||
|
- Improved:
|
||||||
|
- Some constant has been flattened to be evaluated.
|
||||||
|
- The usage of the deprecated API of obsidian has been reduced.
|
||||||
|
- Now the indexedDB adapter will be enabled while the importing configuration.
|
||||||
|
- Misc:
|
||||||
|
- Compiler, framework, and dependencies have been upgraded.
|
||||||
|
- Due to standing for these impacts (especially in esbuild and svelte,) terser has been introduced.
|
||||||
|
Feel free to notify your opinion to me! I do not like to obfuscate the code too.
|
||||||
|
- 0.19.17
|
||||||
|
- Fixed:
|
||||||
|
- Now nested ignore files could be parsed correctly.
|
||||||
|
- The unexpected deletion of hidden files in some cases has been corrected.
|
||||||
|
- Hidden file change is no longer reflected on the device which has made the change itself.
|
||||||
|
- Behaviour changed:
|
||||||
|
- From this version, the file which has `:` in its name should be ignored even if on Linux devices.
|
||||||
|
- 0.19.18
|
||||||
|
- Fixed:
|
||||||
|
- Now the empty (or deleted) file could be conflict-resolved.
|
||||||
|
- 0.19.19
|
||||||
|
- Fixed:
|
||||||
|
- Resolving conflicted revision has become more robust.
|
||||||
|
- LiveSync now try to keep local changes when fetching from the rebuilt remote database.
|
||||||
|
Local changes now have been kept as a revision and fetched things will be new revisions.
|
||||||
|
- Now, all files will be restored after performing `fetch` immediately.
|
||||||
|
- 0.19.20
|
||||||
|
- New feature:
|
||||||
|
- `Sync on Editor save` has been implemented
|
||||||
|
- We can start synchronisation when we save from the Obsidian explicitly.
|
||||||
|
- Now we can use the `Hidden file sync` and the `Customization sync` cooperatively.
|
||||||
|
- We can exclude files from `Hidden file sync` which is already handled in Customization sync.
|
||||||
|
- We can ignore specific plugins in Customization sync.
|
||||||
|
- Now the message of leftover conflicted files accepts our click.
|
||||||
|
- We can open `Resolve all conflicted files` in an instant.
|
||||||
|
- Refactored:
|
||||||
|
- Parallelism functions made more explicit.
|
||||||
|
- Type errors have been reduced.
|
||||||
|
- Fixed:
|
||||||
|
- Now documents would not be overwritten if they are conflicted.
|
||||||
|
It will be saved as a new conflicted revision.
|
||||||
|
- Some error messages have been fixed.
|
||||||
|
- Missing dialogue titles have been shown now.
|
||||||
|
- We can click close buttons on mobile now.
|
||||||
|
- Conflicted Customisation sync files will be resolved automatically by their modified time.
|
||||||
|
- 0.19.21
|
||||||
|
- Fixed:
|
||||||
|
- Hidden files are no longer handled in the initial replication.
|
||||||
|
- Report from `Making report` fixed
|
||||||
|
- No longer contains customisation sync information.
|
||||||
|
- Version of LiveSync has been added.
|
||||||
|
- 0.19.22
|
||||||
|
- Fixed:
|
||||||
|
- Now the synchronisation will begin without our interaction.
|
||||||
|
- No longer puts the configuration of the remote database into the log while checking configuration.
|
||||||
|
- Some outdated description notes have been removed.
|
||||||
|
- Options that are meaningless depending on other settings configured are now hidden.
|
||||||
|
- Scan for hidden files before replication
|
||||||
|
- Scan customization periodically
|
||||||
|
- 0.19.23
|
||||||
|
-Improved:
|
||||||
|
- We can open the log pane also from the command palette now.
|
||||||
|
- Now, the hidden file scanning interval could be configured to 0.
|
||||||
|
- `Check database configuration` now points out that we do not have administrator permission.
|
||||||
|
|
||||||
|
|
||||||
### 0.18.0
|
### 0.18.0
|
||||||
|
|
||||||
#### Now, paths of files in the database can now be obfuscated. (Experimental Feature)
|
#### Now, paths of files in the database can now be obfuscated. (Experimental Feature)
|
||||||
|
|||||||
Reference in New Issue
Block a user