Skip to content

Commit

Permalink
Merge pull request #37 from mlsof21/fix-farming-mode
Browse files Browse the repository at this point in the history
Fix farming mode
  • Loading branch information
mlsof21 authored Jul 28, 2024
2 parents a2c2940 + 21c60c4 commit 94f8073
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 54 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 1.3.0 - 2024-07-27 - The One Where It Actually Works When Not Using the Beta

- Fixed Farming mode
- Fixed basically anything that used the character menu when not using the Beta app

### 1.2.7 - 2023-04-20 - The One About Troubleshooting (and Strand)

- Add `Download Logs` button to the options page
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "voice-dim",
"version": "1.2.7",
"version": "1.3.0",
"description": "Perform common DIM actions by using speech recognition.",
"main": "dist/chrome/js/voice-dim.js",
"scripts": {
Expand Down Expand Up @@ -46,4 +46,4 @@
"webpack-cli": "^4.10.0",
"webpack-visualizer-plugin2": "^1.0.0"
}
}
}
2 changes: 1 addition & 1 deletion public/manifest.chrome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Voice DIM",
"description": "Control DIM with your voice.",
"version": "1.2.7",
"version": "1.3.0",
"manifest_version": 3,
"background": {
"service_worker": "js/background.js"
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.firefox.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Voice DIM",
"description": "Control DIM with your voice.",
"version": "1.2.7",
"version": "1.3.0",
"manifest_version": 2,
"background": {
"scripts": ["js/background.js"]
Expand Down
15 changes: 6 additions & 9 deletions src/ts/background.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { infoLog } from './common';
const tag = 'background';

chrome.commands.onCommand.addListener((command: any) => {
infoLog('voice dim', `Command "${command}" triggered`);
infoLog(tag, `Command "${command}" triggered`);
sendDimTabMessage({ dimShortcutPressed: true });
});

Expand All @@ -23,30 +24,26 @@ async function getDimTabId(): Promise<number | undefined | null> {
async function sendDimTabMessage(message: any) {
const dimTabId = await getDimTabId();
if (dimTabId) {
infoLog('message', 'sending', message);
infoLog(tag, 'sending', message);

chrome.tabs.sendMessage(dimTabId, message, (response: any) => {
infoLog('voice dim', { response });
infoLog(tag, { response });
});
}
}

chrome.runtime.onMessage.addListener((data: any, sender: chrome.runtime.MessageSender) => {
infoLog('voice dim', { data });
infoLog(tag, { data });
if (data === 'showOptions') {
openOptionsPage();
}
});

chrome.runtime.onInstalled.addListener(() => {
openOptionsPage();
});

async function openOptionsPage() {
const [optionsTab] = await chrome.tabs.query({
url: `chrome-extension://${chrome.runtime.id}\/html\/options.html`,
});
infoLog('voice dim', { optionsTab });
infoLog(tag, { optionsTab });
if (!optionsTab) chrome.tabs.create({ url: '../html/options.html' });
else {
chrome.tabs.update(optionsTab.id!, { active: true });
Expand Down
14 changes: 8 additions & 6 deletions src/ts/common.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
export const logs: Log[] = [];

const commonTag = 'common';

export type Log = {
tag: string;
message: unknown;
args: unknown[];
};

export function infoLog(tag: string, message: unknown, ...args: unknown[]) {
console.log(`[${tag}]`, message, ...args);
console.log(`[voice dim - ${tag}]`, message, ...args);
logs.push({ tag: `[${tag} info]`, message, args });
}

export function debugLog(tag: string, message: unknown, ...args: unknown[]) {
console.debug(`[${tag}]`, message, ...args);
console.debug(`[voice dim - ${tag}]`, message, ...args);
logs.push({ tag: `[${tag} debug]`, message, args });
}

Expand Down Expand Up @@ -71,7 +73,7 @@ export async function waitForElementToDisplay(
} else {
setTimeout(function () {
if (timeoutInMs && Date.now() - startTimeInMs > timeoutInMs) {
debugLog('voice dim', "couldn't find", selector);
debugLog(commonTag, "couldn't find", selector);
return reject();
}
loopSearch();
Expand Down Expand Up @@ -104,7 +106,7 @@ export const DEFAULT_ALWAYS_LISTENING: AlwaysListening = {

export function store<T>(key: string, value: T) {
chrome.storage.local.set({ [key]: value }, () => {
infoLog('voice dim', 'Stored', key, value);
infoLog(commonTag, 'Stored', key, value);
});
}

Expand All @@ -115,12 +117,12 @@ export function retrieve<T>(key: string, defaultValue: T): Promise<T> {
console.error(chrome.runtime.lastError.message);
reject(chrome.runtime.lastError.message);
}
infoLog('voice dim', { result });
infoLog(commonTag, { result });
if (Object.keys(result).length == 0) {
store(key, defaultValue);
resolve(defaultValue);
}
infoLog('voice dim', 'Found', result[key]);
infoLog(commonTag, 'Found', result[key]);
resolve(result[key]);
});
});
Expand Down
14 changes: 8 additions & 6 deletions src/ts/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
store,
} from './common';

const tag = 'options';

function onCommandChange() {
const commands: Record<string, string[]> = {};
Object.keys(DEFAULT_COMMANDS).forEach((command) => {
Expand All @@ -24,7 +26,7 @@ function onCommandChange() {
const dimTabs = tabs.filter((tab) => tab.url?.match(/destinyitemmanager\.com.*inventory/));
if (dimTabs && dimTabs[0].id)
chrome.tabs.sendMessage(dimTabs[0].id, 'shortcut updated', (response) => {
infoLog('voice dim', { response });
infoLog(tag, { response });
});
});
}
Expand All @@ -34,13 +36,13 @@ function sendListenOptionsMessage() {
const dimTab = tabs.filter((tab) => tab.url?.match(/destinyitemmanager\.com.*inventory/))[0];
if (dimTab.id)
chrome.tabs.sendMessage(dimTab.id, 'listening options updated', (response) => {
infoLog('voice dim', { response });
infoLog(tag, { response });
});
});
}

function onActivationPhraseChange() {
infoLog('voice dim', 'updating activation phrase');
infoLog(tag, 'updating activation phrase');

const activationPhrase = <HTMLInputElement>document.getElementById('activationPhrase');
const listeningToggle = <HTMLInputElement>document.getElementById('alwaysListeningToggle');
Expand All @@ -56,7 +58,7 @@ function onActivationPhraseChange() {
}

function onAlwaysListeningChange(listeningOptions: AlwaysListening) {
infoLog('voice dim', 'updating alwaysListening');
infoLog(tag, 'updating alwaysListening');

updateSaveText(true, 'Saved!');
setTimeout(() => updateSaveText(false), 3000);
Expand Down Expand Up @@ -115,7 +117,7 @@ function downloadLogsButtonClicked() {
const dimTabs = tabs.filter((tab) => tab.url?.match(/destinyitemmanager\.com.*inventory/));
if (dimTabs && dimTabs[0].id)
chrome.tabs.sendMessage(dimTabs[0].id, 'get logs', (response: { ack: string; logs: Log[] }) => {
infoLog('voice dim', { response });
infoLog(tag, { response });
const { logs } = response;

createDownloadableFile(transformLogs(logs));
Expand Down Expand Up @@ -156,7 +158,7 @@ window.onload = function () {
const activationPhraseInput = <HTMLInputElement>document.getElementById('activationPhrase');
activationPhraseInput?.addEventListener('keydown', debounce(onActivationPhraseChange));
const commandInputs = document.querySelectorAll('.commands input');
infoLog('voice dim', { commandInputs });
infoLog(tag, { commandInputs });
commandInputs.forEach((input) => {
input.addEventListener('keydown', debounce(onCommandChange));
});
Expand Down
Loading

0 comments on commit 94f8073

Please sign in to comment.