[Pharo-users] Re: Pharo-WebView

2022-01-05 Thread Tomaž Turk

Dear all,

Pharo-Webview works on Windows 10 64-bit and Linux 64-bit (tested on 
Ubuntu 20.04). The needed webview.so dynamic library is available within 
the repository at https://github.com/eftomi/Pharo-Webview. On Linux use 
headless VM.


There's also a webview.dylib for MacOS if someone wants to try it (built 
on Monterey), however I wasn't successful on this platform, despite the 
fact that I tried TFWorker and TFMainThreadRunner approaches, too. I'm 
also not keen on Cocoa.


The library itself lacks a better support for webview create-destroy 
mechanisms although it could be upgraded. I achieved my needed 
functionality and unfortunatelly don't have time to continue. Maybe I'll 
continue in next months, but according to my experiences so far it would 
be better to choose a slightly heavier but cleaner Photino 
(https://www.tryphotino.io/) or something else. Or maybe to work on pure 
Pharo approach :-)


One of the interesting challenges is a double nature of Pharo - 
interactive and "headless" mode - meaning that the application runs 
without Pharo GUI. It'd be nice if both approaches would be possible. 
The library that I used builds on the headless idea, where the main GUI 
loop is supposed to be taken over by the webview, which is the main 
reason for "create-destroy" challenge if you use it interactively. This 
multiplied by USER32.DLL, Gtk3, and Cocoa ...


Best wishes,
Tomaz

[Pharo-users] Re: Pharo-WebView

2021-12-28 Thread Tomaž Turk

Short report on webview porting:
- on Windows (Edge, Edge/Chrome) it works single threaded, it is more or 
less done, needs some rigorous stability testing,
- on Linux/Ubuntu (gtk3, webkit2gtk) almost done, it works as a separate 
TFWorker thread, still needs some process status checking if webview 
window is closed by user.
- on MacOS (Cocoa, WebKit) I got hold of an older Mac (Sierra) where 
WebKit doesn't support clipboard operations, but I have made a dynamic 
library without clipboard support just to continue the development. If 
anyone is curious, for compilation you need gcc (available here: 
https://github.com/kennethreitz/osx-gcc-installer). Then get webview.h 
and webview.cc from https://github.com/webview/webview and compile it 
with:


c++ -dynamiclib webview.cc -std=c++11 -framework WebKit -o 
libwebview.dylib


After some more tests on Windows and Linux I'll pack all the libs on 
GitHub and update the readme.


Happy holidays,
Tomaz



[Pharo-users] Re: Pharo-WebView

2021-12-23 Thread Russ Whaley
I tried to run the commands in terminal in MacOS... it didn't even (nor did
I) understand 'go' so we were both stymied at step one (lol).  I'll pick it
up again after the holidays and give it another try with my full attention.

Happy Holidays,
Russ

On Thu, Dec 23, 2021 at 1:06 PM  wrote:

> @Todd, @Russ, yes, with Gtk3 it's a bit harder than I expected.
>
> Gtk3 has a main message loop gtk_main() which, as it is being used in the 
> webview
> library  that I chose, blocks Pharo
> completely while webview window is active. On Windows, the webview window
> in general works without engaging the main message loop, but windows
> implementation doesn't rely on Gtk3 but on Edge.
>
> On Linux, I firstly tried to put this webview library into a separate
> thread (a worker with headless image), however in this kind of setup the
> callbacks from the library cannot reach Pharo main thread. I solved this by
> exposing two additional Gtk3 functions in webview library,
> gtk_events_pending() and gtk_main_iteration() which enabled the
> construction of main event loop in Pharo that I run on the Idle Process
> priority level so that it doesn't take 100% of the processor time, like
> this:
>
> proc := [[ true ]
>
> whileTrue: [
>
> (wv ffiEventsPending = 1) ifTrue:
>
> [wv ffiRunIteration].
>
> Processor yield.
>
> ]] forkAt: Processor lowestPriority.
>
> So I don't need to run the webview library in separate thread, which is a
> bit simpler, and the callbacks work as they should. Now I just have to
> create some signaling so that Pharo will know if the user closes the
> webview window, and check if two Pharo classes that I already have (WebView
> and WebViewCallback) will suffice for these additional complications.
>
> If anybody has a better idea for main loop implementation, I'm opened to
> suggestions :-)
>
> The webview library that I chose uses Cocoa on MacOS, so no Gtk3 there. I
> hope that it will not be too difficult and that the above "one thread
> approach" will be OK for MacOS, too. Gtk3 was quite challenging, I was also
> considering to drop whis webview library and use gtk-bindings for Pharo
> directly, however then I would not be consistent also for Edge and Cocoa
> (in using one "umbrella" library). As far as I know, the webview general
> intention is to use the native GUI technology as much as possible.
>
> Best wishes,
> Tomaz
>


