feat(settings): add an offline mode that hides internet-only tools

"offline": true in tools-settings.json hides tools that need internet
access (menus and routes). Tools declare it with requiresInternet, either
always or unless an intranet mirror is configured. The settings helper
lives in a module without top-level await so eagerly loaded tool
index.ts files can use it without delaying app boot.

Refs sharevb/it-tools#571

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sebastian DanielssonandClaude Opus 5.5 authored and sharevb committed 2026-10-25 18:51:17 +01:00
1 parent ea30976669
commit 4a80283786
12 files changed
+47 -4

No files matched your search

+11 -2
View File
@@ -1,8 +1,17 @@
import { appBaseUrl as base } from '@/utils/base-url';
import type { ToolsSettings } from '@/utils/tools-settings';
export { type ToolsSettings, getToolsSettingString } from '@/utils/tools-settings';
// Optional per-deployment settings. Lives in its own top-level-await module so the
// fetch runs concurrently with the config fetches in src/tools/index.ts (sibling async
// module subgraphs evaluate in parallel) instead of serially after them.
export const toolsSettings: Record<string, Record<string, any> | any> = await fetch(`${base}tools-settings.json`)
.then((response) => (response.ok ? (response.json() as Promise<Record<string, Record<string, any> | any>>) : {}))
export const toolsSettings: ToolsSettings = await fetch(`${base}tools-settings.json`)
.then((response) => (response.ok ? (response.json() as Promise<ToolsSettings>) : {}))
.catch(() => ({}));
/**
* `"offline": true` in tools-settings.json marks a deployment without internet access (an air-gapped intranet).
* Tools that only work with internet are hidden, and tools with a bundled or mirrored fallback switch to it.
*/
export const isOfflineMode = toolsSettings.offline === true;
@@ -11,4 +11,5 @@ export const tool = defineTool({
createdAt: new Date('2026-05-11'),
category: 'Forensic',
externAccessDescription: t('tools.dns-propagation-tester.externalAccess'),
requiresInternet: true,
});
+1
View File
@@ -11,4 +11,5 @@ export const tool = defineTool({
createdAt: new Date('2024-08-15'),
category: 'Network',
externAccessDescription: t('tools.dns-queries.externalAccess'),
requiresInternet: true,
});
+1
View File
@@ -11,4 +11,5 @@ export const tool = defineTool({
createdAt: new Date('2025-08-15'),
category: 'Network',
externAccessDescription: t('tools.dnsbl-checker.externalAccess'),
requiresInternet: true,
});
+2
View File
@@ -1,5 +1,6 @@
import { translate as t } from '@/plugins/i18n.plugin';
import { defineTool } from '../tool';
import { getToolsSettingString } from '@/utils/tools-settings';
export const tool = defineTool({
name: t('tools.explainshell.title'),
@@ -11,4 +12,5 @@ export const tool = defineTool({
createdAt: new Date('2026-01-30'),
category: 'Data',
externAccessDescription: t('tools.explainshell.externalAccess'),
requiresInternet: (settings) => !getToolsSettingString(settings, 'explainchain', 'url'),
});
+1
View File
@@ -11,4 +11,5 @@ export const tool = defineTool({
createdAt: new Date('2025-10-03'),
category: 'Network',
externAccessDescription: t('tools.iana-whois-checker.externalAccess'),
requiresInternet: true,
});
+11 -2
View File
@@ -5,14 +5,17 @@ import { appBaseUrl as base } from '@/utils/base-url';
const modules = import.meta.glob<true, string, ToolWithCategory>('./*/index.ts', { eager: true, import: 'tool' });
// Both config files are optional; fetch them in parallel so app boot waits on at
// most one network round-trip instead of two sequential ones.
const [filterConfig, externalTools] = await Promise.all([
// most one network round-trip instead of two sequential ones. tools-settings.json is
// imported dynamically for the same reason: a static import would evaluate (and fetch)
// it before this module's own fetches start.
const [filterConfig, externalTools, { toolsSettings, isOfflineMode }] = await Promise.all([
fetch(`${base}tools-filter.json`)
.then((response) => (response.ok ? (response.json() as Promise<ToolsFilter>) : ({} as ToolsFilter)))
.catch(() => ({}) as ToolsFilter),
fetch(`${base}external-tools.json`)
.then((response) => (response.ok ? (response.json() as Promise<ExternalTool[]>) : ([] as ExternalTool[])))
.catch(() => [] as ExternalTool[]),
import('@/tools-settings'),
]);
const allModules: ToolWithCategory[] = Object.values(modules);
@@ -45,7 +48,13 @@ const filters = {
includeToolsFilterRegex: makeRegExp(filterConfig.includeToolsFilterRegex),
};
const requiresInternet = ({ requiresInternet }: ToolWithCategory) =>
typeof requiresInternet === 'function' ? requiresInternet(toolsSettings) : Boolean(requiresInternet);
const filteredModules = allModules.filter((tool) => {
if (isOfflineMode && requiresInternet(tool)) {
return false;
}
const category = tool.category || 'Development';
if (filters.includeToolsFilterRegex?.test(tool.path)) {
return true;
+1
View File
@@ -11,4 +11,5 @@ export const tool = defineTool({
createdAt: new Date('2024-01-17'),
category: 'Network',
externAccessDescription: t('tools.ip-geo-location.externalAccess'),
requiresInternet: true,
});
+1
View File
@@ -11,4 +11,5 @@ export const tool = defineTool({
createdAt: new Date('2025-01-01'),
category: 'Network',
externAccessDescription: t('tools.my-ip.externalAccess'),
requiresInternet: true,
});
+1
View File
@@ -11,4 +11,5 @@ export const tool = defineTool({
createdAt: new Date('2026-01-03'),
category: 'Data',
externAccessDescription: t('tools.online-wiktionary.externalAccess'),
requiresInternet: true,
});
+7
View File
@@ -1,3 +1,4 @@
import type { ToolsSettings } from '@/utils/tools-settings';
import type { Component } from 'vue';
export interface Tool {
@@ -12,6 +13,12 @@ export interface Tool {
createdAt?: Date;
npmPackages?: string[];
externAccessDescription?: string;
/**
* Whether the tool needs internet access to be useful. When the deployment sets `"offline": true` in
* tools-settings.json, tools for which this is (or returns) true are hidden. Use the function form for tools that
* work offline once an intranet mirror is configured in tools-settings.json.
*/
requiresInternet?: boolean | ((settings: ToolsSettings) => boolean);
footer?: string;
category: string;
externalHTMLContent?: string;
+9
View File
@@ -0,0 +1,9 @@
// Kept apart from src/tools-settings.ts, which fetches tools-settings.json with a top-level await: tool index.ts files
// load eagerly, and importing that module from them would hold up src/tools/index.ts until the fetch completes.
export type ToolsSettings = Record<string, any>;
/** A second-level `tools-settings.json` value (`{ "<tool>": { "<key>": "..." } }`), trimmed, or '' when unset. */
export function getToolsSettingString(settings: ToolsSettings, tool: string, key: string): string {
return String(settings[tool]?.[key] ?? '').trim();
}