NOTE: This document surely became outdated. I'll improve this doc in a while. but your contributions are always welcome.

# Settings of this plugin

The settings dialog has been quite long, so I split each configuration into tabs.  
If you feel something, please feel free to inform me.

| icon  | description                                                       |
| :---: | ----------------------------------------------------------------- |
|   🛰️   | [Remote Database Configurations](#remote-database-configurations) |
|   📦   | [Local Database Configurations](#local-database-configurations)   |
|   ⚙️   | [General Settings](#general-settings)                             |
|   🔁   | [Sync Settings](#sync-settings)                                   |
|   🔧   | [Miscellaneous](#miscellaneous)                                   |
|   🧰   | [Hatch](#miscellaneous)                                           |
|   🔌   | [Plugin and its settings](#plugin-and-its-settings)               |
|   🚑   | [Corrupted data](#corrupted-data)                                 |

## Remote Database Configurations
Configure the settings of synchronize server. If any synchronization is enabled, you can't edit this section. Please disable all synchronization to change.

### URI
URI of CouchDB. In the case of Cloudant, It's "External Endpoint(preferred)".  
**Do not end it up with a slash** when it doesn't contain the database name.

### Username
Your CouchDB's Username. Administrator's privilege is preferred.

### Password
Your CouchDB's Password.  
Note: This password is saved into your Obsidian's vault in plain text.

### Database Name
The Database name to synchronize.  
⚠️If not exist, created automatically.


### End to End Encryption
Encrypt your database. It affects only the database, your files are left as plain.

The encryption algorithm is AES-GCM.

Note: If you want to use "Plugins and their settings", you have to enable this.

### Passphrase
The passphrase to used as the key of encryption. Please use the long text.

### Apply
Set the End to End encryption enabled and its passphrase for use in replication.  
If you change the passphrase of an existing database, overwriting the remote database is strongly recommended.


### Overwrite remote database
Overwrite the remote database with the local database using the passphrase you applied.


### Rebuild
Rebuild remote and local databases with local files. It will delete all document history and retained chunks, and shrink the database.

### Test Database connection
You can check the connection by clicking this button.

### Check database configuration
You can check and modify your CouchDB configuration from here directly.

### Lock remote database.
Other devices are banned from the database when you have locked the database.  
If you have something troubled with other devices, you can protect the vault and remote database with your device.

## Local Database Configurations
"Local Database" is created inside your obsidian.

### Batch database update
Delay database update until raise replication, open another file, window visibility changes, or file events except for file modification.  
This option can not be used with LiveSync at the same time.


### Fetch rebuilt DB.
If one device rebuilds or locks the remote database, every other device will be locked out from the remote database until it fetches rebuilt DB.

### minimum chunk size and LongLine threshold
The configuration of chunk splitting.

Self-hosted LiveSync splits the note into chunks for efficient synchronization. This chunk should be longer than the "Minimum chunk size".

Specifically, the length of the chunk is determined by the following orders.

1. Find the nearest newline character, and if it is farther than LongLineThreshold, this piece becomes an independent chunk.

2. If not, find the nearest to these items.
    1. A newline character
    2. An empty line (Windows style)
    3. An empty line (non-Windows style)
3. Compare the farther in these 3 positions and the next "newline\]#" position, and pick a shorter piece as a chunk.

This rule was made empirically from my dataset. If this rule acts as badly on your data. Please give me the information.

You can dump saved note structure to `Dump informations of this doc`. Replace every character with x except newline and "#" when sending information to me.

The default values are 20 letters and 250 letters.

## General Settings

### Do not show low-priority log
If you enable this option, log only the entries with the popup.

### Verbose log

## Sync Settings

### LiveSync
Do LiveSync.

It is the one of raison d'être of this plugin.

Useful, but this method drains many batteries on the mobile and uses not the ignorable amount of data transfer.

This method is exclusive to other synchronization methods.

### Periodic Sync
Synchronize periodically. 

### Periodic Sync Interval
Unit is seconds.

### Sync on Save
Synchronize when the note has been modified or created.

### Sync on File Open
Synchronize when the note is opened.

### Sync on Start
Synchronize when Obsidian started.

### Use Trash for deleted files
When the file has been deleted on remote devices, deletion will be replicated to the local device and the file will be deleted.

If this option is enabled, move deleted files into the trash instead delete actually.

### Do not delete empty folder
Self-hosted LiveSync will delete the folder when the folder becomes empty. If this option is enabled, leave it as an empty folder.

### Use newer file if conflicted (beta)
Always use the newer file to resolve and overwrite when conflict has occurred.


### Experimental.
### Sync hidden files

Synchronize hidden files.

- Scan hidden files before replication.
If you enable this option, all hidden files are scanned once before replication.

- Scan hidden files periodicaly.
If you enable this option, all hidden files will be scanned each [n] seconds.

Hidden files are not actively detected, so we need scanning.

Each scan stores the file with their modification time. And if the file has been disappeared, the fact is also stored. Then, When the entry of the hidden file has been replicated, it will be reflected in the storage if the entry is newer than storage.

Therefore, the clock must be adjusted. If the modification time is determined to be older, the changeset will be skipped or cancelled (It means, **deleted**), even if the file spawned in a hidden folder.

### Advanced settings
Self-hosted LiveSync using PouchDB and synchronizes with the remote by [this protocol](https://docs.couchdb.org/en/stable/replication/protocol.html).
So, it splits every entry into chunks to be acceptable by the database with limited payload size and document size.

However, it was not enough.
According to [2.4.2.5.2. Upload Batch of Changed Documents](https://docs.couchdb.org/en/stable/replication/protocol.html#upload-batch-of-changed-documents) in [Replicate Changes](https://docs.couchdb.org/en/stable/replication/protocol.html#replicate-changes), it might become a bigger request.

Unfortunately, there is no way to deal with this automatically by size for every request.
Therefore, I made it possible to configure this.

Note: If you set these values lower number, the number of requests will increase.  
Therefore, if you are far from the server, the total throughput will be low, and the traffic will increase.

### Batch size
Number of change feed items to process at a time. Defaults to 250.

### Batch limit
Number of batches to process at a time. Defaults to 40. This along with batch size controls how many docs are kept in memory at a time.

## Miscellaneous

### Show status inside editor
Show information inside the editor pane.
It would be useful for mobile.

### Check integrity on saving
Check all chunks are correctly saved on saving.

### Presets
You can set synchronization method at once as these pattern:
- LiveSync
  - LiveSync : enabled
  - Batch database update : disabled
  - Periodic Sync : disabled
  - Sync on Save : disabled
  - Sync on File Open : disabled
  - Sync on Start : disabled
- Periodic w/ batch
  - LiveSync : disabled
  - Batch database update : enabled
  - Periodic Sync : enabled
  - Sync on Save : disabled
  - Sync on File Open : enabled
  - Sync on Start : enabled
- Disable all sync
  - LiveSync : disabled
  - Batch database update : disabled
  - Periodic Sync : disabled
  - Sync on Save : disabled
  - Sync on File Open : disabled
  - Sync on Start : disabled


## Hatch
From here, everything is under the hood. Please handle it with care.

When there are problems with synchronization, the warning message is shown Under this section header.

- Pattern 1  
![CorruptedData](../images/lock_pattern1.png)  
This message is shown when the remote database is locked and your device is not marked as "resolved".  
Almost it is happened by enabling End-to-End encryption or History has been dropped.  
If you enabled End-to-End encryption, you can unlock the remote database by "Apply and receive" automatically. Or "Drop and receive" when you dropped. If you want to unlock manually, click "mark this device as resolved".

- Pattern 2  
![CorruptedData](../images/lock_pattern2.png)  
The remote database indicates that has been unlocked Pattern 1.  
When you mark all devices as resolved, you can unlock the database.
But, there's no problem even if you leave it as it is.

### Verify and repair all files
read all files in the vault, and update them into the database if there's diff or could not read from the database.

### Suspend file watching
If enable this option, Self-hosted LiveSync dismisses every file change or deletes the event.

From here, these commands are used inside applying encryption passphrases or dropping histories.

Usually, doesn't use it so much. But sometimes it could be handy.

## Plugins and settings (beta)

### Enable plugin synchronization
If you want to use this feature, you have to activate this feature by this switch.

### Sweep plugins automatically
Plugin sweep will run before replication automatically.

### Sweep plugins periodically
Plugin sweep will run each 1 minute.

### Notify updates
When replication is complete, a message will be notified if a newer version of the plugin applied to this device is configured on another device.

### Device and Vault name
To save the plugins, you have to set a unique name every each device.

### Open
Open the "Plugins and their settings" dialog.

### Corrupted or missing data
![CorruptedData](../images/corrupted_data.png)

When Self-hosted LiveSync could not write to the file on the storage, the files are shown here. If you have the old data in your vault, change it once, it will be cured. Or you can use the "File History" plugin.
