Skip to content

Commit

Permalink
Merge pull request #489 from internxt/feat/merge-feats
Browse files Browse the repository at this point in the history
Feat/merge feats
  • Loading branch information
miguelsw authored Apr 11, 2024
2 parents f4f9fa7 + 55b5bbd commit ee15ddb
Show file tree
Hide file tree
Showing 27 changed files with 757 additions and 649 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internxt-drive",
"version": "2.0.6",
"version": "2.0.7",
"author": "Internxt <[email protected]>",
"description": "Internxt Drive client UI",
"license": "AGPL-3.0",
Expand Down
2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internxt-drive",
"version": "2.0.6",
"version": "2.0.7",
"description": "Internxt Drive client UI",
"main": "./dist/main/main.js",
"author": "Internxt <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion release/app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ uuid@^9.0.0:
resolved "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz"
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==

virtual-drive@../../../../node-win:
virtual-drive@../../../node-win:
version "1.0.1"
dependencies:
dotenv "^16.4.1"
Expand Down
7 changes: 7 additions & 0 deletions src/apps/main/background-processes/sync-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import Logger from 'electron-log';
import eventBus from '../event-bus';
import nodeSchedule from 'node-schedule';
import * as Sentry from '@sentry/electron/main';

let worker: BrowserWindow | null = null;
let workerIsRunning = false;
Expand Down Expand Up @@ -85,6 +86,7 @@ function spawnSyncEngineWorker() {
})
.catch((err) => {
Logger.error('[MAIN] Error loading sync engine worker', err);
Sentry.captureException(err);
});

