Skip to content

Commit

Permalink
Add codes of 'show console logs' button.
Browse files Browse the repository at this point in the history
  • Loading branch information
ifgris committed Oct 9, 2024
1 parent 2cee0f1 commit 065eaa9
Show file tree
Hide file tree
Showing 3 changed files with 345 additions and 308 deletions.
20 changes: 12 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ import { join } from "path";
import { LocalBackupSettingTab } from "./settings";
import {
replaceDatePlaceholdersWithValues,
LocalBackupUtils,
getDefaultPath,
getDefaultName,
createFileByArchiver,
createZipByAdmZip,
deleteBackupsByLifeCycle,
deletePerDayBackups
} from "./utils";
import { ICON_DATA } from "./constants";
import { NewVersionNotifyModal, PromptModal } from "./modals";
Expand Down Expand Up @@ -69,6 +66,7 @@ const DEFAULT_SETTINGS: LocalBackupPluginSettings = {

export default class LocalBackupPlugin extends Plugin {
settings: LocalBackupPluginSettings;
utils: LocalBackupUtils;
intervalId: NodeJS.Timeout | null = null;

async onload() {
Expand All @@ -77,6 +75,8 @@ export default class LocalBackupPlugin extends Plugin {
const settingTab = new LocalBackupSettingTab(this.app, this);
this.addSettingTab(settingTab);

await this.loadUtis();

// startup notice
try {
if (this.settings.versionValue !== this.manifest.version) {
Expand Down Expand Up @@ -132,6 +132,10 @@ export default class LocalBackupPlugin extends Plugin {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}

async loadUtis() {
this.utils = new LocalBackupUtils(this.app, this);
}

async saveSettings() {
this.settings.versionValue = this.manifest.version;
await this.saveData(this.settings);
Expand Down Expand Up @@ -193,9 +197,9 @@ export default class LocalBackupPlugin extends Plugin {

if (this.settings.callingArchiverStatus) {
backupFilePath = join(savePathValue, `${fileNameWithDateValues}.${this.settings.archiveFileTypeValue}`);
await createFileByArchiver(this.settings.archiverTypeValue, archiverPathValue, this.settings.archiveFileTypeValue, vaultPath, backupFilePath);
await this.utils.createFileByArchiver(this.settings.archiverTypeValue, archiverPathValue, this.settings.archiveFileTypeValue, vaultPath, backupFilePath);
} else {
await createZipByAdmZip(vaultPath, backupFilePath);
await this.utils.createZipByAdmZip(vaultPath, backupFilePath);
}

if (this.settings.showConsoleLog) {
Expand All @@ -205,13 +209,13 @@ export default class LocalBackupPlugin extends Plugin {
new Notice(`Vault backup created: ${backupFilePath}`);
}

deleteBackupsByLifeCycle(
this.utils.deleteBackupsByLifeCycle(
savePathValue,
savePathValue,
this.settings.fileNameFormatValue,
lifecycleValue);

deletePerDayBackups(
this.utils.deletePerDayBackups(
savePathValue,
savePathValue,
this.settings.fileNameFormatValue,
Expand Down
122 changes: 61 additions & 61 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ import "./styles.css";

// Add this type definition
interface LocalBackupPluginSettings {
startupBackupStatus: boolean;
lifecycleValue: string;
backupsPerDayValue: string;
winSavePathValue: string;
unixSavePathValue: string;
fileNameFormatValue: string;
intervalBackupStatus: boolean;
backupFrequencyValue: string;
maxRetriesValue: string;
retryIntervalValue: string;
showRibbonIcon: boolean;
showConsoleLog: boolean;
startupBackupStatus: boolean;
lifecycleValue: string;
backupsPerDayValue: string;
winSavePathValue: string;
unixSavePathValue: string;
fileNameFormatValue: string;
intervalBackupStatus: boolean;
backupFrequencyValue: string;
maxRetriesValue: string;
retryIntervalValue: string;
showRibbonIcon: boolean;
showConsoleLog: boolean;
showNotifications: boolean;
oneWayBackupStatus: boolean;
oneWayWinSavePathValue: string; // Added for one-way backup Windows path
oneWayUnixSavePathValue: string; // Added for one-way backup Unix path
oneWayLifecycleValue: string; // Added for one-way backup retention
oneWayBackupsPerDayValue: string; // Added for one-way backups per day
callingArchiverStatus: boolean;
archiverTypeValue: string;
archiveFileTypeValue: string;
archiverWinPathValue: string;
archiverUnixPathValue: string;
oneWayBackupStatus: boolean;
oneWayWinSavePathValue: string; // Added for one-way backup Windows path
oneWayUnixSavePathValue: string; // Added for one-way backup Unix path
oneWayLifecycleValue: string; // Added for one-way backup retention
oneWayBackupsPerDayValue: string; // Added for one-way backups per day
callingArchiverStatus: boolean;
archiverTypeValue: string;
archiveFileTypeValue: string;
archiverWinPathValue: string;
archiverUnixPathValue: string;
}

export class LocalBackupSettingTab extends PluginSettingTab {
Expand Down Expand Up @@ -86,7 +86,7 @@ export class LocalBackupSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName("Backups per day")
.setDesc(
Expand Down Expand Up @@ -191,14 +191,14 @@ export class LocalBackupSettingTab extends PluginSettingTab {
);
return;
}
else{
else {
this.plugin.settings.backupFrequencyValue = value;
await this.plugin.saveSettings();
await this.plugin.applySettings();
}
})
);

new Setting(containerEl)
.setName("Retry times")
.setDesc("Set the retry times after backup failed.")
Expand All @@ -214,7 +214,7 @@ export class LocalBackupSettingTab extends PluginSettingTab {
);
return;
}
else{
else {
this.plugin.settings.maxRetriesValue = value;
await this.plugin.saveSettings();
await this.plugin.applySettings();
Expand All @@ -237,14 +237,14 @@ export class LocalBackupSettingTab extends PluginSettingTab {
);
return;
}
else{
else {
this.plugin.settings.retryIntervalValue = value;
await this.plugin.saveSettings();
await this.plugin.applySettings();
}
})
);

new Setting(containerEl)
.setName("Show ribbon icon")
.setDesc(ribbonIconDesc)
Expand All @@ -256,7 +256,7 @@ export class LocalBackupSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName("Show console logs")
.setDesc("Enable/Disable console log statements")
Expand All @@ -268,17 +268,17 @@ export class LocalBackupSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName("Show notifications")
.setDesc("Enable/Disable normal notifications, keep exceptions only")
.addToggle((toggle: ToggleComponent) =>
toggle
.setValue(this.plugin.settings.showNotifications)
.onChange(async (value: boolean) => {
this.plugin.settings.showNotifications = value;
await this.plugin.saveSettings();
})
.setName("Show notifications")
.setDesc("Enable/Disable normal notifications, keep exceptions only")
.addToggle((toggle: ToggleComponent) =>
toggle
.setValue(this.plugin.settings.showNotifications)
.onChange(async (value: boolean) => {
this.plugin.settings.showNotifications = value;
await this.plugin.saveSettings();
})
);

containerEl.createEl("h3", { text: "One Way Backup Settings" });
Expand Down Expand Up @@ -339,7 +339,7 @@ export class LocalBackupSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName("One way backups per day")
.setDesc(
Expand All @@ -360,7 +360,7 @@ export class LocalBackupSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);

containerEl.createEl("h3", { text: "File Archiver Settings (Optional)" });

new Setting(containerEl)
Expand All @@ -378,30 +378,30 @@ export class LocalBackupSettingTab extends PluginSettingTab {
new Setting(containerEl)
.setName("Select file archiver")
.setDesc("The selected archiver must be installed. eg. 7-Zip for Windows, 7-Zip/p7zip for Unix")
.addDropdown((dropDown: DropdownComponent) =>{
.addDropdown((dropDown: DropdownComponent) => {
dropDown
.addOption("sevenZip", "7-Zip")
.addOption("winRAR", "WinRAR")
.addOption("bandizip", "bandizip")
.setValue(this.plugin.settings.archiverTypeValue)
.onChange(async (value: string) => {
this.plugin.settings.archiverTypeValue = value;
await this.plugin.saveSettings();
});
.addOption("sevenZip", "7-Zip")
.addOption("winRAR", "WinRAR")
.addOption("bandizip", "bandizip")
.setValue(this.plugin.settings.archiverTypeValue)
.onChange(async (value: string) => {
this.plugin.settings.archiverTypeValue = value;
await this.plugin.saveSettings();
});
});

new Setting(containerEl)
.setName("Select archive file type")
.addDropdown((dropDown: DropdownComponent) =>{
.addDropdown((dropDown: DropdownComponent) => {
dropDown
.addOption("zip", "zip")
.addOption("7z", "7z")
.addOption("rar", "rar")
.setValue(this.plugin.settings.archiveFileTypeValue)
.onChange(async (value: string) => {
this.plugin.settings.archiveFileTypeValue = value;
await this.plugin.saveSettings();
});
.addOption("zip", "zip")
.addOption("7z", "7z")
.addOption("rar", "rar")
.setValue(this.plugin.settings.archiveFileTypeValue)
.onChange(async (value: string) => {
this.plugin.settings.archiveFileTypeValue = value;
await this.plugin.saveSettings();
});
});

new Setting(containerEl)
Expand All @@ -415,7 +415,7 @@ export class LocalBackupSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName("File archiver path (Unix)")
.setDesc("Full path of Archiver. eg. /usr/bin/7z or 7z for Unix.")
Expand Down
Loading

0 comments on commit 065eaa9

Please sign in to comment.