Rare: Refactor Discord RPC file, object and variable names
This commit is contained in:
parent
826d116dd6
commit
125709b53b
|
@ -101,9 +101,9 @@ class MainWindow(QMainWindow):
|
|||
|
||||
if not self.args.offline:
|
||||
try:
|
||||
from rare.utils.rpc import DiscordRPC
|
||||
from rare.utils.discord_rpc import DiscordRPC
|
||||
|
||||
self.rpc = DiscordRPC()
|
||||
self.discord_rpc = DiscordRPC()
|
||||
except ModuleNotFoundError:
|
||||
logger.warning("Discord RPC module not found")
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from PyQt5.QtCore import QSettings, Qt, pyqtSlot, QUrl
|
|||
from PyQt5.QtGui import QDesktopServices
|
||||
from PyQt5.QtWidgets import QWidget, QMessageBox
|
||||
|
||||
from rare.components.tabs.settings.widgets.rpc import RPCSettings
|
||||
from rare.components.tabs.settings.widgets.discord_rpc import DiscordRPCSettings
|
||||
from rare.models.options import options, LibraryView
|
||||
from rare.shared import LegendaryCoreSingleton
|
||||
from rare.ui.components.tabs.settings.rare import Ui_RareSettings
|
||||
|
@ -75,8 +75,8 @@ class RareSettings(QWidget):
|
|||
self.ui.view_combo.setCurrentIndex(0)
|
||||
self.ui.view_combo.currentIndexChanged.connect(self.on_view_combo_changed)
|
||||
|
||||
self.rpc = RPCSettings(self)
|
||||
self.ui.right_layout.insertWidget(1, self.rpc, alignment=Qt.AlignTop)
|
||||
self.discord_rpc_settings = DiscordRPCSettings(self)
|
||||
self.ui.right_layout.insertWidget(1, self.discord_rpc_settings, alignment=Qt.AlignTop)
|
||||
|
||||
self.ui.sys_tray.setChecked(self.settings.value(*options.sys_tray))
|
||||
self.ui.sys_tray.stateChanged.connect(
|
||||
|
|
|
@ -3,34 +3,34 @@ from PyQt5.QtWidgets import QGroupBox
|
|||
|
||||
from rare.shared import GlobalSignalsSingleton
|
||||
from rare.models.options import options
|
||||
from rare.ui.components.tabs.settings.widgets.rpc import Ui_RPCSettings
|
||||
from rare.ui.components.tabs.settings.widgets.discord_rpc import Ui_DiscordRPCSettings
|
||||
|
||||
|
||||
class RPCSettings(QGroupBox):
|
||||
class DiscordRPCSettings(QGroupBox):
|
||||
def __init__(self, parent):
|
||||
super(RPCSettings, self).__init__(parent=parent)
|
||||
self.ui = Ui_RPCSettings()
|
||||
super(DiscordRPCSettings, self).__init__(parent=parent)
|
||||
self.ui = Ui_DiscordRPCSettings()
|
||||
self.ui.setupUi(self)
|
||||
self.signals = GlobalSignalsSingleton()
|
||||
|
||||
self.settings = QSettings()
|
||||
|
||||
self.ui.enable.setCurrentIndex(self.settings.value(*options.rpc_enable))
|
||||
self.ui.enable.setCurrentIndex(self.settings.value(*options.discord_rpc_mode))
|
||||
self.ui.enable.currentIndexChanged.connect(self.__enable_changed)
|
||||
|
||||
self.ui.show_game.setChecked((self.settings.value(*options.rpc_name)))
|
||||
self.ui.show_game.setChecked((self.settings.value(*options.discord_rpc_game)))
|
||||
self.ui.show_game.stateChanged.connect(
|
||||
lambda: self.settings.setValue(options.rpc_name.key, self.ui.show_game.isChecked())
|
||||
lambda: self.settings.setValue(options.discord_rpc_game.key, self.ui.show_game.isChecked())
|
||||
)
|
||||
|
||||
self.ui.show_os.setChecked((self.settings.value(*options.rpc_os)))
|
||||
self.ui.show_os.setChecked((self.settings.value(*options.discord_rpc_os)))
|
||||
self.ui.show_os.stateChanged.connect(
|
||||
lambda: self.settings.setValue(options.rpc_os.key, self.ui.show_os.isChecked())
|
||||
lambda: self.settings.setValue(options.discord_rpc_os.key, self.ui.show_os.isChecked())
|
||||
)
|
||||
|
||||
self.ui.show_time.setChecked((self.settings.value(*options.rpc_time)))
|
||||
self.ui.show_time.setChecked((self.settings.value(*options.discord_rpc_time)))
|
||||
self.ui.show_time.stateChanged.connect(
|
||||
lambda: self.settings.setValue(options.rpc_time.key, self.ui.show_time.isChecked())
|
||||
lambda: self.settings.setValue(options.discord_rpc_time.key, self.ui.show_time.isChecked())
|
||||
)
|
||||
|
||||
try:
|
||||
|
@ -40,5 +40,5 @@ class RPCSettings(QGroupBox):
|
|||
self.setToolTip(self.tr("Pypresence is not installed"))
|
||||
|
||||
def __enable_changed(self, i):
|
||||
self.settings.setValue(options.rpc_enable.key, i)
|
||||
self.settings.setValue(options.discord_rpc_mode.key, i)
|
||||
self.signals.discord_rpc.apply_settings.emit()
|
|
@ -45,10 +45,10 @@ class Defaults(Namespace):
|
|||
)
|
||||
library_order = Value(key="library_order", default=int(LibraryOrder.TITLE), dtype=int)
|
||||
|
||||
rpc_enable = Value(key="rpc_enable", default=0, dtype=int)
|
||||
rpc_name = Value(key="rpc_game", default=True, dtype=bool)
|
||||
rpc_time = Value(key="rpc_time", default=True, dtype=bool)
|
||||
rpc_os = Value(key="rpc_os", default=True, dtype=bool)
|
||||
discord_rpc_mode = Value(key="discord_rpc_mode", default=0, dtype=int)
|
||||
discord_rpc_game = Value(key="discord_rpc_game", default=True, dtype=bool)
|
||||
discord_rpc_time = Value(key="discord_rpc_time", default=True, dtype=bool)
|
||||
discord_rpc_os = Value(key="discord_rpc_os", default=True, dtype=bool)
|
||||
|
||||
|
||||
options = Defaults()
|
||||
|
|
|
@ -16,8 +16,8 @@ class Ui_RareSettings(object):
|
|||
RareSettings.setObjectName("RareSettings")
|
||||
RareSettings.resize(629, 447)
|
||||
RareSettings.setWindowTitle("RareSettings")
|
||||
self.rare_layout = QtWidgets.QHBoxLayout(RareSettings)
|
||||
self.rare_layout.setObjectName("rare_layout")
|
||||
self.main_layout = QtWidgets.QHBoxLayout(RareSettings)
|
||||
self.main_layout.setObjectName("main_layout")
|
||||
self.left_layout = QtWidgets.QVBoxLayout()
|
||||
self.left_layout.setObjectName("left_layout")
|
||||
self.interface_group = QtWidgets.QGroupBox(RareSettings)
|
||||
|
@ -93,7 +93,7 @@ class Ui_RareSettings(object):
|
|||
self.left_layout.addWidget(self.settings_group)
|
||||
spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
||||
self.left_layout.addItem(spacerItem1)
|
||||
self.rare_layout.addLayout(self.left_layout)
|
||||
self.main_layout.addLayout(self.left_layout)
|
||||
self.right_layout = QtWidgets.QVBoxLayout()
|
||||
self.right_layout.setObjectName("right_layout")
|
||||
self.log_dir_group = QtWidgets.QGroupBox(RareSettings)
|
||||
|
@ -130,7 +130,7 @@ class Ui_RareSettings(object):
|
|||
self.right_layout.addWidget(self.groupBox)
|
||||
spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
||||
self.right_layout.addItem(spacerItem2)
|
||||
self.rare_layout.addLayout(self.right_layout)
|
||||
self.main_layout.addLayout(self.right_layout)
|
||||
|
||||
self.retranslateUi(RareSettings)
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<property name="windowTitle">
|
||||
<string notr="true">RareSettings</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="rare_layout">
|
||||
<layout class="QHBoxLayout" name="main_layout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="left_layout">
|
||||
<item>
|
||||
|
|
66
rare/ui/components/tabs/settings/widgets/discord_rpc.py
Normal file
66
rare/ui/components/tabs/settings/widgets/discord_rpc.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'rare/ui/components/tabs/settings/widgets/discord_rpc.ui'
|
||||
#
|
||||
# Created by: PyQt5 UI code generator 5.15.10
|
||||
#
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
|
||||
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
|
||||
|
||||
class Ui_DiscordRPCSettings(object):
|
||||
def setupUi(self, DiscordRPCSettings):
|
||||
DiscordRPCSettings.setObjectName("DiscordRPCSettings")
|
||||
DiscordRPCSettings.resize(370, 149)
|
||||
DiscordRPCSettings.setWindowTitle("DiscordRPCSettings")
|
||||
self.main_layout = QtWidgets.QGridLayout(DiscordRPCSettings)
|
||||
self.main_layout.setObjectName("main_layout")
|
||||
self.enable = QtWidgets.QComboBox(DiscordRPCSettings)
|
||||
self.enable.setObjectName("enable")
|
||||
self.enable.addItem("")
|
||||
self.enable.addItem("")
|
||||
self.enable.addItem("")
|
||||
self.main_layout.addWidget(self.enable, 0, 1, 1, 1)
|
||||
self.label = QtWidgets.QLabel(DiscordRPCSettings)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
|
||||
self.label.setSizePolicy(sizePolicy)
|
||||
self.label.setObjectName("label")
|
||||
self.main_layout.addWidget(self.label, 0, 0, 1, 1)
|
||||
self.show_game = QtWidgets.QCheckBox(DiscordRPCSettings)
|
||||
self.show_game.setObjectName("show_game")
|
||||
self.main_layout.addWidget(self.show_game, 1, 0, 1, 2)
|
||||
self.show_os = QtWidgets.QCheckBox(DiscordRPCSettings)
|
||||
self.show_os.setObjectName("show_os")
|
||||
self.main_layout.addWidget(self.show_os, 2, 0, 1, 2)
|
||||
self.show_time = QtWidgets.QCheckBox(DiscordRPCSettings)
|
||||
self.show_time.setObjectName("show_time")
|
||||
self.main_layout.addWidget(self.show_time, 3, 0, 1, 2)
|
||||
|
||||
self.retranslateUi(DiscordRPCSettings)
|
||||
|
||||
def retranslateUi(self, DiscordRPCSettings):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
DiscordRPCSettings.setTitle(_translate("DiscordRPCSettings", "Discord RPC"))
|
||||
self.enable.setItemText(0, _translate("DiscordRPCSettings", "When Playing"))
|
||||
self.enable.setItemText(1, _translate("DiscordRPCSettings", "Always"))
|
||||
self.enable.setItemText(2, _translate("DiscordRPCSettings", "Never"))
|
||||
self.label.setText(_translate("DiscordRPCSettings", "Show"))
|
||||
self.show_game.setText(_translate("DiscordRPCSettings", "Show Game"))
|
||||
self.show_os.setText(_translate("DiscordRPCSettings", "Show OS"))
|
||||
self.show_time.setText(_translate("DiscordRPCSettings", "Show Time playing"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
DiscordRPCSettings = QtWidgets.QGroupBox()
|
||||
ui = Ui_DiscordRPCSettings()
|
||||
ui.setupUi(DiscordRPCSettings)
|
||||
DiscordRPCSettings.show()
|
||||
sys.exit(app.exec_())
|
77
rare/ui/components/tabs/settings/widgets/discord_rpc.ui
Normal file
77
rare/ui/components/tabs/settings/widgets/discord_rpc.ui
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DiscordRPCSettings</class>
|
||||
<widget class="QGroupBox" name="DiscordRPCSettings">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>370</width>
|
||||
<height>149</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">DiscordRPCSettings</string>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Discord RPC</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="main_layout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="enable">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>When Playing</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Always</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Never</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="show_game">
|
||||
<property name="text">
|
||||
<string>Show Game</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="show_os">
|
||||
<property name="text">
|
||||
<string>Show OS</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="show_time">
|
||||
<property name="text">
|
||||
<string>Show Time playing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -1,66 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'rare/ui/components/tabs/settings/widgets/rpc.ui'
|
||||
#
|
||||
# Created by: PyQt5 UI code generator 5.15.6
|
||||
#
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
|
||||
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
|
||||
|
||||
class Ui_RPCSettings(object):
|
||||
def setupUi(self, RPCSettings):
|
||||
RPCSettings.setObjectName("RPCSettings")
|
||||
RPCSettings.resize(174, 146)
|
||||
RPCSettings.setWindowTitle("DiscordRPC")
|
||||
self.layout = QtWidgets.QGridLayout(RPCSettings)
|
||||
self.layout.setObjectName("layout")
|
||||
self.enable = QtWidgets.QComboBox(RPCSettings)
|
||||
self.enable.setObjectName("enable")
|
||||
self.enable.addItem("")
|
||||
self.enable.addItem("")
|
||||
self.enable.addItem("")
|
||||
self.layout.addWidget(self.enable, 0, 1, 1, 1)
|
||||
self.label = QtWidgets.QLabel(RPCSettings)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
|
||||
self.label.setSizePolicy(sizePolicy)
|
||||
self.label.setObjectName("label")
|
||||
self.layout.addWidget(self.label, 0, 0, 1, 1)
|
||||
self.show_game = QtWidgets.QCheckBox(RPCSettings)
|
||||
self.show_game.setObjectName("show_game")
|
||||
self.layout.addWidget(self.show_game, 1, 0, 1, 2)
|
||||
self.show_os = QtWidgets.QCheckBox(RPCSettings)
|
||||
self.show_os.setObjectName("show_os")
|
||||
self.layout.addWidget(self.show_os, 2, 0, 1, 2)
|
||||
self.show_time = QtWidgets.QCheckBox(RPCSettings)
|
||||
self.show_time.setObjectName("show_time")
|
||||
self.layout.addWidget(self.show_time, 3, 0, 1, 2)
|
||||
|
||||
self.retranslateUi(RPCSettings)
|
||||
|
||||
def retranslateUi(self, RPCSettings):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
RPCSettings.setTitle(_translate("RPCSettings", "Discord RPC"))
|
||||
self.enable.setItemText(0, _translate("RPCSettings", "When Playing"))
|
||||
self.enable.setItemText(1, _translate("RPCSettings", "Always"))
|
||||
self.enable.setItemText(2, _translate("RPCSettings", "Never"))
|
||||
self.label.setText(_translate("RPCSettings", "Show"))
|
||||
self.show_game.setText(_translate("RPCSettings", "Show Game"))
|
||||
self.show_os.setText(_translate("RPCSettings", "Show OS"))
|
||||
self.show_time.setText(_translate("RPCSettings", "Show Time playing"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
RPCSettings = QtWidgets.QGroupBox()
|
||||
ui = Ui_RPCSettings()
|
||||
ui.setupUi(RPCSettings)
|
||||
RPCSettings.show()
|
||||
sys.exit(app.exec_())
|
|
@ -1,77 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>RPCSettings</class>
|
||||
<widget class="QGroupBox" name="RPCSettings">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>174</width>
|
||||
<height>146</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">DiscordRPC</string>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Discord RPC</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="layout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="enable">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>When Playing</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Always</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Never</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="show_game">
|
||||
<property name="text">
|
||||
<string>Show Game</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="show_os">
|
||||
<property name="text">
|
||||
<string>Show OS</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="show_time">
|
||||
<property name="text">
|
||||
<string>Show Time playing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -10,19 +10,19 @@ from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton
|
|||
from rare.models.options import options
|
||||
|
||||
client_id = "830732538225360908"
|
||||
logger = getLogger("RPC")
|
||||
logger = getLogger("DiscordRPC")
|
||||
|
||||
|
||||
class DiscordRPC(QObject):
|
||||
def __init__(self):
|
||||
super(DiscordRPC, self).__init__()
|
||||
self.RPC = None
|
||||
self.rpc = None
|
||||
self.state = 1 # 0: game, 1: always active, 2: off
|
||||
self.core = LegendaryCoreSingleton()
|
||||
self.signals = GlobalSignalsSingleton()
|
||||
|
||||
self.settings = QSettings()
|
||||
if self.settings.value(*options.rpc_enable) == 1: # show always
|
||||
if self.settings.value(*options.discord_rpc_mode) == 1: # show always
|
||||
self.state = 2
|
||||
self.set_discord_rpc()
|
||||
|
||||
|
@ -33,7 +33,7 @@ class DiscordRPC(QObject):
|
|||
self.set_discord_rpc(app_name)
|
||||
|
||||
def changed_settings(self, game_running: list = None):
|
||||
value = self.settings.value(*options.rpc_enable)
|
||||
value = self.settings.value(*options.discord_rpc_mode)
|
||||
if value == 2:
|
||||
self.remove_rpc()
|
||||
return
|
||||
|
@ -45,15 +45,15 @@ class DiscordRPC(QObject):
|
|||
self.set_discord_rpc(game_running[0])
|
||||
|
||||
def remove_rpc(self):
|
||||
if self.settings.value(*options.rpc_enable) != 1:
|
||||
if not self.RPC:
|
||||
if self.settings.value(*options.discord_rpc_mode) != 1:
|
||||
if not self.rpc:
|
||||
return
|
||||
try:
|
||||
self.RPC.close()
|
||||
self.rpc.close()
|
||||
except Exception:
|
||||
logger.warning("Already closed")
|
||||
del self.RPC
|
||||
self.RPC = None
|
||||
del self.rpc
|
||||
self.rpc = None
|
||||
logger.info("Remove RPC")
|
||||
self.state = 2
|
||||
else:
|
||||
|
@ -61,56 +61,56 @@ class DiscordRPC(QObject):
|
|||
self.set_discord_rpc()
|
||||
|
||||
def set_discord_rpc(self, app_name=None):
|
||||
if not self.RPC:
|
||||
if not self.rpc:
|
||||
try:
|
||||
self.RPC = Presence(
|
||||
self.rpc = Presence(
|
||||
client_id
|
||||
) # Rare app: https://discord.com/developers/applications
|
||||
self.RPC.connect()
|
||||
self.rpc.connect()
|
||||
except ConnectionRefusedError as e:
|
||||
logger.warning(f"Discord is not active\n{e}")
|
||||
self.RPC = None
|
||||
self.rpc = None
|
||||
return
|
||||
except FileNotFoundError as e:
|
||||
logger.warning(f"File not found error\n{e}")
|
||||
self.RPC = None
|
||||
self.rpc = None
|
||||
return
|
||||
except pypresence.exceptions.InvalidPipe as e:
|
||||
logger.error(f"Is Discord running? \n{e}")
|
||||
self.RPC = None
|
||||
self.rpc = None
|
||||
return
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
self.RPC = None
|
||||
self.rpc = None
|
||||
return
|
||||
self.update_rpc(app_name)
|
||||
|
||||
def update_rpc(self, app_name=None):
|
||||
if self.settings.value(*options.rpc_enable) == 2 or (
|
||||
not app_name and self.settings.value(*options.rpc_enable) == 0
|
||||
if self.settings.value(*options.discord_rpc_mode) == 2 or (
|
||||
not app_name and self.settings.value(*options.discord_rpc_mode) == 0
|
||||
):
|
||||
self.remove_rpc()
|
||||
return
|
||||
title = None
|
||||
if not app_name:
|
||||
self.RPC.update(
|
||||
self.rpc.update(
|
||||
large_image="logo", details="https://github.com/RareDevs/Rare"
|
||||
)
|
||||
return
|
||||
if self.settings.value(*options.rpc_name):
|
||||
if self.settings.value(*options.discord_rpc_game):
|
||||
try:
|
||||
title = self.core.get_installed_game(app_name).title
|
||||
except AttributeError:
|
||||
logger.error(f"Could not get title of game: {app_name}")
|
||||
title = app_name
|
||||
start = None
|
||||
if self.settings.value(*options.rpc_time):
|
||||
if self.settings.value(*options.discord_rpc_time):
|
||||
start = str(time.time()).split(".")[0]
|
||||
os = None
|
||||
if self.settings.value(*options.rpc_os):
|
||||
if self.settings.value(*options.discord_rpc_os):
|
||||
os = f"via Rare on {platform.system()}"
|
||||
|
||||
self.RPC.update(
|
||||
self.rpc.update(
|
||||
large_image="logo", details=title, large_text=title, state=os, start=start
|
||||
)
|
||||
self.state = 0
|
Loading…
Reference in a new issue