refactor: use same backup path everywhere #2910

This commit is contained in:
Johannes Millan 2023-12-29 14:09:49 +01:00
parent 2cee503ffd
commit cf1c38bf3b
7 changed files with 11 additions and 19 deletions

View file

@ -13,11 +13,10 @@ import * as path from 'path';
import { error, log } from 'electron-log/main';
import { AppDataComplete } from '../src/app/imex/sync/sync.model';
let BACKUP_DIR = path.join(app.getPath('userData'), `backups`);
export const BACKUP_DIR = path.join(app.getPath('userData'), `backups`);
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function initBackupAdapter(backupDir: string): void {
BACKUP_DIR = backupDir;
export function initBackupAdapter(): void {
console.log('Saving backups to', BACKUP_DIR);
log('Saving backups to', BACKUP_DIR);

View file

@ -16,6 +16,8 @@ export interface ElectronAPI {
// ------
getUserDataPath(): Promise<string>;
getBackupPath(): Promise<string>;
checkBackupAvailable(): Promise<false | LocalBackupMeta>;
loadBackupData(backupPath: string): Promise<string>;

View file

@ -12,6 +12,7 @@ import { exec } from 'child_process';
import { getWin } from './main-window';
import { quitApp, showOrFocus } from './various-shared';
import { loadSimpleStoreAll, saveSimpleStore } from './simple-store';
import { BACKUP_DIR } from './backup';
export const initIpcInterfaces = (): void => {
// HANDLER
@ -19,6 +20,7 @@ export const initIpcInterfaces = (): void => {
ipcMain.handle(IPC.GET_PATH, (ev, name: string) => {
return app.getPath(name as any);
});
ipcMain.handle(IPC.GET_BACKUP_PATH, () => BACKUP_DIR);
// BACKEND EVENTS
// --------------

View file

@ -19,6 +19,7 @@ const ea: ElectronAPI = {
// INVOKE
// ------
getUserDataPath: () => _invoke('GET_PATH', 'userData') as Promise<string>,
getBackupPath: () => _invoke('GET_BACKUP_PATH') as Promise<string>,
checkBackupAvailable: () =>
_invoke('BACKUP_IS_AVAILABLE') as Promise<false | LocalBackupMeta>,
loadBackupData: (backupPath) =>

View file

@ -57,6 +57,7 @@ export enum IPC {
FULL_SCREEN_BLOCKER = 'FULL_SCREEN_BLOCKER',
GET_PATH = 'GET_PATH',
GET_BACKUP_PATH = 'GET_BACKUP_PATH',
RELOAD_MAIN_WIN = 'RELOAD_MAIN_WIN',
OPEN_DEV_TOOLS = 'OPEN_DEV_TOOLS',

View file

@ -151,11 +151,6 @@ export const startApp = (): void => {
app.setAppLogsPath();
}
const BACKUP_DIR =
`${app.getPath('userData')}` + process.platform == 'linux' || IS_MAC
? `/`
: `\\` + `backups`;
initDebug({ showDevTools: isShowDevTools }, IS_DEV);
// NOTE: opening the folder crashes the mas build
@ -180,7 +175,7 @@ export const startApp = (): void => {
// APP EVENT LISTENERS
// -------------------
appIN.on('ready', createMainWin);
appIN.on('ready', () => initBackupAdapter(BACKUP_DIR));
appIN.on('ready', () => initBackupAdapter());
appIN.on('ready', () => initLocalFileSyncAdapter());
appIN.on('ready', () => initFullScreenBlocker(IS_DEV));

View file

@ -63,20 +63,12 @@ export class ConfigPageComponent implements OnInit, OnDestroy {
getAutomaticBackUpFormCfg(),
];
} else if (IS_ELECTRON) {
window.ea.getUserDataPath().then((userDataPath) => {
const backupPath = `${userDataPath}${
(
navigator.platform
? navigator.platform.indexOf('Win') > -1
: navigator.userAgent?.indexOf('Windows') > -1
)
? '\\'
: '/'
}backups`;
window.ea.getBackupPath().then((backupPath) => {
this.globalSyncProviderFormCfg = [
...this.globalSyncProviderFormCfg,
getAutomaticBackUpFormCfg(backupPath),
];
this._cd.detectChanges();
});
}
}