Skip to content

Commit fa38aa7

Browse files
authored
fix: Resolve infinite recursion in options app initialization (#72)
1 parent 7441aca commit fa38aa7

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

Changelog.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
#### v1.4.6 – Released on November 1, 2025
1+
#### v1.4.7 – Released on November 01, 2025
2+
3+
##### Fixed
4+
5+
- Fixed options page opening issue.
6+
7+
---
8+
9+
#### v1.4.6 – Released on November 01, 2025
210

311
##### Fixed
412

1010 KB
Binary file not shown.
1010 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "translate-it",
3-
"version": "1.4.6",
3+
"version": "1.4.7",
44
"type": "module",
55
"description": "Smart Translation Assistant",
66
"scripts": {

src/app/main/options.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ async function initializeApp() {
6969
await setI18nLocale(userLocale);
7070
logger.debug('✅ vue-i18n plugin locale set:', userLocale)
7171

72-
// Check for tab query parameter for Firefox shortcuts navigation
73-
let initialRoute = '/';
72+
// Check for tab query parameter for Firefox shortcuts navigation and hash URLs
73+
let initialRoute = '/languages'; // Default to languages tab
7474
let shouldNavigateToHelp = false;
7575

7676
try {
77+
// First check query parameters (for Firefox shortcuts)
7778
const urlParams = new URLSearchParams(window.location.search);
7879
const tabParam = urlParams.get('tab');
7980

@@ -86,6 +87,21 @@ async function initializeApp() {
8687
// For Firefox help navigation, redirect to help tab
8788
initialRoute = '/help';
8889
logger.debug('Detected tab=help parameter, redirecting to help tab for Firefox');
90+
} else {
91+
// If no query parameter, check hash URL
92+
const hash = window.location.hash.replace('#', '').replace('/', '');
93+
if (hash === 'help' || hash === 'shortcuts') {
94+
initialRoute = '/help';
95+
logger.debug(`Detected hash #${hash}, redirecting to help tab`);
96+
} else if (hash && hash !== '') {
97+
// Use the hash path if it's valid
98+
const validRoutes = ['languages', 'appearance', 'activation', 'prompt', 'api', 'import-export', 'advance', 'about', 'help'];
99+
if (validRoutes.includes(hash)) {
100+
initialRoute = `/${hash}`;
101+
logger.debug(`Detected hash #${hash}, redirecting to ${initialRoute} tab`);
102+
}
103+
}
104+
// If hash is empty or '/', keep default languages route
89105
}
90106
} catch (e) {
91107
logger.debug('Failed to parse URL parameters:', e);
@@ -96,7 +112,22 @@ async function initializeApp() {
96112
const router = createRouter({
97113
history: createWebHashHistory(),
98114
routes: [
99-
{ path: '/', redirect: initialRoute },
115+
{ path: '/', redirect: () => {
116+
// Avoid infinite redirect by checking current hash
117+
const currentHash = window.location.hash.replace('#', '').replace('/', '');
118+
if (currentHash === '' || currentHash === '/') {
119+
logger.debug(`Root redirect: current hash is empty, redirecting to ${initialRoute}`);
120+
return initialRoute;
121+
}
122+
// If current hash matches a valid route, use it instead
123+
const validRoutes = ['languages', 'appearance', 'activation', 'prompt', 'api', 'import-export', 'advance', 'about', 'help'];
124+
if (validRoutes.includes(currentHash)) {
125+
logger.debug(`Root redirect: current hash #${currentHash} is valid, using it`);
126+
return `/${currentHash}`;
127+
}
128+
logger.debug(`Root redirect: using default route ${initialRoute}`);
129+
return initialRoute;
130+
}},
100131
{ path: '/languages', component: LanguagesTab, name: 'languages' },
101132
{ path: '/appearance', component: AppearanceTab, name: 'appearance' },
102133
{ path: '/activation', component: ActivationTab, name: 'activation' },

0 commit comments

Comments
 (0)