def run_forever(args, config): is_daemon_started = is_port_used(23333) or is_port_used(23334) if config.MODE & App.DaemonMode and is_daemon_started: print_error('Fuo daemon is already started.') sys.exit(1) if config.MODE & App.GuiMode: prepare_gui() app = setup_app(args, config) if sys.platform.lower() == 'darwin': enable_mac_hotkey() loop = asyncio.get_event_loop() try: if not config.MODE & App.GuiMode: if config.MODE & App.DaemonMode: # when started with daemon mode, show some message to tell user # that the program is running. print('Fuo daemon running on 0.0.0.0:23333 (tcp)') else: print('Fuo running with no daemon and no window') loop.run_forever() except KeyboardInterrupt: # NOTE: gracefully shutdown? pass finally: loop.stop() app.shutdown() loop.close()
def init(args, config): """ return value: 1: run cli 2: run once (run simple cmd) 3: run loop """ # 根据命令行参数来更新配置 # 注:用户在 rcfile 文件中也可以配置这些选项的值 # 所以我们不能这样实现 config.DEBUG = args.debug,而是像下面这样 config.DEBUG = args.debug or config.DEBUG config.MPV_AUDIO_DEVICE = args.mpv_audio_device or config.MPV_AUDIO_DEVICE config.LOG_TO_FILE = bool(args.log_to_file or config.LOG_TO_FILE) if args.cmd is not None: is_daemon_started = is_port_used(23333) or is_port_used(23334) if is_daemon_started: return 1 # run_cli cli_cmds = ('show', 'play', 'search') if args.cmd not in cli_cmds: print_error('Fuo daemon not started.') sys.exit(1) return 2 # run_once if not args.no_window: try: import PyQt5 # noqa except ImportError: logger.warning('PyQt5 is not installed, can only use daemon mode.') else: config.MODE |= App.GuiMode if not args.no_server: config.MODE |= App.DaemonMode return 3
def run_cli(args, config): is_daemon_started = is_port_used(23333) or is_port_used(23334) if is_daemon_started: climain(args) sys.exit(0) cli_cmds = ('show', 'play', 'search') # 如果服务端已经启动,则将命令发送给服务端处理 if args.cmd not in cli_cmds: print_error('Fuo daemon not started.') sys.exit(1) run_once(args, config)
def run_forever(args, config): is_daemon_started = is_port_used(23333) or is_port_used(23334) if config.MODE & App.DaemonMode and is_daemon_started: print_error('Fuo daemon is already started.') sys.exit(1) if config.MODE & App.GuiMode: prepare_gui() app = setup_app(args, config) if sys.platform.lower() == 'darwin': enable_mac_hotkey(force=config.FORCE_MAC_HOTKEY) loop = asyncio.get_event_loop() try: loop.run_forever() except KeyboardInterrupt: # NOTE: gracefully shutdown? pass finally: loop.stop() app.shutdown() loop.close()