Skip to content

Commit

Permalink
Merge pull request #374 from internxt/feature/macos-migration-banner
Browse files Browse the repository at this point in the history
Feature/macos migration banner
  • Loading branch information
PixoDev authored Sep 21, 2023
2 parents 0d0a748 + 4a9c29b commit 2fb84f6
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 14 deletions.
7 changes: 7 additions & 0 deletions src/main/app-info/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { ipcMain, app } from 'electron';

import { executeQuery } from './service';
import axios from 'axios';

ipcMain.handle('execute-app-query', (_, query) => executeQuery(query));

ipcMain.handle('get-download-urls', async () => {
const response = await axios.get('https://internxt.com/api/download');

return response.data;
});

ipcMain.handle('get-path', (_, path) => {
const result = app.getPath(path);
return result;
Expand Down
21 changes: 7 additions & 14 deletions src/main/background-processes/webdav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { ipcWebdav } from '../ipcs/webdav';
import path from 'path';
import Logger from 'electron-log';
import eventBus from '../event-bus';
import { ejectMacOSInstallerDisks, unmountDrive } from '../../workers/webdav/VirtualDrive';

import {
ejectMacOSInstallerDisks,
unmountDrive,
} from '../../workers/webdav/VirtualDrive';

let webdavWorker: BrowserWindow | null = null;

Expand Down Expand Up @@ -47,19 +49,8 @@ function stopWebDavServer() {
webdavWorker?.webContents.send('STOP_WEBDAV_SERVER_PROCESS');
}

function startWebDavServer() {
webdavWorker?.webContents.send('START_WEBDAV_SERVER_PROCESS');
}

eventBus.on('USER_LOGGED_OUT', stopWebDavServer);
eventBus.on('USER_WAS_UNAUTHORIZED', stopWebDavServer);
eventBus.on('USER_LOGGED_IN', () => {
if (webdavWorker === null) {
spawnWebdavServerWorker();
} else {
startWebDavServer();
}
});

if (process.platform === 'darwin') {
eventBus.on('APP_IS_READY', ejectMacOSInstallerDisks);
Expand All @@ -72,6 +63,8 @@ ipcMain.handle('retry-virtual-drive-mount', () => {
ipcMain.handle('unmount-virtual-drive-and-quit', async () => {
try {
await unmountDrive();
} catch (onMenuQuitClickError) { Logger.error({ onMenuQuitClickError }); };
} catch (onMenuQuitClickError) {
Logger.error({ onMenuQuitClickError });
}
await app.quit();
});
1 change: 1 addition & 0 deletions src/main/preload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ declare interface Window {
retryVirtualDriveMount(): void;
unmountVirtualDriveAndQuit: () => Promise<boolean>;
startRemoteSync: () => Promise<void>;
getDownloadUrls: () => Promise<{ platforms: Record<string, string> }>;
openUrl: (url: string) => Promise<void>;
// DEV
resizeWindow: () => typeof import('../main/dev/service').resizeCurrentWindow;
Expand Down
3 changes: 3 additions & 0 deletions src/main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ contextBridge.exposeInMainWorld('electron', {
unmountVirtualDriveAndQuit() {
return ipcRenderer.invoke('unmount-virtual-drive-and-quit');
},
getDownloadUrls() {
return ipcRenderer.invoke('get-download-urls');
},
onVirtualDriveStatusChange(callback) {
const eventName = 'virtual-drive-status-change';
const callbackWrapper = (_, v) => {
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/localize/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
}
},
"widget": {
"macos-available": {
"title": "Desktop v2.0 is already here!",
"message": "The native macOS app is faster and more efficient, install it today"
},
"header": {
"usage": {
"of": "of",
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/localize/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
}
},
"widget": {
"macos-available": {
"title": "Desktop v2.0 está disponible!",
"message": "La versión nativa de MacOS es más rapida y eficiente, instálala hoy"
},
"header": {
"usage": {
"of": "de",
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/localize/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
}
},
"widget": {
"macos-available": {
"title": "Desktop v2.0 est disponible!",
"message": "L'application native de macOS est plus rapide et plus efficace, installez-la dès aujourd'hui"
},
"header": {
"usage": {
"of": "de",
Expand Down
44 changes: 44 additions & 0 deletions src/renderer/pages/Widget/MacOSVersionAvailableBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ArrowRight } from '@phosphor-icons/react';
import React, { useEffect, useState } from 'react';
import { useTranslationContext } from '../../context/LocalContext';
import { reportError } from '../../utils/errors';

const getDownloadUrl = async () => {
const { platforms } = await window.electron.getDownloadUrls();

return platforms['MacOS'];
};
export const MacOSVersionAvailableBanner: React.FC = () => {
const { translate } = useTranslationContext();
const [downloadURL, setDownloadURL] = useState<string>();
useEffect(() => {
getDownloadUrl().then(setDownloadURL).catch(reportError);
}, []);

const handleDownloadMacOSNative = async () => {
try {
if (!downloadURL) return;
await window.electron.openUrl(downloadURL);
} catch (error) {
reportError(error);
}
};
return (
<div
className="flex flex-row bg-primary px-5 py-4"
onClick={handleDownloadMacOSNative}
>
<div className="mr-4">
<h2 className="mb-1 text-sm font-semibold">
{translate('widget.macos-available.title')}
</h2>
<h3 className="text-sm">
{translate('widget.macos-available.message')}
</h3>
</div>
<div className="flex items-center">
<ArrowRight size={24} />
</div>
</div>
);
};
6 changes: 6 additions & 0 deletions src/renderer/pages/Widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ import { SyncStatus } from '../../../main/background-processes/sync';
import { SyncFailed } from './SyncFailed';
import useVirtualDriveStatus from 'renderer/hooks/VirtualDriveStatus';
import { VirtualDriveError } from './VirtualDriveError';
import { MacOSVersionAvailableBanner } from './MacOSVersionAvailableBanner';
import useClientPlatform from '../../hooks/ClientPlatform';

export default function Widget() {
const [syncStatus, setSyncStatus] = useState<SyncStatus>('RUNNING');
useSyncStatus(setSyncStatus);

const platform = useClientPlatform();

const { status: virtualDriveStatus } = useVirtualDriveStatus();
const handleRetrySync = () => {
window.electron.startRemoteSync().catch((err) => {
Expand Down Expand Up @@ -50,6 +55,7 @@ export default function Widget() {
return (
<div className="flex h-screen flex-col overflow-hidden">
<Header />
{platform === 'darwin' ? <MacOSVersionAvailableBanner /> : null}
<SyncErrorBanner />
<BackupsFatalErrorBanner />
{displayErrorInWidget ? renderWidgetError() : <SyncInfo />}
Expand Down

0 comments on commit 2fb84f6

Please sign in to comment.