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

web browser runtimes #642

Closed
Ksengine opened this issue Nov 6, 2020 · 43 comments
Closed

web browser runtimes #642

Ksengine opened this issue Nov 6, 2020 · 43 comments
Labels

Comments

@Ksengine
Copy link
Contributor

Ksengine commented Nov 6, 2020

add web browser runtimes

we can use chrome and firefox as runtimes.
we can remove menus, search bar and other decorations.
i have experience with doing this

chrome is easy
firefox is bit complex

  • YES I am willing to work on this issue myself.

  • NO I am not prepared to support this issue financially.

@r0x0r
Copy link
Owner

r0x0r commented Nov 6, 2020

Do you mean Chrome's app mode?

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 6, 2020

yes

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 6, 2020

and xul apps on firefox

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 6, 2020

we can control window using ajax long polling.
and iframe is used to show window.

@r0x0r
Copy link
Owner

r0x0r commented Nov 6, 2020

If I am not mistaken Google is sunsetting Chrome's app mode. I would not pursue that.

I am not familiar with XUL, but the thing about additional renderers that implementations require support. With the current situation I am being the sole developer, I cannot take on board any more renderers.

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 6, 2020

If I am not mistaken Google is sunsetting Chrome's app mode. I would not pursue that.

more info?

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 6, 2020

i can help

@r0x0r
Copy link
Owner

r0x0r commented Nov 6, 2020

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 6, 2020

sorry. you understood it wrongly.
chrome apps are extensions with some files(manifest etc.)
i am saying about chrome app mode.
we can run chrme with --app flag
eg:-

<chrome path> --app="https://www.google.com"

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 7, 2020

you should visit #641

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 7, 2020

add suitable labels

@r0x0r
Copy link
Owner

r0x0r commented Nov 7, 2020

You are correct about the app mode.
I see the rationale behind adding Chrome as a renderer. However several issues must be resolved first.

  1. It has browser menu bar and other controls. Is there anyway to hide those?
  2. What would happen if chrome is selected as a renderer and Chrome is not installed on user machine?
  3. How does JS-Python bridge would work?

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 8, 2020

i thought about hose problems.
i can explain

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 8, 2020

  1. app mode hides them
  2. they can't use chrome as renderer.(we can force them to install)
    add it to guilib.py like other methods(gtk, qt...)
  3. we can use wesockets, SSE, ajax long polling, ajax requests etc

@r0x0r
Copy link
Owner

r0x0r commented Nov 8, 2020

Menu bar is not hidden on MacOS
image

Is it different on other OSes?

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 8, 2020

sorry, menu bar is showing on any platform

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 8, 2020

if you are saying about frameless mode
--kiosk mode can remove them

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 8, 2020

chrome.py

#!/usr/bin/python
# -*- coding: utf-8 -*-
import platform
import os

name = "Google Chrome/Chromium"


def find_path():
    """
    find the chrome executable path on Windows, Linux/OpenBSD, Mac or Unknown system.
    """
    if platform.system() == "Windows":
        return _find_chrome_win()

    elif platform.system() == "Darwin":  # Mac OS
        return _find_chrome_mac()

    elif platform.system() == "Linux" or platform.system() == "OpenBSD":
        return _find_chrome_linux()

    else:
        try:
            return _find_chrome_linux()
        except:
            try:
                return _find_chrome_mac()
            except:
                try:
                    return _find_chrome_win()
                except:
                    return None


def _find_chrome_mac():
    paths = [  # mac os chrome path list
        "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
        "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
        "/Applications/Chromium.app/Contents/MacOS/Chromium",
        "/usr/bin/google-chrome-stable",
        "/usr/bin/google-chrome",
        "/usr/bin/chromium",
        "/usr/bin/chromium-browser",
    ]

    chrome_path = None

    for path in paths:  # loop through paths
        if os.path.exists(path):
            chrome_path = path

    if chrome_path != None:
        return chrome_path

    else:  # use which command to find chrome
        for browser in ("google-chrome", "chrome", "chromium", "chromium-browser"):
            a = os.popen("which " + browser).read()
            if a == "":
                pass
            else:
                return a[:-1]

        return None


