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

feat: add Webiew::navigate_to_url, closes #776 #777

Merged
merged 5 commits into from Nov 30, 2022
Merged

Conversation

amrbashir
Copy link
Member

@amrbashir amrbashir commented Nov 29, 2022

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

@amrbashir amrbashir requested a review from a team as a code owner November 29, 2022 12:50
src/webview/mod.rs Outdated Show resolved Hide resolved
@wusyong wusyong merged commit a2b9531 into dev Nov 30, 2022
@wusyong wusyong deleted the feat/navigate-to-url branch November 30, 2022 11:14
@github-actions github-actions bot mentioned this pull request Nov 30, 2022
@patientplatypus6
Copy link

patientplatypus6 commented Dec 24, 2022

Some quick comments, because this looks like it would be important for the usefulness of the library.
First, this feature is not yet in the main branch of the library and I would encourage you to push it as soon as possible. What I am doing is using an IPC_Channel (through Servo, not between Javascript code) to run this library in conjunction with Rust/Iced.

Here's is what I'm working on -
https://github.com/patientplatypus6/ipciceexample
Specifically, I'd like to be able to programmatically push new URLs based on state changes that occur at top level - see line marked below. I can save local state in an enum, but I can't push a new URL.
https://github.com/patientplatypus6/ipciceexample/blob/main/webview/src/main.rs#L84

This is a blocking issue for what I'm working on, so whenever this happens to be pushed into the main branch if you could be so kind as to just respond to this comment so I can repull the repo that would be helpful.

Thanks for all your hard work on this library. Merry Christmas and Happy Holidays.

@amrbashir
Copy link
Member Author

@patientplatypus6
Copy link

patientplatypus6 commented Dec 25, 2022

Thanks for the reply. It took me a little bit of thinking in how this was supposed to work. Sorry I am unfamiliar with the library. Here is an example page on how you can pass a load_url.

The important bit is that you can pass the webview that is returned from the builder

    let webview = WebViewBuilder::new(window)?
      .with_url(url)?
      .build()?;

into the eventloop.run which I didn't think was possible for some reason -


    event_loop.run(move |event, x, control_flow| {
      *control_flow = ControlFlow::Wait;
      match event {
        Event::NewEvents(StartCause::Init) => {
            newstate = data_handler(prevstate.clone());
        },
        Event::MainEventsCleared => {
            if Some(newstate.data.clone()) != Some(prevstate.data.clone()) {  
                println!("newstate.data.clone() {:?}", newstate.data.clone());
                let newstatedata = newstate.data.clone().unwrap();
                let newstateparent = newstate.parent.clone().unwrap();
                println!("value of newstatedata: {:?}", newstatedata);
                state_updated(newstatedata, newstateparent);
                prevstate = newstate.clone();
                let newurl = "https://www.reddit.com".to_string();
                proxy.send_event(UserEvent::Navigation(newurl.clone()));
            }
        },
        Event::UserEvent(UserEvent::Navigation(uri)) => {
            println!("{}", uri);
            let url = uri.clone();
            println!("value of url {:?}", url); 
            webview.load_url(&uri);
        },
        Event::WindowEvent {
          event: WindowEvent::CloseRequested,
          ..
        } => *control_flow = ControlFlow::Exit,
        _ => (),
      }
    });
  }

webview.load_url(&uri) would be available under the arm Event::UserEvent(UserEvent::Navigation(uri)) => { in the match statement. Here is a link to my repo.

https://github.com/patientplatypus6/ipciceexample/blob/main/webview/src/main.rs#L85

Thanks again for the reply and working on this library.

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.

None yet

3 participants