-- 
Russ Whaley
whaley.r...@gmail.com


[Pharo-users] Re: Pharo-WebView

2021-12-23 Thread tomazz . turk
@Todd, @Russ, yes, with Gtk3 it's a bit harder than I expected. 

Gtk3 has a main message loop gtk_main() which, as it is being used in the 
[webview library](https://github.com/webview/webview) that I chose, blocks 
Pharo completely while webview window is active. On Windows, the webview window 
in general works without engaging the main message loop, but windows 
implementation doesn't rely on Gtk3 but on Edge. 

On Linux, I firstly tried to put this webview library into a separate thread (a 
worker with headless image), however in this kind of setup the callbacks from 
the library cannot reach Pharo main thread. I solved this by exposing two 
additional Gtk3 functions in webview library, gtk_events_pending() and 
gtk_main_iteration() which enabled the construction of main event loop in Pharo 
that I run on the Idle Process priority level so that it doesn't take 100% of 
the processor time, like this:

`proc := [[ true ] `

`   whileTrue: [ `

`   (wv ffiEventsPending = 1) ifTrue: `

`   [wv ffiRunIteration]. `

`   Processor yield.`

`   ]] forkAt: Processor lowestPriority.`

So I don't need to run the webview library in separate thread, which is a bit 
simpler, and the callbacks work as they should. Now I just have to create some 
signaling so that Pharo will know if the user closes the webview window, and 
check if two Pharo classes that I already have (WebView and WebViewCallback) 
will suffice for these additional complications.

If anybody has a better idea for main loop implementation, I'm opened to 
suggestions :-)

The webview library that I chose uses Cocoa on MacOS, so no Gtk3 there. I hope 
that it will not be too difficult and that the above "one thread approach" will 
be OK for MacOS, too. Gtk3 was quite challenging, I was also considering to 
drop whis webview library and use gtk-bindings for Pharo directly, however then 
I would not be consistent also for Edge and Cocoa (in using one "umbrella" 
library). As far as I know, the webview general  intention is to use the native 
GUI technology as much as possible. 

Best wishes,\
Tomaz


[Pharo-users] Re: Pharo-WebView

2021-12-22 Thread Russ Whaley
Todd, me neither, but I am a bit worried about mentions of gtk, as I
haven’t been able to get that to work either :(

On Fri, Dec 17, 2021 at 12:50 PM Todd Blanchard via Pharo-users <
pharo-users@lists.pharo.org> wrote:

> Seems cool but I can't figure out how to build it as a library on MacOS.
>
>
> On Dec 16, 2021, at 10:02 AM, Tomaž Turk  wrote:
>
> Dear all,
>
> Pharo-WebView package is now available on GitHub at
> https://github.com/eftomi/Pharo-Webview.
>
> Pharo-WebView is a package which implements a binding to webview dll
> library available at https://github.com/webview/webview in Pharo. Webview
> allows you to show HTML user interfaces in a native window, inject
> JavaScript code and HTML content into the window. It renders HTML
> originating via web requests or as a direct input.
>
> I tested it on Windows 64 bit in Pharo 64, I plan to do that on Pharo 32
> and Linux, however I don't have access to Mac, so if anybody is interested,
> I'd be grateful :-)
>
> Best wishes,
> Tomaz
>
>
> --
Russ Whaley
whaley.r...@gmail.com


[Pharo-users] Re: Pharo-WebView

2021-12-20 Thread Tomaž Turk

Done :-)

[Pharo-users] Re: Pharo-WebView

2021-12-20 Thread Guillermo Polito
Thanks Tomaz,

You may have hit a bug/unimplemented feature.
Would you mind opening an issue with some more details? What Pharo version, 
what backend, an example with the C counterpart maybe?
Everything that would help us quickly build a test is super useful to work in a 
fix (or even, a written test would be better than any explanation ;)).

Otherwise, with the coming holidays this may get lost.
G

