Coder Social home page Coder Social logo

zalegzl / electron-flask Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matbloch/electron-flask

1.0 1.0 0.0 45 KB

Barebone template for cross platform desktop apps, featuring a FLASK powered backend for IPC

JavaScript 52.83% Python 31.54% HTML 15.63%

electron-flask's Introduction

Electron-Flask Bootstrap Template

Contribution guidelines for this project

Dependencies

Installation

  1. Clone the repository git clone ...
  2. Install Python dependencies python -m pip install -r requirements.txt
  3. Install node modules npm install

Running the App

Start app

  • Windows: .\node_modules\.bin\electron .
  • Mac OS/Linux: ./node_modules/.bin/electron .

Start app with globally installed electron

  • electron .

Run the app through your web browser

  • Start Flask server manually: python web_app/run_app.py

Bundling

Packaging is done in two steps:

  1. A standalone Python executable containing the Flask backend is generated using PyInstaller
  2. The Python executable and the electron application (electron.js) are bundled using electron-builder

NOTE: The Python executable is generated in the "one-file-mode"; All dependencies are wrapped in a single executable. When executed, the program is decompressed to a temporary directory and run in a second process from there. This has to be considered in the life-cycle management of the electron app. See killPythonSubprocesses of electron.js.

Package the app for the host platform

  • npm run package (output binaries will be stored in /dist)

Cross-Platform packaging

  • Not yet supported (due to lacking cross-compilation support of PyInstaller)

Why Flask?

  • Using a Flask webserver for interprocess communication (ICP) comes in handy to bundle an existing Flask-based service into a desktop application. The endpoints don't have to be changed.
  • For other applications there are more efficient alternatives to using Flask/HTTP for ICP, e.g. zerorpc.

Process scheme

Encountered Issues

  • asar is read-only, .pyc files cannot be created
  • When bundling the standalone Python executable in an .asar, a random filename is generated. This makes life-cycle management of the backend service difficult (see also section Bundling).

Feature Backlog

Bundling Resources with the Python Executable

  • use --add-data to bundle resources with the python executables (use sys._MEIPASS to resolve paths)

  • see python-eel/Eel#57

def resource_path(relative_path):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)
    return os.path.join(os.path.abspath("."), relative_path)

Cross-Compilation through Docker

  • create a Docker image to allow building for Linux on Windows

ASAR Bundling

  • When bundling the electron app in an .asar, the path to the python executable (which is copied to the resource folder) is not resolved properly

electron-flask's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.