Esempio n. 1
0
def init(args, config):
    """
    1: run cli or simple cmd
    0: run loop
    -1: error
    """
    # 让程序能正确的找到图标资源
    os.chdir(os.path.join(os.path.dirname(__file__), '..'))
    sys.excepthook = excepthook
    ensure_dirs()

    # 从 rcfile 中加载配置和代码
    load_rcfile(config)

    # 根据命令行参数来更新配置
    # 注:用户在 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:
        # load some config before start run_cli
        run_cli(args, config)
        return 1

    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
Esempio n. 2
0
def main():
    parser = setup_argparse()
    args = parser.parse_args()

    if args.version:
        print('feeluown {}, fuocore {}'.format(feeluown_version,
                                               fuocore_version))
        return

    if is_port_used(23333) or is_port_used(23334):
        print('\033[0;31m', end='')
        print(
            'Port(23333 or 23334) is used, maybe another feeluown is running?')
        print('\033[0m', end='')
        sys.exit(1)

    debug = args.debug
    mpv_audio_device = args.mpv_audio_device
    cli_only = args.no_window
    logger_config(debug, to_file=args.log_to_file)

    load_rcfile()

    player_kwargs = dict(audio_device=bytes(mpv_audio_device, 'utf-8'))

    # 设置 exception hook
    sys.excepthook = excepthook

    if not cli_only:
        try:
            import PyQt5  # noqa
        except ImportError:
            logger.warning('PyQt5 is not installed,can only use CLI mode.')
            cli_only = True

    if not cli_only:
        from PyQt5.QtWidgets import QApplication
        from quamash import QEventLoop

        q_app = QApplication(sys.argv)
        q_app.setQuitOnLastWindowClosed(True)
        q_app.setApplicationName('FeelUOwn')

        app_event_loop = QEventLoop(q_app)
        asyncio.set_event_loop(app_event_loop)

    mode = App.CliMode if cli_only else App.GuiMode
    app = create_app(mode, **player_kwargs)
    bind_signals(app)

    event_loop = asyncio.get_event_loop()
    try:
        event_loop.run_forever()
        logger.info('Event loop stopped.')
    except KeyboardInterrupt:
        # NOTE: gracefully shutdown?
        app.shutdown()
    finally:
        event_loop.close()
Esempio n. 3
0
def main():
    # 让程序能正确的找到图标等资源
    os.chdir(os.path.join(os.path.dirname(__file__), '..'))
    sys.excepthook = excepthook

    parser = setup_argparse()
    args = parser.parse_args()

    if args.version:
        print('feeluown {}, fuocore {}'.format(feeluown_version,
                                               fuocore_version))
        return

    check_ports()
    ensure_dirs()
    config = create_config()
    load_rcfile(config)
    map_args_to_config(args, config)
    logger_config(config.DEBUG, to_file=args.log_to_file)

    if config.MODE & App.GuiMode:
        try:
            import PyQt5  # noqa
        except ImportError:
            logger.warning('PyQt5 is not installed,can only use CLI mode.')
            config.MODE = App.CliMode

    if config.MODE & App.GuiMode:
        from PyQt5.QtWidgets import QApplication
        from quamash import QEventLoop

        q_app = QApplication(sys.argv)
        q_app.setQuitOnLastWindowClosed(True)
        q_app.setApplicationName('FeelUOwn')

        app_event_loop = QEventLoop(q_app)
        asyncio.set_event_loop(app_event_loop)

    event_loop = asyncio.get_event_loop()
    Signal.setup_aio_support(loop=event_loop)
    app = create_app(config)
    bind_signals(app)
    if sys.platform.lower() == 'darwin':
        enable_mac_hotkey(force=config.FORCE_MAC_HOTKEY)
    try:
        event_loop.run_forever()
    except KeyboardInterrupt:
        # NOTE: gracefully shutdown?
        pass
    finally:
        event_loop.stop()
        app.shutdown()
        event_loop.close()
Esempio n. 4
0
def main():
    sys.excepthook = excepthook
    parse_args(sys.argv)

    cli_only = '-nw' in sys.argv
    if not cli_only:
        try:
            import PyQt5  # noqa
        except ImportError:
            logger.warning('PyQt5 is not installed,can only use CLI mode.')
            cli_only = True

    if not cli_only:
        from PyQt5.QtWidgets import QApplication
        from quamash import QEventLoop
        from feeluown.guiapp import GuiApp

        q_app = QApplication(sys.argv)
        q_app.setQuitOnLastWindowClosed(True)
        q_app.setApplicationName('FeelUOwn')

        app_event_loop = QEventLoop(q_app)
        asyncio.set_event_loop(app_event_loop)
        pubsub_gateway, pubsub_server = run_pubsub()

        app = GuiApp(pubsub_gateway)
        app.initialize()
        load_rcfile(app)
        # TODO: 调用 show 时,会弹出主界面,但这时界面还没开始绘制
        # 为了让提升启动速度,一些非必须的初始化操作可以在 show 之后进行
        app.show()
    else:
        from feeluown.app import CliApp

        pubsub_gateway, pubsub_server = run_pubsub()
        app = CliApp(pubsub_gateway)
        app.initialize()

    live_lyric = app.live_lyric
    event_loop = asyncio.get_event_loop()
    event_loop.create_task(run_server(app, live_lyric))
    try:
        event_loop.run_forever()
        logger.info('Event loop stopped.')
    except KeyboardInterrupt:
        # NOTE: gracefully shutdown?
        pass
    finally:
        pubsub_server.close()
        event_loop.close()
