Skip to content

Commit

Permalink
Merge pull request #29 from mlsof21/fix-transfer-name-issues
Browse files Browse the repository at this point in the history
Fix transfer name issues
  • Loading branch information
mlsof21 committed Nov 25, 2022
2 parents 0f3f05a + e6f3632 commit 05a8467
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
### 1.2.3 - 2022-11-25 - Parsing Issues

- Weapons with periods in their name (IKELOS weapons, a few others) are now parsed correctly
- Slight optimization for transferring weapons by name (no longer populates the search bar with `name:"<weapon>"`)

### 1.2.2 - 2022-10-04 - Activation Phrase Fix

- Added fix for capital letter in activation phrase by trimming/lowercasing everywhere
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "voice-dim",
"version": "1.2.2",
"version": "1.2.3",
"description": "Perform common DIM actions by using speech recognition.",
"main": "dist/chrome/js/voice-dim.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.chrome.json
@@ -1,7 +1,7 @@
{
"name": "Voice DIM",
"description": "Control DIM with your voice.",
"version": "1.2.2",
"version": "1.2.3",
"manifest_version": 3,
"background": {
"service_worker": "js/background.js"
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.firefox.json
@@ -1,7 +1,7 @@
{
"name": "Voice DIM",
"description": "Control DIM with your voice.",
"version": "1.2.2",
"version": "1.2.3",
"manifest_version": 2,
"background": {
"scripts": ["js/background.js"]
Expand Down
6 changes: 5 additions & 1 deletion scripts/update_version.py
Expand Up @@ -45,6 +45,7 @@ def write_new_version(file_path: str, new_version: str, dry_run: bool = False):
data['version'] = f"{new_version}"

if dry_run:
print("Not writing to file since dry run")
return

with open(file_path, 'w') as f:
Expand All @@ -63,6 +64,7 @@ def write_changelog_update(file_path: str, new_version: str, dry_run: bool = Fal
print(data)

if dry_run:
print("Not writing to file since dry run")
return

with open(file_path, 'w') as f:
Expand Down Expand Up @@ -107,7 +109,9 @@ def main():
print(current_version)

next_version = get_next_version(current_version, part)
print(next_version)

print("New version:", next_version)
print("Dry run:", dry_run)

for file in files:
write_new_version(file, next_version, dry_run)
Expand Down
45 changes: 29 additions & 16 deletions src/ts/voiceDim.ts
Expand Up @@ -217,8 +217,9 @@ async function handleStoreItem(query: string) {
await clearSearchBar();
return;
}
await populateSearchBar(`name:"${itemToStore?.match}"`);
const itemDiv = availableItems[itemToStore.match];
// probably not necessary since we're just using the element returned above
// await populateSearchBar(`name:"${itemToStore?.match}"`);
const itemDiv = availableItems[itemToStore.match].item;
itemDiv?.dispatchEvent(uiEvents.singleClick);
const vaultDiv = await waitForElementToDisplay('.item-popup [title^="Vault"]');
vaultDiv?.dispatchEvent(uiEvents.singleClick);
Expand Down Expand Up @@ -266,13 +267,20 @@ async function getItemToMove(query: string): Promise<Element | null> {
let nonPerkQuery = getGenericQuery(splitQuery[0]);

const perkQuery = splitQuery.length > 1 && splitQuery[1] !== '' ? getPerkQuery(splitQuery[1]) : '';

// getting a specific weapon
if (nonPerkQuery === '') {
const availableItems = getAllTransferableItems();
const itemToGet = getClosestMatch(Object.keys(availableItems), splitQuery[0]);
await populateSearchBar(`${perkQuery} name:"${itemToGet?.match}"`);
if (!itemToGet) return null;
const fullName = availableItems[itemToGet.match].name;
debugLog('voice dim', { itemToGet });
await populateSearchBar(`${perkQuery} name:"${fullName}"`.trim());
const visibleItems = getVisibleItems();
itemToMove = visibleItems[0];
} else {
}
// Getting a generic weapon (solar grenade launcher, kinetic handcannon, etc.)
else {
nonPerkQuery += ` ${perkQuery} -is:incurrentchar -is:postmaster`;
await populateSearchBar(nonPerkQuery);
const filteredItems = getVisibleItems();
Expand All @@ -287,7 +295,7 @@ async function transferItem(item: Element) {
item.dispatchEvent(uiEvents.singleClick);
const currentClass = getCurrentCharacterClass();
const expandCollapseButton = await waitForElementToDisplay('div[title^="Expand or collapse"]');
if (!document.querySelector('div[class^="ItemMoveLocations"]')) {
if (!document.querySelector('div[title^="Store"]')) {
expandCollapseButton?.dispatchEvent(uiEvents.singleClick);
}
const storeDiv = await waitForElementToDisplay(`[title^="Store"] [data-icon*="${currentClass}"]`, 500);
Expand Down Expand Up @@ -409,15 +417,15 @@ function checkForGenericTerms(queries: Record<string, string>, query: string) {
return fullQuery;
}

function getAllTransferableItems(): Record<string, Element> {
const items: Record<string, Element> = {};
function getAllTransferableItems(): Record<string, { name: string; item: Element }> {
const items: Record<string, { name: string; item: Element }> = {};
for (const labelName of transferableItemAriaLabels) {
const result = document.querySelectorAll(`[aria-label="${labelName}"] .item`);
const filteredItems = getVisibleItems(result);
filteredItems.forEach((item) => {
const split = (<HTMLElement>item).title.split('\n');
const sanitized = split[0].replaceAll('.', '');
items[sanitized] = item;
items[sanitized] = { name: split[0], item };
});
}

Expand Down Expand Up @@ -467,16 +475,20 @@ async function populateSearchBar(searchInput: string): Promise<void> {
const newValue = `${searchBar.value} ${searchInput.trim()}`.trim();
searchBar.value = newValue;
infoLog('voice dim', 'Populating search bar with', searchBar.value);
searchBar?.dispatchEvent(uiEvents.input);
await sleep(50);
searchBar?.focus();
searchBar?.dispatchEvent(uiEvents.enter);
searchBar?.blur;
await simulateSearchInput();

await waitForSearchToUpdate(count);
}
}

async function simulateSearchInput() {
searchBar?.dispatchEvent(uiEvents.input);
await sleep(50);
searchBar?.focus();
searchBar?.dispatchEvent(uiEvents.enter);
searchBar?.blur();
}

async function clearSearchBar() {
infoLog('voice dim', 'Clearing search bar');
const clearButton = document.querySelector('.filter-bar-button[title^=Clear]');
Expand All @@ -485,9 +497,10 @@ async function clearSearchBar() {
clearButton?.dispatchEvent(uiEvents.singleClick);
if (searchBar && searchBar?.value !== '') {
searchBar.value = '';
searchBar?.dispatchEvent(uiEvents.escape);
searchBar?.blur();
waitForUpdate = true;
}
searchBar?.blur;
if (waitForUpdate) await waitForSearchToUpdate(initialCount);
}

Expand Down Expand Up @@ -653,8 +666,8 @@ function init() {
getPerks();
getCustomCommands();
getAlwaysListeningOptions();
createMicDiv();
createHelpDiv();
if (!document.getElementById('voiceDim')) createMicDiv();
if (!document.getElementById('voiceDimHelp')) createHelpDiv();
}
}

Expand Down

0 comments on commit 05a8467

Please sign in to comment.