Skip to content

Commit

Permalink
[MS] Update GUI to use bindings in web mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-7 committed Jan 24, 2025
1 parent 518ef67 commit 51dc190
Show file tree
Hide file tree
Showing 60 changed files with 1,334 additions and 2,177 deletions.
2 changes: 2 additions & 0 deletions client/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ PARSEC_APP_TRIAL_SERVERS="trial.parsec.cloud"
PARSEC_APP_BMS_USE_MOCK="false"
PARSEC_APP_BMS_MOCKED_FUNCTIONS=""
PARSEC_APP_BMS_FAIL_FUNCTIONS=""
PARSEC_APP_CREATE_DEFAULT_WORKSPACES="true"
PARSEC_APP_CLEAR_CACHE="true"
14 changes: 8 additions & 6 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ ionic cap add ios

## Variables

| Name | Type | Description | Remark |
| ---------------------------------- | ------------------------- | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `PARSEC_APP_DEV_BMS_CREDENTIALS` | `<email>:<password>` | Used as default login credentials for the BMS | Only for development purposes! Avoid using `:` in your password as it will mess up the parsing. |
| `PARSEC_APP_BMS_USE_MOCK` | `boolean` | Used to mock calls to the BMS | Only for development purposes! |
| `PARSEC_APP_BMS_MOCKED_FUNCTIONS ` | `function1;function2;...` | Comma-separated list of functions from the BMS API to mock | Only for development purposes! |
| `PARSEC_APP_BMS_FAIL_FUNCTIONS ` | `function1;function2;...` | Comma-separated list of functions from the BMS API that should fail if mocked | Only for development purposes! |
| Name | Type | Description | Remark |
| -------------------------------------- | ------------------------- | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `PARSEC_APP_DEV_BMS_CREDENTIALS` | `<email>:<password>` | Used as default login credentials for the BMS | Only for development purposes! Avoid using `:` in your password as it will mess up the parsing. |
| `PARSEC_APP_BMS_USE_MOCK` | `boolean` | Used to mock calls to the BMS | Only for development purposes! |
| `PARSEC_APP_BMS_MOCKED_FUNCTIONS ` | `function1;function2;...` | Comma-separated list of functions from the BMS API to mock | Only for development purposes! |
| `PARSEC_APP_BMS_FAIL_FUNCTIONS ` | `function1;function2;...` | Comma-separated list of functions from the BMS API that should fail if mocked | Only for development purposes! |
| `PARSEC_APP_CREATE_DEFAULT_WORKSPACES` | `boolean` | Create default workspaces when initializing the app | Only for development purposes! |
| `PARSEC_APP_CLEAR_CACHE` | `boolean` | Clear the cache | Only for development purposes! |
20 changes: 20 additions & 0 deletions client/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ export default defineConfig({
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
testIgnore: [
'**/device_greet.spec.ts',
'**/device_join_organization.spec.ts',
'**/user_join.spec.ts',
'**/create_organization*.spec.ts',
'**/workspace_sharing.spec.ts',
'**/workspace_history.spec.ts',
'**/user_list.spec.ts',
'**/user_details.spec.ts',
'**/users_list.spec.ts',
'**/document_context_menu.spec.ts',
'**/file_import.spec.ts',
'**/file_details.spec.ts',
'**/file_viewers.spec.ts',
'**/file_viewers_document.spec.ts',
'**/file_viewers_pdf.spec.ts',
'**/documents_list.spec.ts',
'**/export_recovery_device.spec.ts',
'**/import_recovery_device.spec.ts',
],
/* Configure projects for major browsers */
projects: [
{
Expand Down
4 changes: 2 additions & 2 deletions client/src/common/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ function size(bytes: number, system: [number, string][]): Translatable {
return { key: key, data: { size: formattedAmount } };
}

export function formatFileSize(bytesize: number): Translatable {
export function formatFileSize(bytesize: number | bigint): Translatable {
const SYSTEM: [number, string][] = [
[Math.pow(1024, 0), 'common.filesize.bytes'],
[Math.pow(1024, 1), 'common.filesize.kilobytes'],
[Math.pow(1024, 2), 'common.filesize.megabytes'],
[Math.pow(1024, 3), 'common.filesize.gigabytes'],
[Math.pow(1024, 4), 'common.filesize.terabytes'],
];
return size(bytesize, SYSTEM);
return size(Number(bytesize), SYSTEM);
}

/* File icons */
Expand Down
33 changes: 17 additions & 16 deletions client/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { availableDeviceMatchesServer } from '@/common/device';
import { bootstrapLinkValidator, claimLinkValidator, fileLinkValidator } from '@/common/validators';
import appEnUS from '@/locales/en-US.json';
import appFrFR from '@/locales/fr-FR.json';
import { getLoggedInDevices, getOrganizationHandle, isElectron, listAvailableDevices, logout, needsMocks, parseFileLink } from '@/parsec';
import { getLoggedInDevices, getOrganizationHandle, isElectron, listAvailableDevices, logout, parseFileLink } from '@/parsec';
import { AvailableDevice, Platform, libparsec } from '@/plugins/libparsec';
import { Env } from '@/services/environment';
import { Events } from '@/services/eventDistributor';
Expand Down Expand Up @@ -55,6 +55,13 @@ function preventRightClick(): void {
});
}

function warnRefresh(): void {
window.addEventListener('beforeunload', async (event) => {
event.preventDefault();
event.returnValue = true;
});
}

async function initViewers(): Promise<void> {
pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

Expand Down Expand Up @@ -161,20 +168,10 @@ async function setupApp(): Promise<void> {
app.provide(ThemeManagerKey, themeManager);

if ((await libparsec.getPlatform()) === Platform.Web) {
if (!needsMocks()) {
// Only called when the user has interacted with the page
window.addEventListener('beforeunload', async (event: BeforeUnloadEvent) => {
event.preventDefault();
event.returnValue = true;
});

window.addEventListener('unload', async (_event: Event) => {
// Stop the imports and properly logout on close.
await cleanBeforeQuitting(injectionProvider);
});
} else {
Sentry.disable();
}
window.addEventListener('unload', async (_event: Event) => {
// Stop the imports and properly logout on close.
await cleanBeforeQuitting(injectionProvider);
});
}

window.electronAPI.pageIsInitialized();
Expand All @@ -186,6 +183,7 @@ async function setupApp(): Promise<void> {
// - dev or prod where devices are fetched from the local storage
// - tests with Playwright where the testbed instantiation is done by Playwright
if ('TESTING' in window && window.TESTING) {
Sentry.disable();
// handle the testbed and provides the configPath
window.nextStageHook = (): any => {
return [libparsec, nextStage];
Expand Down Expand Up @@ -358,7 +356,10 @@ function setupMockElectronAPI(): void {
console[level](`[MOCKED-ELECTRON-LOG] ${message}`);
},
pageIsInitialized: (): void => {
window.isDev = (): boolean => needsMocks();
window.isDev = (): boolean => Boolean(import.meta.env.PARSEC_APP_TESTBED_SERVER);
if (!window.isDev()) {
warnRefresh();
}
},
openConfigDir: (): void => {
console.log('OpenConfigDir: Not available');
Expand Down
Loading

0 comments on commit 51dc190

Please sign in to comment.