Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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_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:
def run_once(args, config):
import warnings
warnings.filterwarnings("ignore")
config.MODE = App.CliMode
app = setup_app(args, config)
oncemain(app, args)
def disable(app):
app.library.deregister(provider)
if app.mode & App.GuiMode:
app.providers.remove(provider.identifier)
obj = compile(code, '', 'single')
self._g.update({
'app': self,
'player': self.player
})
exec(obj, self._g, self._g)
class GuiApp(CliApp, QWidget, AppCodeRunnerMixin):
"""
FIXME: Subclass must call initialize to make this mixin
work properly, which seems to be little bit strange. But
this mixin helps avoid duplicate code temporarily.
"""
mode = App.GuiMode | App.CliMode
def __init__(self, pubsub_gateway, player_kwargs=None):
CliApp.__init__(self, pubsub_gateway, player_kwargs=player_kwargs)
QWidget.__init__(self)
self.request = Request(self)
self.tips_manager = TipsManager(self)
self.hotkey_manager = Hotkey(self)
#: collections manager
self.coll_mgr = CollectionManager(self)
self.img_ctl = ImgController(self)
self.playlists = PlaylistsModel(parent=self)
self.histories = HistoriesModel(parent=self)
self.providers = ProvidersModel(parent=self)
self.my_music = MyMusicModel(parent=self)
def enable(app):
app.library.register(provider)
if app.mode & App.GuiMode:
from feeluown.components.provider import ProviderModel
pm = ProviderModel(
name='QQ 音乐',
icon='♫ ',
desc='点击登录 QQ 音乐(未实现,欢迎 PR)',
on_click=None,
)
app.providers.assoc(provider.identifier, pm)
def enable(app):
logger.info('Register provider: %s', provider)
loop = asyncio.get_event_loop()
future_scan = loop.run_in_executor(None, provider.scan)
app.library.register(provider)
if app.mode & App.GuiMode:
from feeluown.components.provider import ProviderModel
pm = ProviderModel(
name='本地音乐',
icon='♪ ',
desc='点击显示所有本地音乐',
on_click=partial(show_provider, app),
)
logger.info('Associate %s with %s', provider, pm.name)
app.providers.assoc(provider.identifier, pm)
future_scan.add_done_callback(lambda _: show_provider(app))