def _find_chrome_linux():
    paths = [
        "/usr/bin/google-chrome-stable",  # linux chrome path list
        "/usr/bin/google-chrome",
        "/usr/bin/chromium",
        "/usr/bin/chromium-browser",
        "/snap/bin/chromium",
    ]

    chrome_path = None

    for path in paths:
        if os.path.exists(path):
            chrome_path = path

    if chrome_path != None:
        return chrome_path

    else:  # use which command to find chrome
        for browser in ("google-chrome", "chrome", "chromium", "chromium-browser"):
            a = os.popen("which " + browser).read()
            if a == "":
                pass
            else:
                return a[:-1]

        return None


def _find_chrome_win():
    import winreg as reg  # import registry

    chrome_path = None
    reg_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe"

    for install_type in (reg.HKEY_CURRENT_USER, reg.HKEY_LOCAL_MACHINE):
        try:
            reg_key = reg.OpenKey(install_type, reg_path, 0, reg.KEY_READ)
            chrome_path = reg.QueryValue(reg_key, None)
            reg_key.Close()
            if not os.path.isfile(chrome_path):
                continue
        except WindowsError:
            chrome_path = None
        else:
            break

    for browser in ("google-chrome", "chrome", "chromium", "chromium-browser"):
        a = os.popen("where " + browser).read()
        if a == "":
            pass
        else:
            chrome_path = a[:-1]

    return chrome_path


chrome_path = find_path()
if not chrome_path:
    raise Exception("No chrome")


class ChromeView:
    def __init__(self, url="data:text/html,<h1>DicksonUI</h1>", options=[]):
        cmd = chrome_path
        for option in options:
            cmd += " "
            cmd += option
        cmd += " --incognito"
        cmd += " --new-window"
        cmd += ' --app="'
        cmd += url + '"'
        os.popen(cmd)

    def version(self, path):
        try:
            v = os.popen(find_path() + " --version").read()
            v2 = v[v.find(" ") + 1 :]
            return int(v2[: v2.find(".")])
        except:
            return None

    def is_chromium(self, path):
        try:
            if os.popen(path + " --version").read().startswith("Chromium"):
                return True
            else:
                return False
        except:
            return None

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 8, 2020

example with DicksonUI(my project)

#!/usr/bin/python
# -*- coding: utf-8 -*-
from dicksonui import Application, window
from chrome import ChromeView
mywindow=window()
App = Application(('',1024))
App.add(mywindow)
mywindow.document.body.innerHTML=open('index.tmp').read()
print("Navigate To - "+App.location)
ChromeView(App.location)

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 8, 2020

screenshot
Screenshot_2020-11-08_11-46-42

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 8, 2020

index.tmp is a html code with bootstrap.

@r0x0r
Copy link
Owner

r0x0r commented Nov 9, 2020

I am not keen on including Chrome due UX reasons.

However, a plugin support for external renderers could be a viable idea. Something like this

import webview
import chrome_webview # external plugin

webview.register(chrome_webview)
webview.create_window(...)
webiew.start(gui='chrome')

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 9, 2020

I am not keen on including Chrome due UX reasons.

UX = user experiense?

explain more

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 9, 2020

why plugin?
we can include it as a gui

@r0x0r
Copy link
Owner

r0x0r commented Nov 9, 2020

Two reasons

  1. Poor UX
  2. I don't want to support code I am not comfortable with.

I appreciate your enthusiasm, but ask yourself will you be here making pull requests and fixing bugs two years from now? What about five years?

Contributors come and go. People solve their problem, submit a PR and after that it is not their problem any more. Should bugs occur, it all comes back to me.

@Ksengine
Copy link
Contributor Author

Poor UX ?

@Ksengine
Copy link
Contributor Author

i had given you an example, not the real code of new gui

@Ksengine
Copy link
Contributor Author

