Skip to content

Commit

Permalink
volumecontroller update and watcher update operation update
Browse files Browse the repository at this point in the history
  • Loading branch information
gogodr committed Jun 16, 2022
1 parent 17f847a commit e70b4b2
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 120 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ config.ini
file_version_info.txt
lamo-watcher.exe
lamo-launcher.exe
logs/
logs/
index.build/
index.dist/
index.onefile-build
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Audio files from [MixKit](https://mixkit.co/)


### Changelog
### 1.2.6.2
- Update VolumeController threadsafe
- Fix watcher update operation

### 1.2.4.1
- Update and relaunch procedure rework

Expand Down
18 changes: 6 additions & 12 deletions compile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import PyInstaller.__main__

import os
from modules.config import Config

import pyinstaller_versionfile

pyinstaller_versionfile.create_versionfile_from_input_file(
output_file="file_version_info.txt",
input_file="metadata.yml",
version=Config().version
)
Config().version

PyInstaller.__main__.run([
'compile.spec',
'--clean'
])
if Config().debug:
os.system(f'python -m nuitka --standalone --windows-icon-from-ico=assets/icons/favicon.ico --enable-plugin=pyside6 --include-data-dir=assets=assets --follow-imports --onefile --windows-file-version={Config().version} --windows-product-version={Config().version} --windows-company-name="Lost Ark Market Online" --windows-product-name="Lost Ark Market Online Launcher App" --windows-file-description="Lost Ark Market Online Launcher App" -o lamo-launcher-debug.exe index.py')
else:
os.system(f'python -m nuitka --standalone --windows-icon-from-ico=assets/icons/favicon.ico --enable-plugin=pyside6 --include-data-dir=assets=assets --follow-imports --onefile --windows-disable-console --windows-file-version={Config().version} --windows-product-version={Config().version} --windows-company-name="Lost Ark Market Online" --windows-product-name="Lost Ark Market Online Launcher App" --windows-file-description="Lost Ark Market Online Launcher App" -o lamo-launcher.exe index.py')
46 changes: 0 additions & 46 deletions compile.spec

This file was deleted.

2 changes: 1 addition & 1 deletion compile_release.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pyinstaller release.spec
python -m nuitka --standalone --windows-icon-from-ico=assets/icons/favicon.ico --enable-plugin=pyside6 --include-data-dir=assets=assets --follow-imports --onefile --windows-disable-console --windows-file-version=1.2.4.1 --windows-product-version=1.2.4.1 --windows-company-name="Lost Ark Market Online" --windows-product-name="Lost Ark Market Online Launcher App" -o lamo-launcher.exe index.py
44 changes: 0 additions & 44 deletions file_version_info.txt

This file was deleted.

11 changes: 9 additions & 2 deletions index.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from time import sleep
from modules.logging import AppLogger
from modules.messagebox import MessageBoxHandler
import modules.single_instance
Expand Down Expand Up @@ -87,12 +88,13 @@ def login_success(self):
# Watcher Version Check
def check_config(self):
Config().check_watcher_version()
print(f"Needs watcher update: {Config().watcher_needs_update}")
if Config().watcher_needs_update == True:
playUpdateDetected()
self.download = LostArkMarketLauncherDownload({
"url": f'https://github.com/gogodr/LostArk-Market-Watcher/releases/download/{Config().watcher_version}/{Config().watcher_file}.exe',
"title": f'New version of the Lost Ark Market Watcher Found: v{Config().watcher_version}',
"file": f'{Config().watcher_file}.exe'
"file": f'{Config().watcher_file}.exe.new'
})
self.download.launch.connect(self.launch_watcher)
self.download.finished_download.connect(self.watcher_downloaded)
Expand All @@ -106,13 +108,18 @@ def watcher_downloaded(self):
self.launch_watcher()

def launch_watcher(self):
sleep(2)
if os.path.exists(f"{Config().watcher_file}.exe.new") == True:
if os.path.exists(f"{Config().watcher_file}.exe") == True:
os.system(f"del /f {Config().watcher_file}.exe")
os.system(f"rename {Config().watcher_file}.exe.new {Config().watcher_file}.exe")
sleep(2)
playSuccess()
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
subprocess.call(f"{Config().watcher_file}.exe")
sys.exit()


if __name__ == "__main__":
try:
Config()
Expand Down
7 changes: 4 additions & 3 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class Config(metaclass=Singleton):
version = "1.2.4.1"
version = "1.2.6.2"
debug = False
id_token: str = None
refresh_token: str = None
Expand Down Expand Up @@ -47,7 +47,6 @@ def load_config(self):
"Watcher", "play_audio") == 'True'
else:
self.play_audio = True
changes = True

