diff --git a/ObsAutoRecordWin.py b/ObsAutoRecordWin.py index 236c307..2d45202 100644 --- a/ObsAutoRecordWin.py +++ b/ObsAutoRecordWin.py @@ -129,7 +129,7 @@ def refresh_icon(self): win32gui.Shell_NotifyIcon(message, self.notify_id) def update_from_state(self, state): - self.icon = os.path.join(os.getcwd(), 'record_green.ico' if state else 'record_red.ico') + self.icon = get_resource_path('record_green.ico' if state else 'record_red.ico') self.hover_text = 'OBS Auto Record ' + ('(connected)' if state else '(disconnected)') self.refresh_icon() @@ -228,10 +228,17 @@ def non_string_iterable(obj): else: return not isinstance(obj, basestring) +def get_resource_path(relative_path): + try: + base_path = sys._MEIPASS + except Exception: + base_path = os.path.abspath(".") + return os.path.join(base_path, relative_path) + if __name__ == '__main__': obs_auto_record = ObsAutoRecord() sys_tray_icon = SysTrayIcon(obs_auto_record, - os.path.join(os.getcwd(), 'record_red.ico'), + get_resource_path('record_red.ico'), 'OBS Auto Record', (), default_menu_index=1) diff --git a/README.md b/README.md index a4963b1..c650373 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,8 @@ Controls OBS to auto record specific games when they are running (works on Windo Install [pywin32](https://github.com/mhammond/pywin32) ``` pip3 install psutil pyinstaller websocket-client wmi -pyinstaller .\ObsAutoRecordWin.py --onefile --noconsole --icon=record_red.ico --name=ObsAutoRecord +pyinstaller .\ObsAutoRecordWin.py --onefile --noconsole --icon=record_red.ico --name=ObsAutoRecord --add-data "record*.ico;." ``` -and put the ico files in the same folder as the executable. ### Mac ``` pip3 install psutil py2app rumps websocket-client