mirror of
https://github.com/nixietab/picodulce.git
synced 2025-04-10 10:28:56 +01:00
better discord rpc
This commit is contained in:
parent
dc81d4285d
commit
15b1567d3e
51
picodulce.py
51
picodulce.py
@ -18,6 +18,7 @@ logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %
|
|||||||
|
|
||||||
class PicomcVersionSelector(QWidget):
|
class PicomcVersionSelector(QWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.current_state = "menu"
|
||||||
self.open_dialogs = []
|
self.open_dialogs = []
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
@ -394,16 +395,26 @@ class PicomcVersionSelector(QWidget):
|
|||||||
|
|
||||||
def run_game(self, selected_instance):
|
def run_game(self, selected_instance):
|
||||||
try:
|
try:
|
||||||
|
# Set current_state to the selected instance
|
||||||
|
self.current_state = selected_instance
|
||||||
# Update lastplayed field in config.json on a separate thread
|
# Update lastplayed field in config.json on a separate thread
|
||||||
update_thread = threading.Thread(target=self.update_last_played, args=(selected_instance,))
|
update_thread = threading.Thread(target=self.update_last_played, args=(selected_instance,))
|
||||||
update_thread.start()
|
update_thread.start()
|
||||||
|
|
||||||
|
# Run the game subprocess
|
||||||
subprocess.run(['picomc', 'play', selected_instance], check=True)
|
subprocess.run(['picomc', 'play', selected_instance], check=True)
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
error_message = f"Error playing {selected_instance}: {e}"
|
error_message = f"Error playing {selected_instance}: {e}"
|
||||||
logging.error(error_message)
|
logging.error(error_message)
|
||||||
# Use QMetaObject.invokeMethod to call showError safely
|
# Use QMetaObject.invokeMethod to call showError safely
|
||||||
QMetaObject.invokeMethod(self, "showError", Qt.QueuedConnection,
|
QMetaObject.invokeMethod(
|
||||||
Q_ARG(str, "Error"), Q_ARG(str, error_message))
|
self, "showError", Qt.QueuedConnection,
|
||||||
|
Q_ARG(str, "Error"), Q_ARG(str, error_message)
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
# Reset current_state to "menu" after the game closes
|
||||||
|
self.current_state = "menu"
|
||||||
|
|
||||||
def update_last_played(self, selected_instance):
|
def update_last_played(self, selected_instance):
|
||||||
config_path = "config.json"
|
config_path = "config.json"
|
||||||
@ -836,19 +847,31 @@ class PicomcVersionSelector(QWidget):
|
|||||||
try:
|
try:
|
||||||
presence.connect()
|
presence.connect()
|
||||||
|
|
||||||
presence.update(
|
# Initialize start time for the session
|
||||||
state="In the menu",
|
start_time = time.time()
|
||||||
details="best launcher to exist",
|
|
||||||
large_image="launcher_icon",
|
|
||||||
large_text="PicoDulce Launcher",
|
|
||||||
start=time.time(),
|
|
||||||
buttons=[{"label": "Download", "url": "https://github.com/nixietab/picodulce"}]
|
|
||||||
)
|
|
||||||
# Keep the script running to maintain the presence
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(15) # Update presence every 15 seconds
|
# Determine the state and details based on the current_state
|
||||||
|
if self.current_state == "menu":
|
||||||
|
state = "In the menu"
|
||||||
|
details = "Picodulce FOSS Launcher"
|
||||||
|
else:
|
||||||
|
state = f"Playing {self.current_state}"
|
||||||
|
|
||||||
|
# Update presence
|
||||||
|
presence.update(
|
||||||
|
state=state,
|
||||||
|
details=details,
|
||||||
|
large_image="launcher_icon",
|
||||||
|
large_text="PicoDulce Launcher",
|
||||||
|
start=start_time,
|
||||||
|
buttons=[{"label": "Download", "url": "https://github.com/nixietab/picodulce"}]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Wait for 15 seconds before checking again
|
||||||
|
time.sleep(15)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Failed to start Discord RCP: %s", str(e))
|
logging.error("Failed to start Discord RPC: %s", str(e))
|
||||||
|
|
||||||
def open_mod_loader_and_version_menu(self):
|
def open_mod_loader_and_version_menu(self):
|
||||||
dialog = ModLoaderAndVersionMenu()
|
dialog = ModLoaderAndVersionMenu()
|
||||||
@ -1085,8 +1108,6 @@ class ModLoaderAndVersionMenu(QDialog):
|
|||||||
logging.error(error_message)
|
logging.error(error_message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
current_date = datetime.now()
|
current_date = datetime.now()
|
||||||
|
Loading…
Reference in New Issue
Block a user