Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- Updated the drive URL.
- Improved the synchronization UI.
- Worked on the functionality to move files and folders.
  • Loading branch information
ArceDanielShok committed Jul 8, 2024
1 parent e40391d commit 2ba3879
Show file tree
Hide file tree
Showing 24 changed files with 303 additions and 223 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.1.0-test",
"version": "2.1.0-v4",
"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.1.0-test",
"version": "2.1.0-v4",
"description": "Internxt Drive client UI",
"main": "./dist/main/main.js",
"author": "Internxt <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion src/apps/main/auth/refresh-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function obtainTokens() {
try {
Logger.debug('[TOKEN] Obtaining new tokens');
const res = await authorizedClient.get(
`${process.env.API_URL}/api/user/refresh`
`${process.env.API_URL}/user/refresh`
);

return res.data;
Expand Down
31 changes: 23 additions & 8 deletions src/apps/main/background-processes/sync-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export async function stopSyncEngineWatcher() {
});

try {
worker?.webContents.send('STOP_SYNC_ENGINE_PROCESS');
worker?.webContents?.send('STOP_SYNC_ENGINE_PROCESS');

await stopPromise;
} catch (err) {
Expand Down Expand Up @@ -219,7 +219,7 @@ async function stopAndClearSyncEngineWatcher() {
});

