Skip to content

Commit

Permalink
bug fixes and update to support wildcards in app matching
Browse files Browse the repository at this point in the history
  • Loading branch information
fireph committed Nov 13, 2017
1 parent 96a7a57 commit 57b30bc
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions ObsAutoRecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# Module : ObsAutoRecord.py
# Description : Windows System tray icon app that auto records apps/games in OBS.
# Author : Frederick Meyer
# Version : 1.0
# Version : 1.0.1
# Date : 12 November 2017
# Notes : System tray icon code based on Simon Brunning's SysTrayIcon.py
# http://www.brunningonline.net/simon/blog/archives/SysTrayIcon.py.html

import configparser
import fnmatch
import json
import os
import psutil
Expand All @@ -33,6 +34,7 @@ def __init__(self):
self.should_restart = True
self.state = False
self.on_state_change = None
self.apps_to_record = get_apps_to_record();
self.start()

def set_on_state_change(self, on_state_change):
Expand All @@ -52,10 +54,12 @@ def start(self):

def on_message(self, ws, message):
json_msg = json.loads(message)
if 'recording' in json_msg and not json_msg['recording'] and self.is_app_open():
self.send_message("StartRecording")
elif 'recording' in json_msg and json_msg['recording'] and not self.is_app_open():
self.send_message("StopRecording")
if 'recording' in json_msg:
is_app_open = self.is_app_open()
if not json_msg['recording'] and is_app_open:
self.send_message("StartRecording")
elif json_msg['recording'] and not is_app_open:
self.send_message("StopRecording")

def on_error(self, ws, error):
print(error)
Expand All @@ -78,11 +82,10 @@ def ping_status(self):
self.timer.start()

def is_app_open(self):
apps_to_record = get_apps_to_record();
for pid in psutil.pids():
p = psutil.Process(pid)
if p.name() in apps_to_record:
return True
for proc in psutil.process_iter(attrs=['name']):
for app in self.apps_to_record:
if fnmatch.fnmatchcase(proc.name(), app):
return True
return False

def send_message(self, requestType):
Expand Down

0 comments on commit 57b30bc

Please sign in to comment.