Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added additional warnings if TTS is not connected to guide people to the setup guide #444

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ jobs:
} | ConvertTo-Json
Invoke-RestMethod -Uri $webhookUrl -Method Post -ContentType "application/json" -Body $payload

# From: https://github.com/SethCohen/github-releases-to-discord
- name: Github Releases To Discord
uses: SethCohen/github-releases-to-discord@master
with:
webhook_url: ${{ secrets.DISCORD_WEBHOOK }}
color: "2105893"
username: "D4LF Release"
# Also not working, have a request out here: https://github.com/SethCohen/github-releases-to-discord/issues/29
# # From: https://github.com/SethCohen/github-releases-to-discord
# - name: Github Releases To Discord
# uses: SethCohen/github-releases-to-discord@master
# with:
# webhook_url: ${{ secrets.DISCORD_WEBHOOK }}
# color: "2105893"
# username: "D4LF Release"

# Not currently working, but I have an issue out for it: https://github.com/nhevia/discord-styled-releases/issues/12
# - name: Sending message to Discord with release notes
Expand Down
30 changes: 16 additions & 14 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
from src.item.filter import Filter
from src.logger import LOG_DIR
from src.overlay import Overlay
from src.scripts.common import SETUP_INSTRUCTIONS_URL
from src.scripts.handler import ScriptHandler
from src.utils.window import WindowSpec, start_detecting_window

LOGGER = logging.getLogger(__name__)

SETUP_INSTRUCTIONS_URL = "https://github.com/d4lfteam/d4lf/blob/main/README.md#how-to-setup"


def main():
# Create folders for logging stuff
Expand Down Expand Up @@ -105,22 +104,25 @@ def check_for_proper_tts_configuration():


def get_d4_local_prefs_file() -> Path | None:
documents_file = pathlib.Path.home() / "Documents" / "Diablo IV" / "LocalPrefs.txt"
onedrive_file = pathlib.Path.home() / "OneDrive" / "Documents" / "Diablo IV" / "LocalPrefs.txt"
all_potential_files: list[Path] = [
pathlib.Path.home() / "Documents" / "Diablo IV" / "LocalPrefs.txt",
pathlib.Path.home() / "OneDrive" / "Documents" / "Diablo IV" / "LocalPrefs.txt",
pathlib.Path.home() / "OneDrive" / "MyDocuments" / "Diablo IV" / "LocalPrefs.txt",
]

if documents_file.exists() and onedrive_file.exists():
# Return the newest of the two
if documents_file.stat().st_mtime > onedrive_file.stat().st_mtime:
return documents_file
return onedrive_file
existing_files: list[Path] = [file for file in all_potential_files if file.exists()]

if documents_file.exists():
return documents_file
if len(existing_files) == 0:
return None

if onedrive_file.exists():
return onedrive_file
if len(existing_files) == 1:
return existing_files[0]

return None
most_recently_modified_file = existing_files[0]
for existing_file in existing_files[1:]:
if existing_file.stat().st_mtime > most_recently_modified_file.stat().st_mtime:
most_recently_modified_file = existing_file
return most_recently_modified_file


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

LOGGER = logging.getLogger(__name__)

SETUP_INSTRUCTIONS_URL = "https://github.com/d4lfteam/d4lf/blob/main/README.md#how-to-setup"


def mark_as_junk():
keyboard.send("space")
Expand Down
9 changes: 8 additions & 1 deletion src/scripts/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from src.config.loader import IniConfigLoader
from src.config.models import ItemRefreshType, UseTTSType
from src.loot_mover import move_items_to_inventory, move_items_to_stash
from src.scripts.common import SETUP_INSTRUCTIONS_URL
from src.ui.char_inventory import CharInventory
from src.ui.chest import Chest
from src.utils.custom_mouse import mouse
Expand Down Expand Up @@ -55,7 +56,13 @@ def setup_key_binds(self):

def filter_items(self, force_refresh=ItemRefreshType.no_refresh):
if IniConfigLoader().general.use_tts in [UseTTSType.full, UseTTSType.mixed]:
self._start_or_stop_loot_interaction_thread(run_loot_filter, (force_refresh, True))
if src.tts.CONNECTED:
self._start_or_stop_loot_interaction_thread(run_loot_filter, (force_refresh, True))
else:
LOGGER.warning(
f"TTS connection has not been made yet. Have you followed all of the instructions in {SETUP_INSTRUCTIONS_URL}? "
f"If so, it's possible your Windows user does not have the correct permissions to allow Diablo 4 to connect to a third party screen reader."
)
else:
self._start_or_stop_loot_interaction_thread(run_loot_filter, (force_refresh, False))

Expand Down
1 change: 1 addition & 0 deletions src/scripts/loot_filter_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def check_items(inv: InventoryBase, force_refresh: ItemRefreshType):
try:
item_descr = src.item.descr.read_descr_tts.read_descr()
LOGGER.debug(f"Attempt {retry_count} to parse item based on TTS: {item_descr}")
retry_count += 1
except Exception:
screenshot("tts_error", img=img)
LOGGER.exception(f"Error in TTS read_descr. {src.tts.LAST_ITEM=}")
Expand Down
4 changes: 4 additions & 0 deletions src/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from src.config.helper import singleton

LAST_ITEM = []
CONNECTED = False
LOGGER = logging.getLogger(__name__)
_DATA_QUEUE = queue.Queue(maxsize=100)
TO_FILTER = ["Champions who earn the favor of"]
Expand Down Expand Up @@ -73,6 +74,8 @@ def read_pipe() -> None:

win32pipe.ConnectNamedPipe(handle, None)
LOGGER.debug("TTS client connected")
global CONNECTED
CONNECTED = True

while True:
try:
Expand All @@ -93,6 +96,7 @@ def read_pipe() -> None:

win32file.CloseHandle(handle)
print("TTS client disconnected")
CONNECTED = False


def find_item_start(data: list[str]) -> int | None:
Expand Down