Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: Progressive file retrieval implemented #504

Merged
merged 12 commits into from
Jul 19, 2024
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internxt-drive",
"version": "2.0.10",
"version": "2.1.0",
"author": "Internxt <[email protected]>",
"description": "Internxt Drive client UI",
"license": "AGPL-3.0",
Expand Down Expand Up @@ -95,8 +95,7 @@
"win": {
"target": [
"nsis"
],
"certificateSubjectName": "Internxt Universal Technologies SL"
]
},
"linux": {
"target": [
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.10",
"version": "2.1.0",
"description": "Internxt Drive client UI",
"main": "./dist/main/main.js",
"author": "Internxt <[email protected]>",
Expand Down
10 changes: 10 additions & 0 deletions src/apps/main/analytics/drive-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ ipcMainDrive.on('FILE_DOWNLOADED', (_, payload) => {
});
});

ipcMainDrive.on('FILE_DOWNLOAD_CANCEL', (_, payload) => {
const { name, extension, size } = payload;

trackEvent('Download Aborted', {
file_name: name,
file_extension: extension,
file_size: size,
});
});

ipcMainDrive.on('FILE_CLONNED', (_, payload) => {
const { name, extension, size, processInfo } = payload;

Expand Down
3 changes: 2 additions & 1 deletion src/apps/main/auth/refresh-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const authorizedClient = getClient();

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
37 changes: 26 additions & 11 deletions src/apps/main/background-processes/sync-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
resolve();
});

const millisecondsToWait = 8_000;
const millisecondsToWait = 5_000;

setTimeout(() => {
reject(
Expand All @@ -55,7 +55,7 @@
const relaunchOnFail = () =>
healthCheck()
.then(() => {
// Logger.debug('Health check succeeded');
Logger.debug('Health check succeeded');
})
.catch(() => {
const warning = 'Health check failed, relaunching the worker';
Expand All @@ -68,10 +68,10 @@
startingWorker = false;
return;
}
spawnSyncEngineWorker();

Check warning on line 71 in src/apps/main/background-processes/sync-engine.ts

View workflow job for this annotation

GitHub Actions / 🧪 Lint and test

'spawnSyncEngineWorker' was used before it was defined
});

healthCheckSchedule = nodeSchedule.scheduleJob('*/30 * * * * *', async () => {
healthCheckSchedule = nodeSchedule.scheduleJob('*/20 * * * * *', async () => {
const workerIsPending = checkSyncEngineInProcess(15_000);
Logger.debug(
'Health check',
Expand Down Expand Up @@ -166,7 +166,7 @@
});

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 @@
});

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 @@

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 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 @@
};

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 All @@ -50,7 +50,7 @@
while (res.status === 409 && i <= 10) {
const deviceName = `${os.hostname()} (${i})`;
logger.info(`[DEVICE] Creating device with name "${deviceName}"`);
res = await createDevice(deviceName);

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

View workflow job for this annotation

GitHub Actions / 🧪 Lint and test

Unexpected `await` inside a loop
i++;
}

Expand All @@ -76,7 +76,7 @@

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 All @@ -84,7 +84,7 @@
);

if (res.ok) {
return decryptDeviceName(await res.json());

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

View workflow job for this annotation

GitHub Actions / 🧪 Lint and test

'decryptDeviceName' was used before it was defined
}
if (res.status === 404) {
newDevice = await tryToCreateDeviceWithDifferentNames();
Expand All @@ -96,7 +96,7 @@
if (newDevice) {
configStore.set('deviceId', newDevice.id);
configStore.set('backupList', {});
const device = decryptDeviceName(newDevice);

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

View workflow job for this annotation

GitHub Actions / 🧪 Lint and test

'decryptDeviceName' was used before it was defined
logger.info(`[DEVICE] Created device with name "${device.name}"`);

return device;
Expand All @@ -107,10 +107,10 @@
}

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 All @@ -118,7 +118,7 @@
}
);
if (res.ok) {
return decryptDeviceName(await res.json());

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

View workflow job for this annotation

GitHub Actions / 🧪 Lint and test

'decryptDeviceName' was used before it was defined
}
throw new Error('Error in the request to rename a device');
}
Expand All @@ -135,7 +135,7 @@
export async function getBackupsFromDevice(): Promise<
(Backup & { pathname: string })[]
> {
const deviceId = getDeviceId();

Check warning on line 138 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 folder = await fetchFolder(deviceId);

Expand Down Expand Up @@ -221,7 +221,7 @@

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 @@

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 @@
}

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
26 changes: 26 additions & 0 deletions src/apps/main/fordwardToWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ ipcMainDrive.on('FILE_DOWNLOADING', (_, payload) => {
});
});

ipcMainDrive.on('SYNCING', () => {
setIsProcessing(true);
});

ipcMainDrive.on('SYNCED', () => {
setIsProcessing(false);
});

ipcMainDrive.on('FILE_PREPARING', (_, payload) => {
const { nameWithExtension, processInfo } = payload;
setIsProcessing(true);
Expand All @@ -34,12 +42,21 @@ ipcMainDrive.on('FILE_PREPARING', (_, payload) => {
});

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

ipcMainDrive.on('FILE_MOVED', (_, payload) => {
const { nameWithExtension } = payload;
Expand Down Expand Up @@ -97,6 +114,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
Loading
Loading