chromelyapps / Chromely

Build Cross Platform HTML Desktop Apps on .NET using native GUI, HTML5, JavaScript, CSS, Owin, AspNetCore (MVC, RazorPages, Blazor)
MIT License
2.98k stars 278 forks source link

Custom button to close browser #353

Closed kennethlou closed 2 years ago

kennethlou commented 2 years ago

Hi,

Do you know how to close the browser via a custom made button? i.e. at the line 33 in main:

line 33 AppBuilder.Create().UseConfig(config).UseApp().Build().Run(args); line 34 int test = 1;

the browser is created in front of the user. Is there any way to have a button with a small piece of code to close it then line 34 will be run?

I am not looking for Application Exit as it will kill the whole process. I just want to close the browser.

Regards,

mattkol commented 2 years ago

@kennethlou I am not sure there is an easy way the way we are setup, but if you can get your hands dirty there might be a way. Others can help too.

The first thing I would do is to identify the browser process and shut it down (in a timer, perhaps) to see what happens. You can identify the browser process by using -

https://github.com/chromelyapps/demo-projects/blob/860dfced1d22ca4004f3be593b3b7cc7f5395c54/web-chromely/web-chromely-mvc/Program.cs#L30

 var proctype = ClientAppUtils.GetProcessType(args);
 if (proctype == ProcessType.Browser) 
 {
      Process currentProcess = Process.GetCurrentProcess();
 }

You can put the code before "line 33".