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

Run RefStudio in the browser #358

Merged
merged 33 commits into from
Aug 18, 2023
Merged

Run RefStudio in the browser #358

merged 33 commits into from
Aug 18, 2023

Conversation

danvk
Copy link
Collaborator

@danvk danvk commented Aug 16, 2023

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
Copy link

codecov bot commented Aug 16, 2023

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
src/api/sidecar.ts Show resolved Hide resolved
@@ -18,7 +18,9 @@ export function useFileProjectNewListener() {
const createFile = useSetAtom(createFileAtom);

return async () => {
const newProjectPath = await save({ defaultPath: await getNewProjectsBaseDir() });
const newProjectPath = import.meta.env.VITE_IS_WEB
Copy link
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.

src/declarations/tauri-settings.d.ts Show resolved Hide resolved
@@ -1,7 +1,8 @@
import { emit, EventCallback, listen } from '@tauri-apps/api/event';
import type { EventCallback } from '@tauri-apps/api/event';
Copy link
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.

src/events.ts Show resolved Hide resolved
src/settings/settingsManager.ts Show resolved Hide resolved
src/vite-env.d.ts Show resolved Hide resolved
type: 'dir';
}
type FakeNode = FakeFile | FakeDir;
type NormalizedPath = string & { _brand: 'normalized' };
Copy link
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.

src/wrappers/tauri-api-stubs/path.ts Show resolved Hide resolved
@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

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

const listeners = new Map<string, tauriEvent.EventCallback<unknown>>();
Copy link
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
11 checks passed
@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