worker.on('close', () => {
Expand Down Expand Up @@ -125,6 +127,7 @@ export async function stopSyncEngineWatcher() {
const stopPromise = new Promise<void>((resolve, reject) => {
ipcMain.once('SYNC_ENGINE_STOP_ERROR', (_, error: Error) => {
Logger.error('[MAIN] Error stopping sync engine worker', error);
Sentry.captureException(error);
reject(error);
});

Expand All @@ -151,6 +154,7 @@ export async function stopSyncEngineWatcher() {
} catch (err) {
// TODO: handle error
Logger.error(err);
Sentry.captureException(err);
} finally {
worker?.destroy();
workerIsRunning = false;
Expand All @@ -175,6 +179,7 @@ async function stopAndClearSyncEngineWatcher() {
'ERROR_ON_STOP_AND_CLEAR_SYNC_ENGINE_PROCESS',
(_, error: Error) => {
Logger.error('[MAIN] Error stopping sync engine worker', error);
Sentry.captureException(error);
reject(error);
}
);
Expand Down Expand Up @@ -202,6 +207,7 @@ async function stopAndClearSyncEngineWatcher() {
} catch (err) {
// TODO: handle error
Logger.error(err);
Sentry.captureException(err);
} finally {
worker?.destroy();
workerIsRunning = false;
Expand All @@ -215,6 +221,7 @@ export function updateSyncEngine() {
} catch (err) {
// TODO: handle error
Logger.error(err);
Sentry.captureException(err);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/apps/main/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (process.env.NODE_ENV !== 'development') {
// Handle open logs

ipcMain.on('open-logs', () => {
const logfilePath = log.transports.file.getFile().path;
const logFolderPath = path.dirname(logfilePath);
const logFilePath = log.transports.file.getFile().path;
const logFolderPath = path.dirname(logFilePath);
shell.openPath(logFolderPath);
});
10 changes: 6 additions & 4 deletions src/apps/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ import { setCleanUpFunction } from './quit';
import { stopSyncEngineWatcher } from './background-processes/sync-engine';
import { Theme } from '../shared/types/Theme';

const gotTheLock = app.requestSingleInstanceLock();

if (!gotTheLock) {
app.quit();
}

Logger.log(`Running ${packageJson.version}`);

Logger.log('Initializing Sentry for main process');
Expand All @@ -73,10 +79,6 @@ function checkForUpdates() {
autoUpdater.checkForUpdatesAndNotify();
}

if (process.platform === 'darwin') {
app.dock.hide();
}

if (process.env.NODE_ENV === 'production') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const sourceMapSupport = require('source-map-support');
Expand Down
2 changes: 2 additions & 0 deletions src/apps/main/realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { io, Socket } from 'socket.io-client';
import { obtainToken } from './auth/service';
import eventBus from './event-bus';
import { broadcastToWindows } from './windows';
import { reportError } from '../renderer/utils/errors';

type XHRRequest = {
getResponseHeader: (headerName: string) => string[] | null;
Expand Down Expand Up @@ -57,6 +58,7 @@ function cleanAndStartRemoteNotifications() {

socket.on('connect_error', (error) => {
logger.error('❌ Remote notifications connect error: ', error);
reportError(error);
});

socket.on('event', (data) => {
Expand Down
27 changes: 27 additions & 0 deletions src/apps/main/remote-sync/RemoteSyncManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
RemoteSyncedFile,
SyncConfig,
SYNC_OFFSET_MS,
WAITING_AFTER_SYNCING
} from './helpers';
import { reportError } from '../bug-report/service';

Expand All @@ -24,6 +25,8 @@ export class RemoteSyncManager {
> = [];
private totalFilesSynced = 0;
private totalFoldersSynced = 0;
private lastSyncingFinishedTimestamp: Date | null = null;

constructor(
private db: {
files: DatabaseCollectionAdapter<DriveFile>;
Expand All @@ -47,10 +50,15 @@ export class RemoteSyncManager {
if (typeof callback !== 'function') return;
this.onStatusChangeCallbacks.push(callback);
}

getSyncStatus(): RemoteSyncStatus {
return this.status;
}

private getLastSyncingFinishedTimestamp() {
return this.lastSyncingFinishedTimestamp;
}

/**
* Check if the RemoteSyncManager is in SYNCED status
*
Expand All @@ -60,10 +68,22 @@ export class RemoteSyncManager {
return this.status === 'SYNCED';
}

/**
* Consult if recently the RemoteSyncManager was syncing
* @returns True if the RemoteSyncManager was syncing recently
* @returns False if the RemoteSyncManager was not syncing recently
*/
recentlyWasSyncing() {
const passedTime = Date.now() - ( this.getLastSyncingFinishedTimestamp()?.getTime() ?? Date.now() );
return passedTime < WAITING_AFTER_SYNCING;
}

resetRemoteSync() {
this.changeStatus('IDLE');
this.filesSyncStatus = 'IDLE';
this.foldersSyncStatus = 'IDLE';
this._placeholdersStatus = 'IDLE';
this.lastSyncingFinishedTimestamp = null;
this.totalFilesSynced = 0;
this.totalFoldersSynced = 0;
}
Expand Down Expand Up @@ -148,6 +168,7 @@ export class RemoteSyncManager {
return true;
}
private changeStatus(newStatus: RemoteSyncStatus) {
this.addLastSyncingFinishedTimestamp();
if (newStatus === this.status) return;
Logger.info(`RemoteSyncManager ${this.status} -> ${newStatus}`);
this.status = newStatus;
Expand All @@ -157,6 +178,12 @@ export class RemoteSyncManager {
});
}

private addLastSyncingFinishedTimestamp() {
if (this.status !== 'SYNCING') return;
Logger.info('Adding last syncing finished timestamp');
this.lastSyncingFinishedTimestamp = new Date();
}

private checkRemoteSyncStatus() {
if (this._placeholdersStatus === 'SYNCING') {
this.changeStatus('SYNCING');
Expand Down
20 changes: 11 additions & 9 deletions src/apps/main/remote-sync/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import eventBus from '../event-bus';
import { RemoteSyncManager } from './RemoteSyncManager';
import { DriveFilesCollection } from '../database/collections/DriveFileCollection';
import { DriveFoldersCollection } from '../database/collections/DriveFolderCollection';
import { clearRemoteSyncStore } from './helpers';
import { clearRemoteSyncStore, RemoteSyncStatus } from './helpers';
import { getNewTokenClient } from '../../shared/HttpClient/main-process-client';
import Logger from 'electron-log';
import { ipcMain } from 'electron';
Expand Down Expand Up @@ -104,16 +104,18 @@ eventBus.on('USER_LOGGED_OUT', () => {

ipcMain.on('CHECK_SYNC', (event) => {
Logger.info('Checking sync');
event.sender.send(
'CHECK_SYNC_ENGINE_RESPONSE',
'Dato obtenido del proceso de sincronización'
);
event.sender.send('CHECK_SYNC_ENGINE_RESPONSE', '');
});

ipcMain.on('CHECK_SYNC_CHANGE_STATUS', async (_, placeholderStates) => {
await sleep(2_000);
Logger.info('[SYNC ENGINE] Changing status');
remoteSyncManager.placeholderStatus = 'SYNCING';
await sleep(7_00);
Logger.info('[SYNC ENGINE] Changing status', placeholderStates);
await sleep(5_000);
remoteSyncManager.placeholderStatus = placeholderStates;
});

ipcMain.handle('CHECK_SYNC_IN_PROGRESS', async () => {
const syncingStatus: RemoteSyncStatus = 'SYNCING';
const isSyncing = remoteSyncManager.getSyncStatus() === syncingStatus;
const recentlySyncing = remoteSyncManager.recentlyWasSyncing();
return isSyncing || recentlySyncing; // If it's syncing or recently was syncing
});
1 change: 1 addition & 0 deletions src/apps/main/remote-sync/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export type SyncConfig = {
};

export const SYNC_OFFSET_MS = 0;
export const WAITING_AFTER_SYNCING = 1000 * 60 * 3; // 5 minutes

export const lastSyncedAtIsNewer = (
itemUpdatedAt: Date,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Logger from 'electron-log';
import { ThumbnailUploaderFactory } from '../infrastructure/ThumbnailUploaderFactory';
import { obtainImageToThumbnailIt } from './obtain-image-to-thumbnail-it';
import { reziseImage } from './resize-image';
import * as Sentry from '@sentry/electron/main';

export async function createAndUploadThumbnail(id: number, name: string) {
const uploader = ThumbnailUploaderFactory.build();
Expand All @@ -17,5 +18,6 @@ export async function createAndUploadThumbnail(id: number, name: string) {

await uploader.upload(id, thumbnail).catch((err) => {
Logger.error('[THUMBNAIL] Error uploading thumbnail: ', err);
Sentry.captureException(err);
});
}
3 changes: 2 additions & 1 deletion src/apps/main/token-scheduler/TokenScheduler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Logger from 'electron-log';
import jwtDecode, { JwtPayload } from 'jwt-decode';
import nodeSchedule from 'node-schedule';
import * as Sentry from '@sentry/electron/main';

const FIVE_SECONDS = 5 * 60;

Expand All @@ -20,7 +21,7 @@ export class TokenScheduler {
return decoded.exp || TokenScheduler.MAX_TIME;
} catch (err) {
Logger.error('[TOKEN] Token could be not decoded');

Sentry.captureException(err); // Use the 'Sentry' module to capture the exception
return TokenScheduler.MAX_TIME;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/apps/sync-engine/BindingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ProcessIssue } from '../shared/types';
import { ipcRenderer } from 'electron';
import { ServerFileStatus } from '../../context/shared/domain/ServerFile';
import { ServerFolderStatus } from '../../context/shared/domain/ServerFolder';
import * as Sentry from '@sentry/electron/renderer';

export type CallbackDownload = (
success: boolean,
Expand Down Expand Up @@ -79,6 +80,7 @@ export class BindingsManager {
})
.catch((error: Error) => {
Logger.error(error);
Sentry.captureException(error);
callback(false);
});
ipcRenderer.send('CHECK_SYNC');
Expand Down Expand Up @@ -162,6 +164,7 @@ export class BindingsManager {
await this.container.virtualDrive.closeDownloadMutex();
} catch (error) {
Logger.error('notify: ', error);
Sentry.captureException(error);
await this.container.virtualDrive.closeDownloadMutex();
}

Expand All @@ -177,6 +180,7 @@ export class BindingsManager {
ipcRenderer.send('CHECK_SYNC');
} catch (error) {
Logger.error(error);
Sentry.captureException(error);
callback(false, '');
}
},
Expand All @@ -198,6 +202,7 @@ export class BindingsManager {
ipcRenderer.send('CHECK_SYNC');
} catch (error) {
Logger.error(error);
Sentry.captureException(error);
callback(false);
}
},
Expand Down Expand Up @@ -244,6 +249,8 @@ export class BindingsManager {
await this.container.virtualDrive.connectSyncRoot();

await this.load();

await this.polling();
}

watch() {
Expand Down Expand Up @@ -318,10 +325,12 @@ export class BindingsManager {
await this.container.filesPlaceholderUpdater.run(tree.files);
} catch (error) {
Logger.error('[SYNC ENGINE] ', error);
Sentry.captureException(error);
}
}

private async pollingStart() {
Logger.debug('[SYNC ENGINE] Starting polling');
return this.container.pollingMonitorStart.run(this.polling.bind(this));
}

Expand All @@ -336,6 +345,7 @@ export class BindingsManager {
ipcRenderer.send('CHECK_SYNC');
} catch (error) {
Logger.error('[SYNC ENGINE] Polling', error);
Sentry.captureException(error);
}
}
}
Loading

0 comments on commit ee15ddb

Please sign in to comment.