Exemplo n.º 1
0
def main():
    global systray, display_mode, clipboard, exiter, ic, timer
    # Kill VcXsrv if already running
    if get_running():
        kill_server()

    # Start VcXsrv
    start_server()

    # Start Tray Icon
    menu = build_menu()
    if display_mode == "c":
        name = current_custom_profile
    else:
        mode_names = {"m": "Multi Window", "s": "Single Window", "f": "Fullscreen"}
        name = mode_names[display_mode]
    systray = tray(ic, f"GWSL Running - {name}", menu, default_menu_index=open_dashboard)
    systray.start()

    # start service listener
    timer = time.perf_counter()
    while True:
        try:
            if time.perf_counter() - timer > 4:
                timer = timer = time.perf_counter()
                if not get_running():
                    # In case someone closes a single-window server... restart as multi window.
                    if display_mode == "s":
                        display_mode = "m"
                        menu = build_menu()
                        systray.update(hover_text="GWSL Running - Multi Window", menu_options=menu)
                        sett = iset.read()
                        sett["graphics"]["window_mode"] = "multi"
                        iset.set(sett)
                        restart_server()
                    elif ask_restart():
                        restart_server()

                    else:
                        systray.shutdown()
                        kill_server()
                        subprocess.getoutput('taskkill /F /IM GWSL.exe')
                        sys.exit()

            if exiter:
                kill_server()
                subprocess.getoutput('taskkill /F /IM GWSL.exe')
                systray.shutdown()
                sys.exit()

        except Exception as e:
            logger.exception("Exception occurred in main loop")

        time.sleep(2)

    kill_server()
    systray.shutdown()
    sys.exit()
Exemplo n.º 2
0
def main():
    """Main entry point for application"""
    global systray, display_mode, clipboard, exiter, ic, timer, audio_enabled
    # Kill VcXsrv if already running
    #if get_running(): we dont need to check do we...

    kill_server()
    kill_audio()

    # Start VcXsrv
    start_server()
    # Start audio
    try:
        sett = iset.read()
        audio_enabled = sett["general"]["pulseaudio"]
    except:
        pass
    start_audio()

    # Start Tray Icon
    menu = build_menu()
    if display_mode == "c":
        name = current_custom_profile
    else:
        mode_names = {
            "m": "Multi Window",
            "s": "Single Window",
            "f": "Fullscreen"
        }
        name = mode_names[display_mode]
    systray = tray(ic,
                   f"GWSL Running - {name}",
                   menu,
                   default_menu_index=open_dashboard)
    systray.start()

    # start service listener
    timer = time.time()
    while True:
        try:
            #print(time.time() - timer)
            if time.time() - timer > 4:
                timer = time.time()
                if not get_running():
                    # In case someone closes a single-window server... restart as multi window.
                    if display_mode == "s":
                        display_mode = "m"
                        menu = build_menu()
                        systray.update(
                            hover_text="GWSL Running - Multi Window",
                            menu_options=menu)
                        sett = iset.read()
                        sett["graphics"]["window_mode"] = "multi"
                        iset.set(sett)
                        restart_server()
                    elif ask_restart():
                        restart_server()
                    else:
                        systray.shutdown()
                        kill_server()
                        kill_audio()
                        subprocess.getoutput('taskkill /F /IM GWSL.exe')
                        sys.exit()
                if audio_enabled == True:
                    if not get_audio_running():
                        #if pulseaudio crashes
                        kill_audio()
                        start_audio()

            if exiter:
                kill_server()
                kill_audio()
                subprocess.getoutput('taskkill /F /IM GWSL.exe')
                systray.shutdown()
                sys.exit()

        except:
            logger.exception("Exception occurred in main loop")
            kill_server()
            systray.shutdown()
            sys.exit()

        time.sleep(2)

    kill_server()
    systray.shutdown()
    sys.exit()