Contributors come and go. People solve their problem, submit a PR and after that it is not their problem any more. Should bugs occur, it all comes back to me.

it's not Contributors' fault, they help you(even for bug fixes.)
i will make pull requests and fixing bugs until i like.
this is not my job.this is my hobby

@Ksengine
Copy link
Contributor Author

ok i will explain all things

@Ksengine
Copy link
Contributor Author

Ksengine commented Nov 10, 2020

webview.start

to use chrome as a webview, we need a server(WSGI is better)

  • open localhost on chrome(using subprocess or os.popen)
  • server sends controller page
  • controller page sets properties and opens a shows the page using iframe
    • title - document.title
    • url - url can be a http url(urloption of webview.start), file url or data url(html option)
      iframe can open localhost connections to local servers
    • html - use data url for iframe
    • width , height - window.resizeTo
    • x, y - window.moveTo
    • resizable - (default is True) if False use window events to detect resizing and set width and height
    • fullscreen - use --kiosk flag or js fullscreen api or css
    • min_size - use window events to detect resizing and set width and height
    • hidden - dont open chrome until pywebview_window.show called
    • frameless - not supported
    • minimized - not supported
    • on_top - not supported
    • confirm_close - using window events,
    • background_color - using css
    • text_select - using css and js

@Ksengine
Copy link
Contributor Author

Then

  • controller page opens a websocket connection to server
  • use wesocket to control window, js api and interdomain communication

@Ksengine
Copy link
Contributor Author

Window object

  • on_top -always False
  • x, y - returns window.screenX and window.screenY
  • width, height - return window.outerWidth and window.outerHeight
  • create_file_dialog - create input with type="file" and raise fake click event
  • destroy - kill chrome process
  • evaluate_js - send js through websocket and get results as JSON
  • get_current_url - return window.location.href
  • get_elements - using evaluate_js
  • hide - not supported
  • load_css - using evaluate set css
  • load_html - using evaluate_js
  • load_url - using evaluate_js
  • minimize - not supported
  • move - window.moveTo
  • restore - not supported
  • set_title - set document.title
  • show - not supported
  • toggle_fulscreen - js fullscreen api

and all events supported through websocket
drag area supported

@Ksengine
Copy link
Contributor Author

for websocket i hope to use @Ksengine/wsocket

@r0x0r
Copy link
Owner

r0x0r commented Nov 10, 2020

it's not Contributors' fault, they help you(even for bug fixes.)
i will make pull requests and fixing bugs until i like.
this is not my job.this is my hobby

You are correct.
This is not my job as well. I do this on my free time and I do not get paid for this.
Exactly for this reason I choose code I work with and how I do it.

@Ksengine
Copy link
Contributor Author

Yes, we will work together to develop this project.
Users should contribute if they need more features

@Ksengine
Copy link
Contributor Author

we can add chrome webview as experimental feature.
i wrote a long description. say your ideas and questions.

@Ksengine
Copy link
Contributor Author

no reply?

@Ksengine
Copy link
Contributor Author

cna i make a PR

@r0x0r
Copy link
Owner

r0x0r commented Nov 13, 2020

Two reasons

  1. Poor UX
  2. I don't want to support code I am not comfortable with.

I appreciate your enthusiasm, but ask yourself will you be here making pull requests and fixing bugs two years from now? What about five years?

Contributors come and go. People solve their problem, submit a PR and after that it is not their problem any more. Should bugs occur, it all comes back to me.

This still stands. By poor UX, I mean Chrome menubar and other browser artefacts. If you manage to make Chrome window more app like, this will make a difference. Otherwise if you want to see this future, I am ready to discuss plugin architecture.

@Ksengine
Copy link
Contributor Author

screenshot
Screenshot_2020-11-08_11-46-42

This as a python web app on chrome.
in this example It has no menubar and other browser artefacts.

@Ksengine
Copy link
Contributor Author

I will make a PR for basic guilib.
then we can discuss about.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Dec 14, 2020
@github-actions
Copy link

The message to post on the issue when closing it. If none provided, will not comment when closing an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants