mirror of
https://github.com/skidoodle/hostinfo
synced 2026-04-28 01:27:36 +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);
|
||||
StorageService.setTabState(tabId, newState).catch(() => { });
|
||||
await StorageService.setTabState(tabId, newState).catch(() => { });
|
||||
|
||||
applyIconForState(tabId, newState);
|
||||
|
||||
@@ -137,7 +137,7 @@ async function processIp(tabId: number, url: string, ip: string) {
|
||||
};
|
||||
|
||||
tabStates.set(tabId, newState);
|
||||
await StorageService.setTabState(tabId, newState);
|
||||
await StorageService.setTabState(tabId, newState).catch(() => { });
|
||||
|
||||
applyIconForState(tabId, newState);
|
||||
}
|
||||
@@ -280,6 +280,9 @@ export default defineBackground({
|
||||
const state = tabStates.get(tab.id!);
|
||||
if (state) {
|
||||
applyIconForState(tab.id!, state);
|
||||
if (state.status === 'loading' && Date.now() - state.lastUpdated > 2000) {
|
||||
initTab(tab.id!, tab.url, true)
|
||||
}
|
||||
} else {
|
||||
initTab(tab.id!, tab.url, true);
|
||||
}
|
||||
@@ -288,9 +291,19 @@ export default defineBackground({
|
||||
|
||||
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||
if (changeInfo.status && tab.url) {
|
||||
if (tab.url) {
|
||||
const state = tabStates.get(tabId);
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,6 +19,9 @@ export function useHostInfo() {
|
||||
setInfo(data);
|
||||
setLoading(false);
|
||||
}
|
||||
if (data.status === 'loading' && Date.now() - data.lastUpdated > 2000) {
|
||||
browser.runtime.sendMessage({ type: 'INIT_TAB', tabId: tab.id, url: tab.url })
|
||||
}
|
||||
} else {
|
||||
if (tab.url) {
|
||||
await browser.runtime.sendMessage({ type: 'INIT_TAB', tabId: tab.id, url: tab.url });
|
||||
@@ -35,8 +38,16 @@ export function useHostInfo() {
|
||||
|
||||
const listener = (changes: any, areaName: string) => {
|
||||
if (areaName === 'session' || areaName === 'local') {
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
browser.storage.onChanged.addListener(listener);
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
||||
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
|
||||
const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,3}(:[0-9a-fA-F]{1,4}){1,4})|([0-9a-fA-F]{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 = {
|
||||
|
||||
Reference in New Issue
Block a user