if self._config.has_option("Watcher", "volume"):
self.volume = float(self._config.get(
Expand Down Expand Up @@ -120,6 +119,7 @@ def HIWORD(dword):
curr_version = version.parse(
f"{HIWORD(ms)}.{LOWORD(ms)}.{HIWORD(ls)}.{LOWORD(ls)}")
latest_version = version.parse(self.launcher_version)
pe.close()

if latest_version > curr_version:
self.launcher_needs_update = True
Expand Down Expand Up @@ -148,6 +148,7 @@ def HIWORD(dword):
curr_version = version.parse(
f"{HIWORD(ms)}.{LOWORD(ms)}.{HIWORD(ls)}.{LOWORD(ls)}")
latest_version = version.parse(self.watcher_version)
pe.close()

if latest_version > curr_version:
self.needs_update = True
self.watcher_needs_update = True
49 changes: 38 additions & 11 deletions modules/sound.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import sys
from threading import Thread
import threading
from time import sleep
import simpleaudio as sa
import os
from pycaw.pycaw import AudioUtilities
from modules.common.singleton import Singleton
from modules.config import Config
from modules.logging import AppLogger


class PlaySoundThread(Thread):
Expand Down Expand Up @@ -43,25 +46,49 @@ def playDownloadComplete():


class VolumeController(metaclass=Singleton):
sessions = None
audio = None
volume = 1.0
lock = threading.Lock()

def __init__(self):
self.searchProcess()
self.sessions = AudioUtilities.GetAllSessions()
spt = Thread(target=self.searchProcess)
spt.start()

def searchProcess(self):
sessions = AudioUtilities.GetAllSessions()
file_name = os.path.basename(sys.executable)
def searchProcess(self, retries = 0):
if self.lock.locked() or self.audio:
return
file_name = os.path.basename(sys.argv[0])
self.lock.acquire()
try:
self.sessions = AudioUtilities.GetAllSessions()
AppLogger().info(f"VolumeController - FileName: {file_name} - retry: {retries}")
for session in self.sessions:
if session.Process and session.Process.name() == file_name:
AppLogger().info(f"VolumeController - FileName: {file_name} - Found")
self.audio = session.SimpleAudioVolume
self.volume = self.audio.GetMasterVolume()
self.setVolume(Config().volume/100)
break
except Exception as ex:
AppLogger().exception(ex)

for session in sessions:
if session.Process and session.Process.name() == file_name:
self.audio = session.SimpleAudioVolume
self.volume = self.audio.GetMasterVolume()
self.setVolume(Config().volume/100)
break
if(self.audio is None):
if retries < 3:
sleep(2)
if self.lock.locked():
self.lock.release()
self.searchProcess(retries+1)
else:
AppLogger().error(f"VolumeController - FileName: {file_name} - Not Found")
if self.lock.locked():
self.lock.release()

def setVolume(self, volume):
if self.audio:
self.audio.SetMasterVolume(volume, None)
else:
self.searchProcess()
self.sessions = AudioUtilities.GetAllSessions()
spt = Thread(target=self.searchProcess)
spt.start()

0 comments on commit e70b4b2

Please sign in to comment.