Esempio n. 1
0
def open_link():
    link = request.args['url']

    if webbrowser.open(link):
        return '', 204

    logger.critical(f'Failed to open browser link: {link}!')
    return abort(500, 'Could not open link!')
Esempio n. 2
0
def monitor_threads(*threads):
    while True:
        for thread in threads:
            if not thread.is_alive():
                logger.critical(f'Thread: {thread} died, exiting!')
                destroy_main_window()
        else:
            sleep(0.5)
Esempio n. 3
0
def main():
    logger.info(f'\n#\n# Booting Kanmail {get_version()}\n#')

    init_window_hacks()
    boot()

    server_thread = Thread(name='Server', target=run_server)
    server_thread.daemon = True
    server_thread.start()

    run_thread(validate_or_remove_license)
    run_thread(run_cache_cleanup_later)

    # Ensure the webserver is up & running by polling it
    waits = 0
    while waits < 10:
        try:
            response = requests.get(
                f'http://{SERVER_HOST}:{server.get_port()}/ping')
            response.raise_for_status()
        except requests.RequestException as e:
            logger.warning(f'Waiting for main window: {e}')
            sleep(0.1 * waits)
            waits += 1
        else:
            break
    else:
        logger.critical('Webserver did not start properly!')
        sys.exit(2)

    create_window(
        unique_key='main',
        **get_window_settings(),
    )

    # Let's hope this thread doesn't fail!
    monitor_thread = Thread(
        name='Thread monitor',
        target=monitor_threads,
        args=(server_thread, ),
    )
    monitor_thread.daemon = True
    monitor_thread.start()

    if DEBUG:
        sleep(1)  # give webpack a second to start listening

    # Start the GUI - this will block until the main window is destroyed
    webview.start(gui=GUI_LIB, debug=DEBUG)

    # Main window closed, cleanup/exit
    sys.exit()
Esempio n. 4
0
def open_link():
    link = request.args['url']

    # https://github.com/pyinstaller/pyinstaller/issues/3668
    xdg_data_dirs = environ.pop('XDG_DATA_DIRS', None)
    try:
        if webbrowser.open(link):
            return '', 204
    finally:
        if xdg_data_dirs:
            environ['XDG_DATA_DIRS'] = xdg_data_dirs

    logger.critical(f'Failed to open browser link: {link}!')
    return abort(500, 'Could not open link!')