try {
worker?.webContents.send('STOP_AND_CLEAR_SYNC_ENGINE_PROCESS');
worker?.webContents?.send('STOP_AND_CLEAR_SYNC_ENGINE_PROCESS');

await response;
} catch (err) {
Expand All @@ -235,8 +235,13 @@ async function stopAndClearSyncEngineWatcher() {

export function updateSyncEngine() {
try {
if (worker?.webContents && !worker?.isDestroyed()) {
worker?.webContents.send('UPDATE_SYNC_ENGINE_PROCESS');
if (
worker &&
!worker.isDestroyed() &&
worker.webContents &&
!worker.webContents.isDestroyed()
) {
worker.webContents?.send('UPDATE_SYNC_ENGINE_PROCESS');
}
} catch (err) {
// TODO: handle error
Expand All @@ -247,17 +252,27 @@ export function updateSyncEngine() {

export function fallbackSyncEngine() {
try {
if (worker?.webContents && !worker?.isDestroyed()) {
worker?.webContents.send('FALLBACK_SYNC_ENGINE_PROCESS');
if (
worker &&
!worker.isDestroyed() &&
worker.webContents &&
!worker.webContents.isDestroyed()
) {
worker?.webContents?.send('FALLBACK_SYNC_ENGINE_PROCESS');
}
} catch (err) {
Logger.error(err);
}
}
export async function sendUpdateFilesInSyncPending(): Promise<string[]> {
try {
if (worker?.webContents && !worker?.isDestroyed()) {
worker?.webContents.send('UPDATE_UNSYNC_FILE_IN_SYNC_ENGINE_PROCESS');
if (
worker &&
!worker.isDestroyed() &&
worker.webContents &&
!worker.webContents.isDestroyed()
) {
worker?.webContents?.send('UPDATE_UNSYNC_FILE_IN_SYNC_ENGINE_PROCESS');
}
return [];
} catch (err) {
Expand Down
12 changes: 6 additions & 6 deletions src/apps/main/device/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const addUnknownDeviceIssue = (error: Error) => {
};

function createDevice(deviceName: string) {
return fetch(`${process.env.API_URL}/api/backup/deviceAsFolder`, {
return fetch(`${process.env.API_URL}/backup/deviceAsFolder`, {
method: 'POST',
headers: getHeaders(true),
body: JSON.stringify({ deviceName }),
Expand Down Expand Up @@ -76,7 +76,7 @@ export async function getOrCreateDevice() {

if (deviceIsDefined) {
const res = await fetch(
`${process.env.API_URL}/api/backup/deviceAsFolder/${savedDeviceId}`,
`${process.env.API_URL}/backup/deviceAsFolder/${savedDeviceId}`,
{
method: 'GET',
headers: getHeaders(),
Expand Down Expand Up @@ -110,7 +110,7 @@ export async function renameDevice(deviceName: string): Promise<Device> {
const deviceId = getDeviceId();

Check warning on line 110 in src/apps/main/device/service.ts

View workflow job for this annotation

GitHub Actions / 🧪 Lint and test

'getDeviceId' was used before it was defined

const res = await fetch(
`${process.env.API_URL}/api/backup/deviceAsFolder/${deviceId}`,
`${process.env.API_URL}/backup/deviceAsFolder/${deviceId}`,
{
method: 'PATCH',
headers: getHeaders(true),
Expand Down Expand Up @@ -221,7 +221,7 @@ export async function addBackup(): Promise<void> {

async function fetchFolder(folderId: number) {
const res = await fetch(
`${process.env.API_URL}/api/storage/v2/folder/${folderId}`,
`${process.env.API_URL}/storage/v2/folder/${folderId}`,
{
method: 'GET',
headers: getHeaders(true),
Expand All @@ -236,7 +236,7 @@ async function fetchFolder(folderId: number) {

export async function deleteBackup(backup: Backup): Promise<void> {
const res = await fetch(
`${process.env.API_URL}/api/storage/folder/${backup.id}`,
`${process.env.API_URL}/storage/folder/${backup.id}`,
{
method: 'DELETE',
headers: getHeaders(true),
Expand Down Expand Up @@ -286,7 +286,7 @@ export async function changeBackupPath(currentPath: string): Promise<boolean> {
}

const res = await fetch(
`${process.env.API_URL}/api/storage/folder/${existingBackup.folderId}/meta`,
`${process.env.API_URL}/storage/folder/${existingBackup.folderId}/meta`,
{
method: 'POST',
headers: getHeaders(true),
Expand Down
9 changes: 9 additions & 0 deletions src/apps/main/fordwardToWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ ipcMainDrive.on('FILE_UPLOADING', (_, payload) => {
});
});

ipcMainDrive.on('FILE_UPLOADED', (_, payload) => {
const { nameWithExtension } = payload;
setIsProcessing(false);
broadcastToWindows('sync-info-update', {
action: 'UPLOADED',
name: nameWithExtension,
});
});

ipcMainDrive.on('FILE_CREATED', (_, payload) => {
const { nameWithExtension } = payload;
setIsProcessing(false);
Expand Down
16 changes: 4 additions & 12 deletions src/apps/main/remote-sync/RemoteSyncManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ export class RemoteSyncManager {
if (value) {
this.changeStatus('SYNCING');
} else {
this.checkRemoteSyncStatus();
// this.checkRemoteSyncStatus();
this.changeStatus('SYNCED');
}
this._isProcessRunning = value;
}
Expand Down Expand Up @@ -251,7 +252,7 @@ export class RemoteSyncManager {
}
}

async getFileCheckpoint(): Promise<Nullable<Date>> {
async getFileCheckpoint(): Promise<Nullable<Date>> {
const { success, result } = await this.db.files.getLastUpdated();

if (!success) return undefined;
Expand Down Expand Up @@ -307,8 +308,6 @@ export class RemoteSyncManager {
}

Logger.info('Remote files sync finished');
this.filesSyncStatus = 'SYNCED';
this.checkRemoteSyncStatus();
return allResults;
} catch (error) {
Logger.error('Remote files sync failed with error: ', error);
Expand Down Expand Up @@ -379,8 +378,7 @@ export class RemoteSyncManager {
}

Logger.info('Remote files sync finished');
this.filesSyncStatus = 'SYNCED';
this.checkRemoteSyncStatus();

return allResults;
} catch (error) {
Logger.error('Remote files sync failed with error: ', error);
Expand Down Expand Up @@ -457,9 +455,6 @@ export class RemoteSyncManager {
Logger.info('Retrieving more folders for sync');
}
}

this.foldersSyncStatus = 'SYNCED';
this.checkRemoteSyncStatus();
return allResults;
} catch (error) {
Logger.error('Remote folders sync failed with error: ', error);
Expand Down Expand Up @@ -527,9 +522,6 @@ export class RemoteSyncManager {
Logger.info('Retrieving more folders for sync');
}
}

this.foldersSyncStatus = 'SYNCED';
this.checkRemoteSyncStatus();
return allResults;
} catch (error) {
Logger.error('Remote folders sync failed with error: ', error);
Expand Down
44 changes: 35 additions & 9 deletions src/apps/main/remote-sync/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '../background-processes/sync-engine';
import { debounce } from 'lodash';
import configStore from '../config';
import { setTrayStatus } from '../tray/tray';

const SYNC_DEBOUNCE_DELAY = 3_000;

Expand All @@ -40,6 +41,13 @@ export function setIsProcessing(isProcessing: boolean) {
remoteSyncManager.isProcessRunning = isProcessing;
}

export function checkSyncEngineInProcess(milliSeconds: number) {
const syncingStatus: RemoteSyncStatus = 'SYNCING';
const isSyncing = remoteSyncManager.getSyncStatus() === syncingStatus;
const recentlySyncing = remoteSyncManager.recentlyWasSyncing(milliSeconds);
return isSyncing || recentlySyncing; // syncing or recently was syncing
}

export async function getUpdatedRemoteItems() {
try {
const [allDriveFiles, allDriveFolders] = await Promise.all([
Expand Down Expand Up @@ -106,6 +114,11 @@ export async function startRemoteSync(folderId?: number): Promise<void> {

ipcMain.handle('START_REMOTE_SYNC', async () => {
Logger.info('Received start remote sync event');
const isSyncing = await checkSyncEngineInProcess(5_000);
if (isSyncing) {
Logger.info('Remote sync is already running');
return;
}
setIsProcessing(true);
await startRemoteSync();
setIsProcessing(false);
Expand All @@ -120,6 +133,15 @@ remoteSyncManager.onStatusChange((newStatus) => {
broadcastToWindows('remote-sync-status-change', newStatus);
});

remoteSyncManager.onStatusChange((newStatus) => {
if (newStatus === 'SYNCING') {
setTrayStatus('SYNCING');
}
if (newStatus === 'SYNCED') {
setTrayStatus('IDLE');
}
});

ipcMain.handle('get-remote-sync-status', () =>
remoteSyncManager.getSyncStatus()
);
Expand All @@ -129,6 +151,11 @@ export async function updateRemoteSync(folderId?: number): Promise<void> {
// that we received the notification, but if we check
// for new data we don't receive it
Logger.info('Updating remote sync');
const isSyncing = await checkSyncEngineInProcess(5_000);
if (isSyncing) {
Logger.info('Remote sync is already running');
return;
}
await sleep(5_000);
await startRemoteSync(folderId);
updateSyncEngine();
Expand All @@ -139,13 +166,6 @@ export async function fallbackRemoteSync(): Promise<void> {
fallbackSyncEngine();
}

export function checkSyncEngineInProcess(milliSeconds: number) {
const syncingStatus: RemoteSyncStatus = 'SYNCING';
const isSyncing = remoteSyncManager.getSyncStatus() === syncingStatus;
const recentlySyncing = remoteSyncManager.recentlyWasSyncing(milliSeconds);
return isSyncing || recentlySyncing; // syncing or recently was syncing
}

ipcMain.handle('SYNC_MANUALLY', async () => {
Logger.info('[Manual Sync] Received manual sync event');
const isSyncing = await checkSyncEngineInProcess(5_000);
Expand Down Expand Up @@ -184,19 +204,25 @@ eventBus.on('RECEIVED_REMOTE_CHANGES', async () => {
// Wait before checking for updates, could be possible
// that we received the notification, but if we check
// for new data we don't receive it
Logger.info('Received remote changes event');
const isSyncing = await checkSyncEngineInProcess(5_000);
if (isSyncing) {
Logger.info('Remote sync is already running');
return;
}
debouncedSynchronization();
});

eventBus.on('USER_LOGGED_IN', async () => {
Logger.info('Received user logged in event');
try {
setIsProcessing(true);
remoteSyncManager.isProcessRunning = true;
const userData = configStore.get('userData');
const lastFilesSyncAt = await remoteSyncManager.getFileCheckpoint();
Logger.info('Last files sync at', lastFilesSyncAt);
const folderId = lastFilesSyncAt ? undefined : userData?.root_folder_id;
await startRemoteSync(folderId);
setIsProcessing(false);
remoteSyncManager.isProcessRunning = false;
} catch (error) {
Logger.error('Error starting remote sync manager', error);
if (error instanceof Error) reportError(error);
Expand Down
2 changes: 1 addition & 1 deletion src/apps/main/usage/serviceBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { UserUsageService } from './service';
import { onUserUnauthorized } from '../auth/handlers';

export function buildUsageService() {
const driveUrl = `${process.env.API_URL}/api`;
const driveUrl = `${process.env.API_URL}`;
const photosUrl = process.env.PHOTOS_URL;

const { name: clientName, version: clientVersion } = appInfo;
Expand Down
4 changes: 2 additions & 2 deletions src/apps/renderer/pages/Login/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function accessRequest(

let accessRes;
try {
accessRes = await fetch(`${process.env.API_URL}/api/access`, {
accessRes = await fetch(`${process.env.API_URL}/access`, {
method: 'POST',
body: JSON.stringify({
email: email.toLowerCase(),
Expand Down Expand Up @@ -84,7 +84,7 @@ export async function loginRequest(email: string): Promise<{
let loginRes;

try {
loginRes = await fetch(`${process.env.API_URL}/api/login`, {
loginRes = await fetch(`${process.env.API_URL}/login`, {
method: 'POST',
body: JSON.stringify({ email }),
headers: {
Expand Down
Loading

0 comments on commit 2ba3879

Please sign in to comment.