mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-08-01 12:10:33 +00:00
feat(localSync): prepare electron interface #690
This commit is contained in:
parent
845c037e46
commit
9f2bcd751c
5 changed files with 90 additions and 11 deletions
|
|
@ -16,7 +16,7 @@ import { error, log } from 'electron-log';
|
|||
let BACKUP_DIR = `${app.getPath('userData')}/backups`;
|
||||
|
||||
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
||||
export function initBackupAdapter(backupDir: string) {
|
||||
export function initBackupAdapter(backupDir: string): void {
|
||||
BACKUP_DIR = backupDir;
|
||||
console.log('Saving backups to', BACKUP_DIR);
|
||||
log('Saving backups to', BACKUP_DIR);
|
||||
|
|
@ -59,7 +59,7 @@ export function initBackupAdapter(backupDir: string) {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
||||
function backupData(ev, data) {
|
||||
function backupData(ev, data): void {
|
||||
if (!existsSync(BACKUP_DIR)) {
|
||||
mkdirSync(BACKUP_DIR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,10 @@ export enum IPC {
|
|||
UNREGISTER_BEFORE_CLOSE = 'UNREGISTER_BEFORE_CLOSE',
|
||||
BEFORE_CLOSE_DONE = 'BEFORE_CLOSE_DONE',
|
||||
|
||||
FILE_SYNC_LOAD = 'FILE_SYNC_LOAD',
|
||||
FILE_SYNC_SAVE = 'FILE_SYNC_SAVE',
|
||||
FILE_SYNC_GET_REV_AND_CLIENT_UPDATE = 'FILE_SYNC_GET_REV_AND_CLIENT_UPDATE',
|
||||
|
||||
// maybe_UPDATE_CURRENT_TASK = 'UPDATE_CURRENT_TASK',
|
||||
// maybe_IS_IDLE = 'IS_IDLE',
|
||||
// maybe_IS_BUSY = 'IS_BUSY',
|
||||
|
|
|
|||
53
electron/local-file-sync.ts
Normal file
53
electron/local-file-sync.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { answerRenderer } from './better-ipc';
|
||||
import { IPC } from './ipc-events.const';
|
||||
import { AppDataComplete, SyncGetRevResult } from '../src/app/imex/sync/sync.model';
|
||||
|
||||
export const initLocalFileSyncAdapter = (): void => {
|
||||
answerRenderer(
|
||||
IPC.FILE_SYNC_SAVE,
|
||||
(
|
||||
ev: any,
|
||||
{
|
||||
filePath,
|
||||
data,
|
||||
localRev,
|
||||
}: { filePath: string; data: AppDataComplete; localRev: string | null },
|
||||
): string | Error => {
|
||||
// TODO kill existing watcher before and kill after
|
||||
console.log(ev);
|
||||
console.log(filePath, data, localRev);
|
||||
return undefined;
|
||||
// if (!existsSync(BACKUP_DIR)) {
|
||||
// return false;
|
||||
// }
|
||||
// const files = readdirSync(BACKUP_DIR);
|
||||
// if (!files.length) {
|
||||
// return false;
|
||||
// }
|
||||
},
|
||||
);
|
||||
|
||||
answerRenderer(
|
||||
IPC.FILE_SYNC_GET_REV_AND_CLIENT_UPDATE,
|
||||
(
|
||||
ev: any,
|
||||
{ filePath, localRev }: { filePath: string; localRev: string | null },
|
||||
): { rev: string; clientUpdate?: number } | SyncGetRevResult => {
|
||||
console.log(ev);
|
||||
console.log(filePath, localRev);
|
||||
return undefined;
|
||||
},
|
||||
);
|
||||
|
||||
answerRenderer(
|
||||
IPC.FILE_SYNC_LOAD,
|
||||
(
|
||||
ev: any,
|
||||
{ filePath, localRev }: { filePath: string; localRev: string | null },
|
||||
): { rev: string; data: AppDataComplete | undefined } => {
|
||||
console.log(ev);
|
||||
console.log(filePath, localRev);
|
||||
return undefined;
|
||||
},
|
||||
);
|
||||
};
|
||||
|
|
@ -22,6 +22,7 @@ import { errorHandlerWithFrontendInform } from './error-handler-with-frontend-in
|
|||
import { initDebug } from './debug';
|
||||
import { IPC } from './ipc-events.const';
|
||||
import { initBackupAdapter } from './backup';
|
||||
import { initLocalFileSyncAdapter } from './local-file-sync';
|
||||
import { JiraCfg } from '../src/app/features/issue/providers/jira/jira.model';
|
||||
import lockscreen from './lockscreen';
|
||||
import { lazySetInterval } from './lazy-set-interval';
|
||||
|
|
@ -120,6 +121,8 @@ appIN.on('certificate-error', (event, webContents, url, err, certificate, callba
|
|||
// -------------------
|
||||
appIN.on('ready', createMainWin);
|
||||
appIN.on('ready', () => initBackupAdapter(BACKUP_DIR));
|
||||
appIN.on('ready', () => initLocalFileSyncAdapter());
|
||||
|
||||
if (!isDisableTray) {
|
||||
appIN.on('ready', createIndicator);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ import { SyncProvider, SyncProviderServiceInterface } from '../sync-provider.mod
|
|||
import { Observable, of } from 'rxjs';
|
||||
import { IS_ELECTRON } from '../../../app.constants';
|
||||
import { AppDataComplete, SyncGetRevResult } from '../sync.model';
|
||||
import { IPC } from '../../../../../electron/ipc-events.const';
|
||||
import { ElectronService } from '../../../core/electron/electron.service';
|
||||
import { first } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
|
|
@ -12,14 +15,24 @@ export class LocalFileSyncService implements SyncProviderServiceInterface {
|
|||
isUploadForcePossible?: boolean;
|
||||
isReady$: Observable<boolean> = of(IS_ELECTRON);
|
||||
|
||||
constructor() {}
|
||||
private _filePath$: Observable<string | undefined> = of(
|
||||
'TEST_PAAAAAAAAAAAAAAAAATH/asd/sync.json',
|
||||
);
|
||||
private _filePathOnce$: Observable<string | undefined> = this._filePath$.pipe(first());
|
||||
|
||||
constructor(private _electronService: ElectronService) {}
|
||||
|
||||
async getRevAndLastClientUpdate(
|
||||
localRev: string | null,
|
||||
): Promise<{ rev: string; clientUpdate?: number } | SyncGetRevResult> {
|
||||
return {
|
||||
rev: 'asd',
|
||||
};
|
||||
const filePath = await this._filePathOnce$.toPromise();
|
||||
return this._electronService.callMain(IPC.FILE_SYNC_GET_REV_AND_CLIENT_UPDATE, {
|
||||
filePath,
|
||||
localRev,
|
||||
}) as Promise<{
|
||||
rev: string;
|
||||
clientUpdate?: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
async uploadAppData(
|
||||
|
|
@ -27,15 +40,21 @@ export class LocalFileSyncService implements SyncProviderServiceInterface {
|
|||
localRev: string | null,
|
||||
isForceOverwrite?: boolean,
|
||||
): Promise<string | Error> {
|
||||
return 'asd';
|
||||
const filePath = await this._filePathOnce$.toPromise();
|
||||
return this._electronService.callMain(IPC.FILE_SYNC_SAVE, {
|
||||
localRev,
|
||||
filePath,
|
||||
data,
|
||||
}) as Promise<string | Error>;
|
||||
}
|
||||
|
||||
async downloadAppData(
|
||||
localRev: string | null,
|
||||
): Promise<{ rev: string; data: AppDataComplete | undefined }> {
|
||||
return {
|
||||
rev: 'asd',
|
||||
data: undefined,
|
||||
};
|
||||
const filePath = await this._filePathOnce$.toPromise();
|
||||
return this._electronService.callMain(IPC.FILE_SYNC_LOAD, {
|
||||
localRev,
|
||||
filePath,
|
||||
}) as Promise<{ rev: string; data: AppDataComplete | undefined }>;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue