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

Create WebViewProvider API, allowing webviews to persist across refreshes #225

Merged
merged 18 commits into from
Jun 13, 2023

Conversation

tjcouch-sil
Copy link
Member

@tjcouch-sil tjcouch-sil commented Jun 7, 2023

  • Reworked loading and saving tabs so every tab is responsible for its own serialization and deserialization
  • Split tab ids into id and tabType
  • Tightened up layout-related types for better TypeScript support
  • Moved saving and loading layout to web view service
  • Created web view provider service that handles web view providers specifically. Each provider is distinct from other providers by having a unique webViewType, which is how the contents of webviews is determined
    • This service is a weird split off from web view service, so I made it internal and not affect extension developers. Seems like a helpful distinction, though. Would love input on any thoughts regarding reworking it. Maybe make a singleton class in web view service? Dunno; not sure it's even worth it right now. Might be best to make an issue if it even warrants it
  • Reworked addWebView so you provide just a webViewType, layout info, and some options. Then the appropriate WebViewProvider takes care of actually making the web view
  • onDidAddWebView event no longer carries content or styles so there's not so much unnecessary talk all over the network over webviews
  • Added a button on the (newly renamed) People webview that opens a new People webview :)
    image

Also created PR on rc-dock for the patch included in this PR: ticlo/rc-dock#208

Resolves #177


This change is Reviewable

Copy link
Member Author

@tjcouch-sil tjcouch-sil left a comment

Choose a reason for hiding this comment

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

Oops - this is supposed to be a draft PR. Sorry! Thanks for previewing and giving feedback :)

Reviewable status: 0 of 25 files reviewed, all discussions resolved

@irahopkinson
Copy link
Contributor

There is a Convert to draft link button top-right in the reviewers section of the side-bar - hard to spot though.

Copy link
Contributor

@irahopkinson irahopkinson left a comment

Choose a reason for hiding this comment

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

I've run out of time to look at everything today but I'll publish what I have so far. Do note there are some tests failing which is why the GitHub checks aren't happy yet.

Reviewed 15 of 25 files at r1, all commit messages.
Reviewable status: 15 of 25 files reviewed, 8 unresolved discussions (waiting on @tjcouch-sil)


extensions/lib/hello-world/hello-world.ts line 43 at r1 (raw file):

const reactWebViewType = 'hello-world.react';

const reactWebViewProvider: IWebViewProvider = {

BTW this is the 3rd copy of this code. What about supplying a webViewProviderFactory function or is this likely to be different for other WebViews?


extensions/lib/hello-world/hello-world.ts line 93 at r1 (raw file):

  // anywhere; it just has to match `webViewType`. See `hello-someone.ts` for an example of keeping
  // an existing webview that was specifically created by `hello-someone`.
  papi.webViews.addWebView(htmlWebViewType, undefined, { existingId: '*' });

BTW how about making this the default options in addWebView, then this call (and the one below) would simplify nicely. A unique WebView is likely the default, right?

Code quote:

{ existingId: '*' }

src/shared/data/web-view.model.ts line 158 at r1 (raw file):

export type AddWebViewOptions = {
  /**
   * If provided, requests from the web view provider an existing existing WebView with this id

This sentence needs some revising to clarify meaning.


src/shared/models/web-view-provider.model.ts line 22 at r1 (raw file):

  getWebView(
    serializedWebView: WebViewDefinitionSerialized,
    addWebViewOptions: AddWebViewOptions,

BTW it appears this argument is optional (at least in hello-someone.ts and hello-world.ts)?


src/shared/models/web-view-provider.model.ts line 31 at r1 (raw file):

    CanHaveOnDidDispose<IWebViewProvider> {}

// What the papi returns on register. Basically a layer over DisposableNetworkObject

Err... how can it be called DisposableWebViewProvider when it omits dispose?


src/shared/services/web-view-provider.service.ts line 49 at r1 (raw file):

 * it unless something else in the existing process is subscribed to it.
 */
function hasKnown(webViewType: string): boolean {

BTW I haven't figured out yet why you choose a standard function or an arrow function. Above you have 2 arrow functions - one tiny and one longer. Here it's also tiny but a function. What's the criteria you use for choosing between them?


src/shared/services/web-view-provider.service.ts line 78 at r1 (raw file):

  // Set up the WebView provider to be a network object so other processes can use it
  const disposableWebViewProvider = (await networkObjectService.set(

BTW you don't need to us as here but instead:

  const disposableWebViewProvider: DisposableWebViewProvider = await networkObjectService.set(
    webViewProviderObjectId,
    webViewProvider,
  );

Perhaps this amounts to the same thing but is slightly cleaner without extra brackets.


src/shared/services/web-view.service.ts line 123 at r1 (raw file):

  const webViewDefinitionCloned: Omit<WebViewDefinition, 'content'> &
    Partial<Pick<WebViewDefinition, 'content'>> &
    Partial<Pick<WebViewDefinitionReact, 'styles'>> = { ...webViewDefinition };

BTW the spread opertator won't do a deep clone but I guess that's all you need here, right?

@tjcouch-sil tjcouch-sil marked this pull request as draft June 8, 2023 13:13
Copy link
Contributor

@irahopkinson irahopkinson left a comment

Choose a reason for hiding this comment

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

Reviewed 10 of 25 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: all files reviewed, 35 unresolved discussions (waiting on @tjcouch-sil)


src/renderer/components/web-view.component.tsx line 57 at r2 (raw file):

}

export default function loadWebViewPanel(savedTabInfo: SavedTabInfo): TabInfo {

This is really loading a WebView tab. Panel has a different meaning in rc-dock so this could be confusing to use panel here. How about loadWebViewTab?

Same for saveWebViewPanel below.

Code quote:

loadWebViewPanel

src/renderer/components/web-view.component.tsx line 57 at r2 (raw file):

}

export default function loadWebViewPanel(savedTabInfo: SavedTabInfo): TabInfo {

BTW I'm not sure if this should remain the default export. I don't have a strong opinion but my instinct is to remove the default now we have other valid exports and we load all 3 in the only place we import them. This is our next item to discuss for styles but this seems a clearer example than some of the other edge cases we need to discuss. Feel free to leave it as is if you feel differently.

Code quote:

default

src/renderer/components/web-view.component.tsx line 71 at r2 (raw file):

    // deserialize the web view. It will asynchronously go get the content and re-run this function
    if (!data.content && data.content !== '')
      (async () => {

The anonymous self-calling function seems a little funky here. How about a named async function that we pass in data to it but don't await when we call it here? E.g. if (!data.content && data.content !== '') getWebViewContent(data);


src/renderer/components/docking/paranext-dock-layout.component.tsx line 62 at r2 (raw file):

const tabLoaderMap = new Map<TabType, TabLoader>([
  [TAB_TYPE_ABOUT, loadAboutPanel],

I think these should all be renamed load<feature>Tab.


src/renderer/components/docking/paranext-dock-layout.component.tsx line 76 at r2 (raw file):

function loadSavedTabInfo(tabInfo: SavedTabInfo): TabInfo {
  const tabLoader = tabLoaderMap.get(tabInfo.tabType);
  if (!tabLoader) return createErrorTab(`No tab loader for tabType '${tabInfo.tabType}'`);

BTW this should be renamed to match the new pattern of loadErrorTab.


src/renderer/components/docking/paranext-dock-layout.component.tsx line 87 at r2 (raw file):

}

type RCDockTabInfo = TabData & Omit<TabInfo, 'title'> & { tabInfoTitle: string };

BTW types should probably be grouped together at the top of the file after imports and before consts. It makes it easier to find and keep them organised and to refactor them into .model.ts files if they are needed elsewhere.


src/renderer/components/docking/paranext-dock-layout.component.tsx line 103 at r2 (raw file):

  return {
    ...tabInfo,
    tabInfoTitle: tabInfo.title,

BTW would it be better to already have it saved this way inside tabInfo so there is no special case here for title and would also simplify things in the saveTab function?


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 77 at r2 (raw file):

      expect(() => loadTab(savedTabInfoNone)).toThrow();
      expect(() => loadTab(savedTabInfoNoId)).toThrow();

These 2 added expects don't add anything to the tests other than more running time. Revert the changes other than the as. If you want to check that no tabType causes a throw then add a new it block and define an id so it gets through the first throw check that this it block tests.


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 87 at r2 (raw file):

      const event: AddWebViewEvent = { webView: {} as WebViewProps, layout: { type: 'tab' } };

      expect(() => addWebViewToDock(event, dockLayout)).toThrow();

In my VSCode this line is complaining that "Expected 3 arguments, but got 2".


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 95 at r2 (raw file):

      const dockLayout = instance(mockDockLayout);
      const event: AddWebViewEvent = {
        webView: { id: 'myId', webViewType: 'test', content: '' },

content is not defined in AddWebViewEvent - you can probably just remove it.


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 99 at r2 (raw file):

      };

      expect(() => addWebViewToDock(event, dockLayout)).toThrow();

In my VSCode this line is complaining that "Expected 3 arguments, but got 2".


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 111 at r2 (raw file):

      const dockLayout = instance(mockDockLayout);
      const event: AddWebViewEvent = {
        webView: { id: 'myId', webViewType: 'test', content: '' },

content is not defined in AddWebViewEvent - you can probably just remove it.


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 115 at r2 (raw file):

      };

      expect(() => addWebViewToDock(event, dockLayout)).toThrow();

In my VSCode this line is complaining that "Expected 3 arguments, but got 2".


src/shared/data/web-view.model.ts line 109 at r2 (raw file):

 * {@link WebViewDefinition}s and verify any existing properties on the WebViews.
 */
export type WebViewDefinitionSerialized =

BTW maybe a better name is SavedWebViewDefinition?


src/shared/services/web-view.service.ts line 111 at r2 (raw file):

}

export function saveTabInfoBase(tabInfo: TabInfo): SavedTabInfo {

This might be better named savedTabInfoBase (added a 'd') since it doesn't actually do any saving but returns saved info.


src/shared/services/web-view.service.ts line 147 at r2 (raw file):

let papiDockLayoutVar = createDockLayoutAsyncVar();

export type OnLayoutChangeEventInternal = {

BTW this is not really internal in the traditional sense since it's exported. It's really the arguments for rc-dock's onLayoutChange method (unless thats what you mean by 'internal')?


src/shared/services/web-view.service.ts line 157 at r2 (raw file):

  onLayoutChange: PapiEvent<OnLayoutChangeEventInternal>;
  addWebViewToDock: (webView: WebViewProps, layout: Layout) => void;
  testLayout: LayoutBase;

BTW it feels like this should be called something else unless you expect it to simply be removed later on?


src/shared/services/web-view.service.ts line 160 at r2 (raw file):

};

const DOCK_LAYOUT_KEY = 'dock-saved-layout';

This should be at the top of the file along with the other consts below the imports.


src/shared/services/web-view.service.ts line 174 at r2 (raw file):

}

async function saveLayout(layout?: LayoutBase): Promise<void> {

I know you talked about moving this here when I was working on the rc-dock stuff but I think I need some help understanding the need since it highly complicates things and moves it out of it's natural encapsulation.


src/shared/services/web-view.service.ts line 175 at r2 (raw file):

async function saveLayout(layout?: LayoutBase): Promise<void> {
  const currentLayout = layout || (await papiDockLayoutVar.promise).dockLayout.saveLayout();

I can't figure out when layout would be optional since the only call to this is in onLayoutChange and it's pasing a value in there. If you are meaning that the value could be undefined then it would be better to declare that rather then make the argument optional (I know they amount to almost the same thing but they read differently). And even then the calling function says it is defined so maybe it needs fixing there too?


src/shared/services/web-view.service.ts line 179 at r2 (raw file):

}

async function loadLayout(layout?: LayoutBase): Promise<void> {

Conversely loadLayout doesn't ever appear to be called with an argument. If so why is it declared? Probably remove the argument.


src/shared/services/web-view.service.ts line 187 at r2 (raw file):

    // A layout was provided, meaning this is a layout change. Since `dockLayout.loadLayout` doesn't
    // run `onLayoutChange`, we run it manually
    await onLayoutChange({ newLayout: layoutToLoad });

This will never get called since the layout argument is never provided. Remove the if block. (BTW I think you will find that the onLayoutChange from rc-dock DOES get called after it runs it's loadTab method.)


src/shared/services/web-view.service.ts line 213 at r2 (raw file):

  loadLayout();

  // Return an unsubscriber ot unregister this dock layout. The primary situation in which I see

typo: 'ot'

Code quote:

ot

src/shared/services/web-view.service.ts line 245 at r2 (raw file):

 * @returns promise that resolves nothing if we successfully handled the webView
 */
export const addWebView = async (

The use of this function has changed. Perhaps rename to showWebView or getWebView (this name is already used in the provider so maybe it makes sense here also or not)?


src/shared/services/web-view.service.ts line 248 at r2 (raw file):

  webViewType: WebViewType,
  layout: Layout = { type: 'tab' },
  options: AddWebViewOptions = {},

BTW could we default this to the single WebView usage, i.e. { existingId: '*' } ?


src/shared/services/web-view.service.ts line 250 at r2 (raw file):

  options: AddWebViewOptions = {},
): Promise<WebViewId | undefined> => {
  const optionsDef = addWebViewOptionsDefaults(options);

BTW prefer unabbreviated names from our style guide. Perhaps use optionDefaults or optionsDefaulted?


src/shared/services/web-view.service.ts line 312 at r2 (raw file):

            // Find any webview with the specified webViewType
            return (item.data as WebViewDefinition).webViewType === webViewType;

BTW this will only ever find the first one of that type. Should we allow the use of '*' if there is more than one of that type? I guess that would be programmer error to use that with more than one available?

Copy link
Member Author

@tjcouch-sil tjcouch-sil left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 27 unresolved discussions (waiting on @irahopkinson)


extensions/lib/hello-world/hello-world.ts line 43 at r1 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW this is the 3rd copy of this code. What about supplying a webViewProviderFactory function or is this likely to be different for other WebViews?

How the code is right now, I think it might be a bit valuable - we may get a few lines back. However, I think introducing state will almost certainly cause every one of these to be very different. As such, I think I'd like to leave it.


extensions/lib/hello-world/hello-world.ts line 93 at r1 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW how about making this the default options in addWebView, then this call (and the one below) would simplify nicely. A unique WebView is likely the default, right?

It makes most sense to me when thinking about how this function will be used in the future to leave the default to be creating a new one (among our current options). Most of the time, people aren't going to make an ever-existing webview that shows solely because their extension is running. Actually, I don't know when that would be something someone would want to do. I imagine that, most of the time, it would be something like someone goes to a menu and presses a button to open the Interlinear for a project for example. That would not just look for any existing interlinear but would rather look for a specific one tied to the project or open a new one. Since we don't have project-specific anything right now, I figure the best default is to leave it to create a new one.

If we made { existingId: '*' } the default, that would mean that, unless someone specifies otherwise, running addWebView will always use any web view that is already showing if one is showing (whether it was created in this same context or another context). I don't imagine that would be super common. I mostly added it to make doing what we're doing now easier.


src/renderer/components/web-view.component.tsx line 57 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

This is really loading a WebView tab. Panel has a different meaning in rc-dock so this could be confusing to use panel here. How about loadWebViewTab?

Same for saveWebViewPanel below.

Done.


src/renderer/components/web-view.component.tsx line 57 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW I'm not sure if this should remain the default export. I don't have a strong opinion but my instinct is to remove the default now we have other valid exports and we load all 3 in the only place we import them. This is our next item to discuss for styles but this seems a clearer example than some of the other edge cases we need to discuss. Feel free to leave it as is if you feel differently.

Good thought. I agree. Done. I will make the component itself the default since that's what the file is named.


src/renderer/components/web-view.component.tsx line 71 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

The anonymous self-calling function seems a little funky here. How about a named async function that we pass in data to it but don't await when we call it here? E.g. if (!data.content && data.content !== '') getWebViewContent(data);

Done.


src/renderer/components/docking/paranext-dock-layout.component.tsx line 76 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW this should be renamed to match the new pattern of loadErrorTab.

I disagree in this case. createErrorTab doesn't do the same thing as the others. It isn't loading anything; it's creating a new tab with a specific error message. Let me know your thoughts. Thanks!


src/renderer/components/docking/paranext-dock-layout.component.tsx line 87 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW types should probably be grouped together at the top of the file after imports and before consts. It makes it easier to find and keep them organised and to refactor them into .model.ts files if they are needed elsewhere.

Agreed. I just didn't get around to that yet. Thanks for pointing it out - helps me to remember! :)


src/renderer/components/docking/paranext-dock-layout.component.tsx line 103 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW would it be better to already have it saved this way inside tabInfo so there is no special case here for title and would also simplify things in the saveTab function?

Done.


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 77 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

These 2 added expects don't add anything to the tests other than more running time. Revert the changes other than the as. If you want to check that no tabType causes a throw then add a new it block and define an id so it gets through the first throw check that this it block tests.

Oh oops, I forgot to put stuff in the objects to make these tests unique! Thanks for catching. Done.


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 87 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

In my VSCode this line is complaining that "Expected 3 arguments, but got 2".

Yep, I just didn't fix all the tests yet. Done.


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 95 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

content is not defined in AddWebViewEvent - you can probably just remove it.

Done. Yep, I just didn't fix all the tests yet.


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 99 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

In my VSCode this line is complaining that "Expected 3 arguments, but got 2".

Done. Yep, I just didn't fix all the tests yet.


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 111 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

content is not defined in AddWebViewEvent - you can probably just remove it.

Done. Yep, I just didn't fix all the tests yet.


src/renderer/components/docking/paranext-dock-layout.component.test.ts line 115 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

In my VSCode this line is complaining that "Expected 3 arguments, but got 2".

Done. Yep, I just didn't fix all the tests yet.


src/shared/data/web-view.model.ts line 158 at r1 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

This sentence needs some revising to clarify meaning.

Done.


src/shared/data/web-view.model.ts line 109 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW maybe a better name is SavedWebViewDefinition?

Done


src/shared/models/web-view-provider.model.ts line 22 at r1 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW it appears this argument is optional (at least in hello-someone.ts and hello-world.ts)?

Actually the argument is not optional. addWebView passes an addWebViewOptions in every time. However, WebViewProviders do not need to list this argument if they do not use it. This is normal TypeScript functionality.


src/shared/models/web-view-provider.model.ts line 31 at r1 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

Err... how can it be called DisposableWebViewProvider when it omits dispose?

DisposableNetworkObject has dispose on it. WebViewProvider has an optional dispose that messes things up when using it as DisposableNetworkObject definitely has dispose. So I omit it here. Same thing happens in the DataProvider types.


src/shared/services/web-view-provider.service.ts line 49 at r1 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW I haven't figured out yet why you choose a standard function or an arrow function. Above you have 2 arrow functions - one tiny and one longer. Here it's also tiny but a function. What's the criteria you use for choosing between them?

Basically no criteria whatsoever. When I started making these services months ago, I was a bit afraid of closures (because I didn't understand them as well as I do now), so I used more arrow functions. These days, I generally use functions in services. I think I probably just left each function as it was when I copied it from data-provider.service.ts


src/shared/services/web-view-provider.service.ts line 78 at r1 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW you don't need to us as here but instead:

  const disposableWebViewProvider: DisposableWebViewProvider = await networkObjectService.set(
    webViewProviderObjectId,
    webViewProvider,
  );

Perhaps this amounts to the same thing but is slightly cleaner without extra brackets.

Sounds good. Thanks!


src/shared/services/web-view.service.ts line 123 at r1 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW the spread opertator won't do a deep clone but I guess that's all you need here, right?

Right. At least for current needs, I don't need to deep clone. Shallow clone works fine.


src/shared/services/web-view.service.ts line 111 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

This might be better named savedTabInfoBase (added a 'd') since it doesn't actually do any saving but returns saved info.

Discussed and will pass on this - this function saves similarly to how the other tab savers do (not saving at all ;) )


src/shared/services/web-view.service.ts line 147 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW this is not really internal in the traditional sense since it's exported. It's really the arguments for rc-dock's onLayoutChange method (unless thats what you mean by 'internal')?

The event was called internal because it was supposed to be solely a means of communication between paranext-dock-layout.component.tsx and web-view.service.ts. However, I decided instead of renaming or something, I'd just refactor it. There is no longer an internal event.


src/shared/services/web-view.service.ts line 157 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW it feels like this should be called something else unless you expect it to simply be removed later on?

Yes, this will hopefully be removed in the future. Potentially addWebViewToDock as well. The reason they are here is that I needed to leave some of the imports in the paranext-dock-layout.components.tsx file because this service is shared. When we refactor this service to split it between different processes well instead of sharing all of its code, we can fix this and actually just import testLayout. I added comments about this and added a comment to #203 as well.


src/shared/services/web-view.service.ts line 160 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

This should be at the top of the file along with the other consts below the imports.

Yep, needed to go back and clean up the code including moving things to where they should go :)


src/shared/services/web-view.service.ts line 174 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

I know you talked about moving this here when I was working on the rc-dock stuff but I think I need some help understanding the need since it highly complicates things and moves it out of it's natural encapsulation.

I think the work of saving and loading layouts is more general and does not belong in a React component which would preferably be just UI work. If we have our layout functions here, we can call them from other places as well. It seems in my mind that the work of saving and loading layouts should not be tightly coupled to the React code but should be in a service and minimally connected (in this case, through registerDockLayout). I think I made it rather messy right now because there are a number of layout utility functions in paranext-dock-layout.component.tsx, but they are only in there because they import renderer code and we unfortunately have not yet implemented #203. I added a comment to move the rest of the layout functions here for #203.


src/shared/services/web-view.service.ts line 175 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

I can't figure out when layout would be optional since the only call to this is in onLayoutChange and it's pasing a value in there. If you are meaning that the value could be undefined then it would be better to declare that rather then make the argument optional (I know they amount to almost the same thing but they read differently). And even then the calling function says it is defined so maybe it needs fixing there too?

Fixed.


src/shared/services/web-view.service.ts line 179 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

Conversely loadLayout doesn't ever appear to be called with an argument. If so why is it declared? Probably remove the argument.

After discussing, we decided we would leave this in as it will likely be used later.


src/shared/services/web-view.service.ts line 187 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

This will never get called since the layout argument is never provided. Remove the if block. (BTW I think you will find that the onLayoutChange from rc-dock DOES get called after it runs it's loadTab method.)

It appears setLayout does run onLayoutChange but loadLayout does not. Tested that loadLayout does indeed not run onLayoutChange.


src/shared/services/web-view.service.ts line 245 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

The use of this function has changed. Perhaps rename to showWebView or getWebView (this name is already used in the provider so maybe it makes sense here also or not)?

Renamed to getWebView


src/shared/services/web-view.service.ts line 248 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW could we default this to the single WebView usage, i.e. { existingId: '*' } ?

See response in hello-world.ts - my preference would be to leave it.


src/shared/services/web-view.service.ts line 250 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW prefer unabbreviated names from our style guide. Perhaps use optionDefaults or optionsDefaulted?

Done


src/shared/services/web-view.service.ts line 312 at r2 (raw file):

Previously, irahopkinson (Ira Hopkinson) wrote…

BTW this will only ever find the first one of that type. Should we allow the use of '*' if there is more than one of that type? I guess that would be programmer error to use that with more than one available?

We discussed and decided the meaning I am trying to achieve here is 'any', not 'all', so I changed to '?'

irahopkinson
irahopkinson previously approved these changes Jun 13, 2023
Copy link
Contributor

@irahopkinson irahopkinson left a comment

Choose a reason for hiding this comment

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

:lgtm: thanks for all your hard work on this.

Reviewed 18 of 18 files at r3, 9 of 9 files at r4, 2 of 2 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @tjcouch-sil)


src/renderer/components/web-view.component.tsx line 57 at r2 (raw file):

Previously, tjcouch-sil (TJ Couch) wrote…

Good thought. I agree. Done. I will make the component itself the default since that's what the file is named.

Even better. Thanks for doing it for the other built-in tabs also.


src/renderer/components/web-view.component.tsx line 59 at r5 (raw file):

/**
 * Tell the web view service to deserialize the web view with the provided serialized definition

BTW use 'load' and 'save' rather than 'deserialize' and 'serialize' here?

@tjcouch-sil tjcouch-sil marked this pull request as ready for review June 13, 2023 03:06
@tjcouch-sil tjcouch-sil enabled auto-merge June 13, 2023 03:07
Copy link
Contributor

@irahopkinson irahopkinson left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @tjcouch-sil)

@tjcouch-sil tjcouch-sil merged commit ba1dee3 into main Jun 13, 2023
@tjcouch-sil tjcouch-sil deleted the 177-web-view-provider branch June 13, 2023 03:16
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.

Create WebViewProvider API
2 participants