A simple python script to restart Chatterino if it crashed. Made because Chatterino always crashes while I am away and that's really annoying.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Chatterino-Restarter-Script/chatterino_process_monitor.py

69 lines
2.2 KiB

import configparser
import psutil
import time
import os
import subprocess
import pystray
from PIL import Image
from datetime import datetime
# Function to check if Chatterino is running
def is_chatterino_running():
for proc in psutil.process_iter():
try:
if program_executable in proc.name():
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
# Function to run Chatterino
def run_program(program_path):
subprocess.Popen([program_path], cwd=program_dir)
now = datetime.now()
timenow = now.strftime("%H:%M:%S")
print("[" + timenow + "] Started Chatterino.")
# Function to display system tray icon
def on_quit_callback(icon):
icon.stop()
# Define system tray icon and menu
def create_tray_icon():
# todo: fix tray icon not showing up
icon_image = Image.open("icon.png")
menu = pystray.Menu(
pystray.MenuItem(
"Quit", on_quit_callback, default=True
)
)
return pystray.Icon("Chatterino Monitor", icon_image, "Chatterino Monitor", menu)
if __name__ == '__main__':
print("Yandols' Chatterino Process Monitor Script")
# Load settings from config file
config = configparser.ConfigParser()
config.read('settings.ini')
program_executable = config.get('ChatterinoMonitor', 'chatterino_exe')
program_dir = config.get('ChatterinoMonitor', 'chatterino_directory')
program_path = program_dir + "\\" + program_executable
# Create system tray icon
icon = create_tray_icon()
time.sleep(1) # wait for system tray icon to initialize
# Loop to check if Chatterino is running every 10 minutes
while True:
if is_chatterino_running():
now = datetime.now()
timenow = now.strftime("%H:%M:%S")
print("[" + timenow + "] Chatterino is running. Rechecking in 10 minutes.")
else:
now = datetime.now()
timenow = now.strftime("%H:%M:%S")
print("[" + timenow + "] Chatterino is not running. Starting in 30 seconds...")
time.sleep(30)
run_program(program_path)
time.sleep(600) # wait 10 minutes