Skip to content

Run RefStudio in the browser#358

Merged
cguedes merged 33 commits into
mainfrom
webapp
Aug 18, 2023
Merged

Run RefStudio in the browser#358
cguedes merged 33 commits into
mainfrom
webapp

Conversation

@danvk

@danvk danvk commented Aug 16, 2023

Copy link
Copy Markdown
Collaborator

There should be no visible changes to the desktop app from this PR.

To run the web version, use:

yarn web:dev

and open http://localhost:1421/ in your browser.

I took the approach of "stub everything out until it runs". I wound up having to implement more logic in the stubs than I expected:

  • settingsManager.ts: I made a lightweight in-memory version of tauri-settings; we'll eventually want to rip this out and move settings into the Python API.
  • invoke: I made this a no-op
  • @tauri-apps/api/event: I implemented a very simple event bus
  • @tauri-apps/api/fs: I implemented an in-memory filesystem to make this API work. Eventually we'll want to connect this to an API on the Python server once we have a clearer idea about exactly the API we need for project lifecycle.

The default display looks pretty empty (this might be a bug in my in-memory FS) but you can X out the project and either create a new one or a sample one to try the editor:

try.sample.project.mov

Saving changes requires a menu bar in the app. I exposed a global emitEvent that you can call from the dev tools if you want to save a file:

save.changes.mov

See #347

@codecov

codecov Bot commented Aug 16, 2023

Copy link
Copy Markdown

Codecov Report

Merging #358 (f2dab8c) into main (c1bebd9) will increase coverage by 2.38%.
Report is 3 commits behind head on main.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main     #358      +/-   ##
==========================================
+ Coverage   84.42%   86.80%   +2.38%     
==========================================
  Files         157       16     -141     
  Lines        9372      917    -8455     
  Branches     1022        0    -1022     
==========================================
- Hits         7912      796    -7116     
+ Misses       1449      121    -1328     
+ Partials       11        0      -11     

see 150 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@danvk danvk marked this pull request as ready for review August 17, 2023 18:03
Comment thread src/api/sidecar.ts

return async () => {
const newProjectPath = await save({ defaultPath: await getNewProjectsBaseDir() });
const newProjectPath = import.meta.env.VITE_IS_WEB

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a workaround for not having a "Save" dialog on the web version.

Comment thread src/declarations/tauri-settings.d.ts
Comment thread src/events.ts
@@ -1,7 +1,8 @@
import { emit, EventCallback, listen } from '@tauri-apps/api/event';
import type { EventCallback } from '@tauri-apps/api/event';

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd enforce that only tauri-wrapper.ts can import values (not types) from @tauri-apps/api. Every other module should use the wrapper. In theory import/no-restricted-paths could enforce this but I had trouble getting it to work.

Comment thread src/events.ts
Comment thread src/settings/settingsManager.ts
Comment thread src/vite-env.d.ts
Comment thread src/wrappers/tauri-api-stubs/__tests__/fs.test.ts
type: 'dir';
}
type FakeNode = FakeFile | FakeDir;
type NormalizedPath = string & { _brand: 'normalized' };

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is that you should only put a "normalized" path (no double-slashes) in the Map. This type enforces that you've gone through normalizePath before touching the Map.

Comment thread src/wrappers/tauri-api-stubs/path.ts
@danvk danvk requested a review from cguedes August 17, 2023 18:06
@danvk danvk changed the title Run RefStudio in the browser (POC) Run RefStudio in the browser Aug 17, 2023
Comment thread src/wrappers/tauri-api-stubs/event.ts Outdated

import * as tauriEvent from '@tauri-apps/api/event';

const listeners = new Map<string, tauriEvent.EventCallback<unknown>>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danvk added support to register multiple listeners for the same event. I'm not sure if we are using that currently, but def something we might use in the future.

- suport multiple event handler for same event
- start application without project in web
- custom port for refstudio web (to run desktop and web side by side)
- startup script updated to `web:dev` t o match `tauri:dev`
cguedes
cguedes previously approved these changes Aug 18, 2023
@cguedes cguedes merged commit 8cff93a into main Aug 18, 2023
@cguedes cguedes deleted the webapp branch August 18, 2023 10:45
@cguedes cguedes linked an issue Aug 18, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Ref Studio to run locally as a web app

3 participants