Esempio n. 5
0
def main():
    parse_args(sys.argv)
    load_rcfile()

    q_app = QApplication(sys.argv)
    q_app.setQuitOnLastWindowClosed(True)
    q_app.setApplicationName('FeelUOwn')

    app_event_loop = QEventLoop(q_app)
    asyncio.set_event_loop(app_event_loop)
    app = App()
    app.show()

    app_event_loop.run_forever()
    sys.exit(0)
Esempio n. 6
0
def init(args, config):
    """
    1: run cli or simple cmd
    0: run loop
    -1: error
    """
    # 让程序能正确的找到图标资源
    os.chdir(os.path.join(os.path.dirname(__file__), '..'))
    sys.excepthook = excepthook
    ensure_dirs()

    if args.version:
        print('feeluown {}'.format(feeluown_version))
        return 1

    if args.cmd is not None:
        run_cli(args, config)
        return 1

    # 从 rcfile 中加载配置和代码
    load_rcfile(config)

    # 根据命令行参数来更新配置
    config.DEBUG = args.debug
    config.MPV_AUDIO_DEVICE = args.mpv_audio_device
    config.FORCE_MAC_HOTKEY = args.force_mac_hotkey
    config.LOG_TO_FILE = args.log_to_file
    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
Esempio n. 7
0
def main():
    parser = setup_argparse()
    args = parser.parse_args()

    if is_port_used(23333) or is_port_used(23334):
        print('\033[0;31m', end='')
        print(
            'Port(23333 or 23334) is used, maybe another feeluown is running?')
        print('\033[0m', end='')
        sys.exit(1)

    debug = args.debug
    mpv_audio_device = args.mpv_audio_device
    cli_only = args.no_window
    logger_config(debug, to_file=args.log_to_file)

    from fuocore.player import MpvPlayer

    player = MpvPlayer(audio_device=bytes(mpv_audio_device, 'utf-8'))
    player.initialize()

    # 设置 exception hook
    sys.excepthook = excepthook

    if not cli_only:
        try:
            import PyQt5  # noqa
        except ImportError:
            logger.warning('PyQt5 is not installed,can only use CLI mode.')
            cli_only = True

    if not cli_only:
        from PyQt5.QtWidgets import QApplication
        from quamash import QEventLoop
        from feeluown.guiapp import GuiApp

        q_app = QApplication(sys.argv)
        q_app.setQuitOnLastWindowClosed(True)
        q_app.setApplicationName('FeelUOwn')

        app_event_loop = QEventLoop(q_app)
        asyncio.set_event_loop(app_event_loop)
        pubsub_gateway, pubsub_server = run_pubsub()

        app = GuiApp(pubsub_gateway, player=player)
        app.initialize()
        load_rcfile(app)
        # TODO: 调用 show 时,会弹出主界面,但这时界面还没开始绘制
        # 为了让提升启动速度,一些非必须的初始化操作可以在 show 之后进行
        app.show()
    else:
        from feeluown.app import CliApp

        pubsub_gateway, pubsub_server = run_pubsub()
        app = CliApp(pubsub_gateway)
        app.initialize()

    live_lyric = app.live_lyric
    event_loop = asyncio.get_event_loop()
    event_loop.create_task(run_server(app, live_lyric))
    try:
        event_loop.run_forever()
        logger.info('Event loop stopped.')
    except KeyboardInterrupt:
        # NOTE: gracefully shutdown?
        pass
    finally:
        pubsub_server.close()
        event_loop.close()
Esempio n. 8
0
def main():
    parser = setup_argparse()
    args = parser.parse_args()

    if args.version:
        print('feeluown {}, fuocore {}'.format(feeluown_version, fuocore_version))
        return

    if is_port_used(23333) or is_port_used(23334):
        print('\033[0;31m', end='')
        print('Port(23333 or 23334) is used, maybe another feeluown is running?')
        print('\033[0m', end='')
        sys.exit(1)

    debug = args.debug
    mpv_audio_device = args.mpv_audio_device
    cli_only = args.no_window
    logger_config(debug, to_file=args.log_to_file)

    load_rcfile()

    player_kwargs = dict(
        audio_device=bytes(mpv_audio_device, 'utf-8'))

    # 设置 exception hook
    sys.excepthook = excepthook

    if not cli_only:
        try:
            import PyQt5  # noqa
        except ImportError:
            logger.warning('PyQt5 is not installed,can only use CLI mode.')
            cli_only = True

    if not cli_only:
        from PyQt5.QtWidgets import QApplication
        from quamash import QEventLoop
        from feeluown.guiapp import GuiApp

        q_app = QApplication(sys.argv)
        q_app.setQuitOnLastWindowClosed(True)
        q_app.setApplicationName('FeelUOwn')

        app_event_loop = QEventLoop(q_app)
        asyncio.set_event_loop(app_event_loop)
        pubsub_gateway, pubsub_server = run_pubsub()

        app = GuiApp(pubsub_gateway, player_kwargs=player_kwargs)
        app.config = config
        # 初始化 UI 和组件间信号绑定
        app.initialize()
        # TODO: 调用 show 时,会弹出主界面,但这时界面还没开始绘制
        # 为了让提升启动速度,一些非必须的初始化操作可以在 show 之后进行
        app.show()
    else:
        from feeluown.app import CliApp

        pubsub_gateway, pubsub_server = run_pubsub()
        app = CliApp(pubsub_gateway, player_kwargs=player_kwargs)
        app.config = config
        app.initialize()

    bind_signals(app)

    event_loop = asyncio.get_event_loop()
    app.protocol.run_server()
    try:
        event_loop.run_forever()
        logger.info('Event loop stopped.')
    except KeyboardInterrupt:
        # NOTE: gracefully shutdown?
        pass
    finally:
        pubsub_server.close()
        event_loop.close()