> El 17 dic 2021, a las 15:00, Tomaž Turk  escribió:
> 
> Thanks! It still has some quirks :-) 
> 
> BTW, it should be possible to get a javascript promise as a result from a 
> callback to Pharo, however I always get "#ifTrue:ifFalse: was sent to nil" in 
> VMCallbackContext64 if I actually do the callback which has a signature with 
> a pointer as a return value, like
> 
> FFICallback
>   signature: #(char * (const char * seq, const char * req))
>   block: [ :seq :req | ... ]  
> 
> or
> 
> FFICallback
>   signature: #(String (const char * seq, const char * req))
>   block: [ :seq :req | ... ] 
> 
> I checked the FFICallback tests and there are no examples of pointer return 
> values. Is this possible?
> 
> Best wishes,
> Tomaz
> 
> -- Original Message --
> From: "Guillermo Polito"  <mailto:guillermopol...@gmail.com>>
> To: "Any question about pharo is welcome"  <mailto:pharo-users@lists.pharo.org>>
> Cc: "Tomaž Turk" mailto:tomazz.t...@gmail.com>>
> Sent: 17. 12. 2021 14:29:37
> Subject: Re: [Pharo-users] Re: Pharo-WebView
> 
>> This is amazing
>> 
>> I wonder how this would marry with PharoJS 
>> 
>>> El 17 dic 2021, a las 11:51, Richard O'Keefe >> <mailto:rao...@gmail.com>> escribió:
>>> 
>>> Ta muchly.  Appreciated.
>>> 
>>> 
>>> On Fri, 17 Dec 2021 at 06:03, Tomaž Turk >> <mailto:tomazz.t...@gmail.com>> wrote:
>>> Dear all,
>>> 
>>> Pharo-WebView package is now available on GitHub at 
>>> https://github.com/eftomi/Pharo-Webview 
>>> <https://github.com/eftomi/Pharo-Webview>.
>>> 
>>> Pharo-WebView is a package which implements a binding to webview dll 
>>> library available at https://github.com/webview/webview 
>>> <https://github.com/webview/webview> in Pharo. Webview allows you to show 
>>> HTML user interfaces in a native window, inject JavaScript code and HTML 
>>> content into the window. It renders HTML originating via web requests or as 
>>> a direct input. 
>>> 
>>> I tested it on Windows 64 bit in Pharo 64, I plan to do that on Pharo 32 
>>> and Linux, however I don't have access to Mac, so if anybody is interested, 
>>> I'd be grateful 
>>> 
>>> Best wishes,
>>> Tomaz



[Pharo-users] Re: Pharo-WebView

2021-12-19 Thread tomazz . turk
A bit of progress :-) I compiled a shared library libwebview.so on Ubuntu with:

`` g++ webview.c -fPIC -shared -o libwebview.so `pkg-config --cflags --libs 
gtk+-3.0 webkit2gtk-4.0` ``

Before that, the gtk and webkit2 dev libraries should be installed with:

`sudo apt install -y libwebkit2gtk-4.0-dev libgtk-3-dev`

And if you don’t have gcc tools:

`sudo apt install build-essential`

I’ll see if I can figure it out for MacOS too. 

It appears that in Linux it is necessary to run the webview in separate thread, 
otherwise Pharo image gets blocked, so I have to slightly change the 
architecture (with threaded FFI as astares pointed out on Discord #ffi).

Tomaz


[Pharo-users] Re: Pharo-WebView

2021-12-17 Thread Todd Blanchard via Pharo-users
Seems cool but I can't figure out how to build it as a library on MacOS.

> On Dec 16, 2021, at 10:02 AM, Tomaž Turk  wrote:
> 
> Dear all,
> 
> Pharo-WebView package is now available on GitHub at 
> https://github.com/eftomi/Pharo-Webview 
> .
> 
> Pharo-WebView is a package which implements a binding to webview dll library 
> available at https://github.com/webview/webview 
>  in Pharo. Webview allows you to show 
> HTML user interfaces in a native window, inject JavaScript code and HTML 
> content into the window. It renders HTML originating via web requests or as a 
> direct input.
> 
> I tested it on Windows 64 bit in Pharo 64, I plan to do that on Pharo 32 and 
> Linux, however I don't have access to Mac, so if anybody is interested, I'd 
> be grateful :-)
> 
> Best wishes,
> Tomaz



[Pharo-users] Re: Pharo-WebView

2021-12-17 Thread Tomaž Turk

Thanks! It still has some quirks :-)

BTW, it should be possible to get a javascript promise as a result from 
a callback to Pharo, however I always get "#ifTrue:ifFalse: was sent to 
nil" in VMCallbackContext64 if I actually do the callback which has a 
signature with a pointer as a return value, like


