mirror of
https://github.com/skidoodle/hostinfo
synced 2026-04-28 09:37:37 +02:00
fix states
This commit is contained in:
@@ -65,7 +65,7 @@ async function initTab(tabId: number, url: string, resolveDns = false) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
tabStates.set(tabId, newState);
|
tabStates.set(tabId, newState);
|
||||||
StorageService.setTabState(tabId, newState).catch(() => { });
|
await StorageService.setTabState(tabId, newState).catch(() => { });
|
||||||
|
|
||||||
applyIconForState(tabId, newState);
|
applyIconForState(tabId, newState);
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ async function processIp(tabId: number, url: string, ip: string) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
tabStates.set(tabId, newState);
|
tabStates.set(tabId, newState);
|
||||||
await StorageService.setTabState(tabId, newState);
|
await StorageService.setTabState(tabId, newState).catch(() => { });
|
||||||
|
|
||||||
applyIconForState(tabId, newState);
|
applyIconForState(tabId, newState);
|
||||||
}
|
}
|
||||||
@@ -280,6 +280,9 @@ export default defineBackground({
|
|||||||
const state = tabStates.get(tab.id!);
|
const state = tabStates.get(tab.id!);
|
||||||
if (state) {
|
if (state) {
|
||||||
applyIconForState(tab.id!, state);
|
applyIconForState(tab.id!, state);
|
||||||
|
if (state.status === 'loading' && Date.now() - state.lastUpdated > 2000) {
|
||||||
|
initTab(tab.id!, tab.url, true)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
initTab(tab.id!, tab.url, true);
|
initTab(tab.id!, tab.url, true);
|
||||||
}
|
}
|
||||||
@@ -288,9 +291,19 @@ export default defineBackground({
|
|||||||
|
|
||||||
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||||
if (changeInfo.status && tab.url) {
|
if (changeInfo.status && tab.url) {
|
||||||
const state = tabStates.get(tabId);
|
if (tab.url) {
|
||||||
if (state) {
|
const state = tabStates.get(tabId);
|
||||||
applyIconForState(tabId, state);
|
if (state) {
|
||||||
|
applyIconForState(tabId, state);
|
||||||
|
if (!state || state.url !== tab.url) {
|
||||||
|
initTab(tabId, tab.url, true)
|
||||||
|
} else {
|
||||||
|
applyIconForState(tabId, state);
|
||||||
|
if (changeInfo.status === 'complete' && state.status === 'loading') {
|
||||||
|
initTab(tabId, tab.url, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+12
-1
@@ -19,6 +19,9 @@ export function useHostInfo() {
|
|||||||
setInfo(data);
|
setInfo(data);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
if (data.status === 'loading' && Date.now() - data.lastUpdated > 2000) {
|
||||||
|
browser.runtime.sendMessage({ type: 'INIT_TAB', tabId: tab.id, url: tab.url })
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tab.url) {
|
if (tab.url) {
|
||||||
await browser.runtime.sendMessage({ type: 'INIT_TAB', tabId: tab.id, url: tab.url });
|
await browser.runtime.sendMessage({ type: 'INIT_TAB', tabId: tab.id, url: tab.url });
|
||||||
@@ -35,7 +38,15 @@ export function useHostInfo() {
|
|||||||
|
|
||||||
const listener = (changes: any, areaName: string) => {
|
const listener = (changes: any, areaName: string) => {
|
||||||
if (areaName === 'session' || areaName === 'local') {
|
if (areaName === 'session' || areaName === 'local') {
|
||||||
fetchInfo();
|
browser.tabs.query({ active: true, currentWindow: true }).then(([tab]) => {
|
||||||
|
if (tab?.id) {
|
||||||
|
const sessionKey = `tab_${tab.id}`;
|
||||||
|
const localKey = `session_tab_${tab.id}`;
|
||||||
|
if (changes[sessionKey] || changes[localKey]) {
|
||||||
|
fetchInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-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]{1,2}(:[0-9a-fA-F]{1,4}){1,5})|([0-9a-fA-F]{1,4}:)((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
||||||
|
|
||||||
export const IpUtils = {
|
export const IpUtils = {
|
||||||
|
|||||||
Reference in New Issue
Block a user