mirror of
https://github.com/remotely-save/remotely-save.git
synced 2024-06-07 21:10:45 +00:00
auto add ignore file
This commit is contained in:
parent
915d027b12
commit
0b5b9cf51a
38
src/main.ts
38
src/main.ts
@ -300,6 +300,9 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
await this.checkIfOauthExpires();
|
||||
await this.checkIfVaultIDAssigned(); // MUST before prepareDB()
|
||||
|
||||
// no need to await this
|
||||
this.tryToAddIgnoreFile();
|
||||
|
||||
await this.prepareDB();
|
||||
|
||||
this.syncStatus = "idle";
|
||||
@ -711,4 +714,39 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
const msg = `syncing progress=${i}/${totalCount},decision=${decision},path=${pathName}`;
|
||||
this.currSyncMsg = msg;
|
||||
}
|
||||
|
||||
async tryToAddIgnoreFile() {
|
||||
const pluginConfigDir =
|
||||
this.manifest.dir ||
|
||||
`${this.app.vault.configDir}/plugins/${this.manifest.dir}`;
|
||||
const pluginConfigDirExists = await this.app.vault.adapter.exists(
|
||||
pluginConfigDir
|
||||
);
|
||||
if (!pluginConfigDirExists) {
|
||||
// what happened?
|
||||
return;
|
||||
}
|
||||
const ignoreFile = `${pluginConfigDir}/.gitignore`;
|
||||
const ignoreFileExists = await this.app.vault.adapter.exists(ignoreFile);
|
||||
|
||||
const contentText = "data.json\n";
|
||||
|
||||
try {
|
||||
if (ignoreFileExists) {
|
||||
// check empty, if empty, we can write it
|
||||
// if not empty, we do nothing
|
||||
const content = (await this.app.vault.adapter.read(ignoreFile)).trim();
|
||||
if (content === "") {
|
||||
// no need to await writing
|
||||
this.app.vault.adapter.write(ignoreFile, contentText);
|
||||
}
|
||||
} else {
|
||||
// not exists, directly create
|
||||
// no need to await
|
||||
this.app.vault.adapter.write(ignoreFile, contentText);
|
||||
}
|
||||
} catch (error) {
|
||||
// just skip
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user