FFICallback
  signature: #(char * (const char * seq, const char * req))
  block: [ :seq :req | ... ]

or

FFICallback
  signature: #(String (const char * seq, const char * req))
  block: [ :seq :req | ... ]

I checked the FFICallback tests and there are no examples of pointer 
return values. Is this possible?


Best wishes,
Tomaz

-- Original Message --
From: "Guillermo Polito" 
To: "Any question about pharo is welcome" 
Cc: "Tomaž Turk" 
Sent: 17. 12. 2021 14:29:37
Subject: Re: [Pharo-users] Re: Pharo-WebView


This is amazing

I wonder how this would marry with PharoJS
:)


El 17 dic 2021, a las 11:51, Richard O'Keefe  
escribió:


Ta muchly.  Appreciated.


On Fri, 17 Dec 2021 at 06:03, Tomaž Turk  
wrote:

Dear all,

Pharo-WebView package is now available on GitHub at 
https://github.com/eftomi/Pharo-Webview.


Pharo-WebView is a package which implements a binding to webview dll 
library available at https://github.com/webview/webview in Pharo. 
Webview allows you to show HTML user interfaces in a native window, 
inject JavaScript code and HTML content into the window. It renders 
HTML originating via web requests or as a direct input.


I tested it on Windows 64 bit in Pharo 64, I plan to do that on Pharo 
32 and Linux, however I don't have access to Mac, so if anybody is 
interested, I'd be grateful

:-)

Best wishes,
Tomaz



[Pharo-users] Re: Pharo-WebView

2021-12-17 Thread Guillermo Polito
This is amazing

I wonder how this would marry with PharoJS :)

> El 17 dic 2021, a las 11:51, Richard O'Keefe  escribió:
> 
> Ta muchly.  Appreciated.
> 
> 
> On Fri, 17 Dec 2021 at 06:03, Tomaž Turk  > wrote:
> Dear all,
> 
> Pharo-WebView package is now available on GitHub at 
> https://github.com/eftomi/Pharo-Webview 
> .
> 
> Pharo-WebView is a package which implements a binding to webview dll library 
> available at https://github.com/webview/webview 
>  in Pharo. Webview allows you to show 
> HTML user interfaces in a native window, inject JavaScript code and HTML 
> content into the window. It renders HTML originating via web requests or as a 
> direct input.
> 
> I tested it on Windows 64 bit in Pharo 64, I plan to do that on Pharo 32 and 
> Linux, however I don't have access to Mac, so if anybody is interested, I'd 
> be grateful :-)
> 
> Best wishes,
> Tomaz
> 



[Pharo-users] Re: Pharo-WebView

2021-12-17 Thread Richard O'Keefe
Ta muchly.  Appreciated.


On Fri, 17 Dec 2021 at 06:03, Tomaž Turk  wrote:

> Dear all,
>
> Pharo-WebView package is now available on GitHub at
> https://github.com/eftomi/Pharo-Webview.
>
> Pharo-WebView is a package which implements a binding to webview dll
> library available at https://github.com/webview/webview in Pharo. Webview
> allows you to show HTML user interfaces in a native window, inject
> JavaScript code and HTML content into the window. It renders HTML
> originating via web requests or as a direct input.
>
> I tested it on Windows 64 bit in Pharo 64, I plan to do that on Pharo 32
> and Linux, however I don't have access to Mac, so if anybody is interested,
> I'd be grateful :-)
>
> Best wishes,
> Tomaz
>
>


[Pharo-users] Re: Pharo-WebView

2021-12-16 Thread Esteban Lorenzano
Very nice :)

Esteban
On Dec 16 2021, at 6:02 pm, Tomaž Turk  wrote:
> Dear all,
>
> Pharo-WebView package is now available on GitHub at 
> https://github.com/eftomi/Pharo-Webview.
>
> Pharo-WebView is a package which implements a binding to webview dll library 
> available at https://github.com/webview/webview in Pharo. Webview allows you 
> to show HTML user interfaces in a native window, inject JavaScript code and 
> HTML content into the window. It renders HTML originating via web requests or 
> as a direct input.
>
> I tested it on Windows 64 bit in Pharo 64, I plan to do that on Pharo 32 and 
> Linux, however I don't have access to Mac, so if anybody is interested, I'd 
> be grateful :-)
>
> Best wishes,
> Tomaz