Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the browser for desktop UI

How can I use the browser as a UI for a desktop app? The ways I have come up with so far are...

  1. Use all HTML/Javascript. Problem: Can't access filesystem or just about anything else.
  2. Run a local webserver while the application is in use. Problem: How do I kill it when the user is done? My users are not technical enough to Ctrl+C.
  3. Embed a browser component in a regular GUI. Problem: Embedded browser components tend to be glitchy at best. The support for Javascript/CSS is never as good as it is in a real browser.
  4. ...?

The ideal solution would work with any technology. I know there are options like writing Firefox extensions, but I want to have complete freedom in the backend technology and browser independence.

like image 953
Instance Hunter Avatar asked Oct 29 '09 12:10

Instance Hunter


3 Answers

In Windows, you could embed the IE ActiveX control, which uses the same rendering engine as IE. (That's a plus and a minus) You can set the ScriptObject property in your host code and access it in Javascript as window.external to do things that Javascript cannot do.

If you run a local webserver, you could have an exit link in the app that kills the websever.

like image 100
SLaks Avatar answered Oct 04 '22 16:10

SLaks


If you are looking for a python Web Server with a Kill link, you could always check CherryPy.

import webbrowser
import cherrypy
import threading

class MyApp:
    """ Sample request handler class. """

    @cherrypy.expose
    def index(self):
        return """<html><head><title>An example application</title></head>
<body>
<h1>This is my sample application</h1>
Put the content here...
<hr>
<a href="/exit">Quit</a>
</body></html>"""

    @cherrypy.expose
    def exit(self):
        raise SystemExit(0)


class MyBGThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.start()

    def run(self):
        cherrypy.tree.mount(MyApp())
        cherrypy.quickstart()

myThread = MyBGThread()
webbrowser.open("http://127.0.0.1:8080")

This code is based on the sample from the SingleClickAndRun on the cherrypy website: http://tools.cherrypy.org/wiki/SingleClickAndRun

Note than in a normal WebApp you would probably use a templating engine and load templates from methods like main.

Something that would be nice would be to embbed a browser control in a gui window and close the server when the app exits.

For the security, you could possibly add an authentication scheme. There are a few that are supported by cherrypy, but you possibly could implement your own too, using tool modules.

like image 20
Martin Avatar answered Oct 04 '22 16:10

Martin


I am looking to do the exact same thing (desktop app that uses an up to date HTML5 / CSS3 browser as the desktop app's GUI), only with Ruby (various reasons why I decided to work with Ruby). Its amazing the number of cross platform libraries people have come up with. But yet, few to no one, has done any work on trying to get a web browser to be a desktop app UI. Cross platform issue... well I won't say solved, but I will say several steps in the right direction taken.

To me this would be perfect with the new HTML5 / CSS3 standards coming out. I know it can be done with a web server running locally.

Another way might be like how the guys from “280 North” are doing what they do. They developed Objective-J (an extension of regular JavaScript that mimics how Objective-C extends regular C) and Cappuccino (the Objective-J equivalent of Objective-C’s Cocoa frame work on the MAC). They also developed “Atlas” which is 280 North’s version of Apple’s “Interface Builder” from Xcode, for their Objective-J and Cappuccino frameworks to build Internet Applications. Atlas is actually a Cappuccino web app running on your desktop as a desktop app. In this case they use the Narwhal… a cross platform, general purpose, JavaScript platform for developing JS apps outside of the browser (basically a specialized web server).

If any one can come up with an idea to make “Browser, direct connect to Desktop App” work without the need of a web server co-existing and still get to manipulate the local FS, I to would be very interested… Hmmm... Now that I think about it, I wonder if the new Google Chrome project “Native Client” can be used to do that. NaCL is much like Active X except you are not limited to a windows platform (but will be limited to the Google Chrome browser, at least for now). Only there is added security via Sandboxing, but you can manipulate the local FS… The more I think about it, the more I am beginning to suspect that it can be done.

Any thoughts?

like image 43
Brad Hutchins Avatar answered Oct 04 '22 15:10

Brad Hutchins