## Description of Changes Adds two new user preferences to the General settings panel, addressing #5908. **Default view on launch** - a segmented control (Tools / Reader / Automate) that controls which left-column tab is active when the app starts. Previously the app always opened on the Tools tab with no way to change this. Users who spend most of their time reading PDFs had to manually switch to the Reader tab on every launch. **Default reader zoom** - a dropdown (Auto / Fit width / Fit page / 50%–200%) that sets the initial zoom level whenever a PDF is opened in the reader. Previously the app always applied an automatic fit-to-viewport calculation. Both settings are non-breaking. The defaults (`Tools` and `Auto`) reproduce the existing behaviour exactly, so existing users see no difference until they change a preference. ### What changed - `preferencesService.ts` - added `StartupView` and `ViewerZoomSetting` types plus the two new fields to `UserPreferences` with safe defaults - `ToolWorkflowContext.tsx` - one-time startup effect that navigates to the preferred tab on first render (mirrors the existing `defaultToolPanelMode` sync pattern) - `ZoomAPIBridge.tsx` - respects the zoom preference before falling back to auto-zoom logic when a document loads - `GeneralSection.tsx` - two new controls added below "Default tool picker mode"; the Select uses `comboboxProps={{ withinPortal: true }}` so the dropdown renders above the settings modal - `en-GB/translation.toml` - new keys for labels, descriptions, and option values Closes #5908 --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [x] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [x] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [ ] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [x] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) <img width="1023" height="747" alt="Screenshot 2026-04-05 185718" src="https://github.com/user-attachments/assets/6a8bc35a-d813-4ab8-b303-55bdce747a6a" /> <img width="1026" height="755" alt="Screenshot 2026-04-05 185620" src="https://github.com/user-attachments/assets/d2c45134-ed32-4332-a193-1a96837ba2a3" /> ### Testing (if applicable) - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details.
125 lines
3.8 KiB
TypeScript
125 lines
3.8 KiB
TypeScript
import { type ToolPanelMode, DEFAULT_TOOL_PANEL_MODE } from '@app/constants/toolPanel';
|
|
import { type ThemeMode, getSystemTheme } from '@app/constants/theme';
|
|
|
|
export type LogoVariant = 'modern' | 'classic';
|
|
|
|
export type PdfRenderMode = 'normal' | 'dark' | 'sepia';
|
|
|
|
export type StartupView = 'tools' | 'read' | 'automate';
|
|
|
|
export type ViewerZoomSetting = 'auto' | 'fitWidth' | 'fitPage' | '50' | '75' | '100' | '125' | '150' | '200';
|
|
|
|
export interface UserPreferences {
|
|
autoUnzip: boolean;
|
|
autoUnzipFileLimit: number;
|
|
defaultToolPanelMode: ToolPanelMode;
|
|
defaultStartupView: StartupView;
|
|
defaultViewerZoom: ViewerZoomSetting;
|
|
theme: ThemeMode;
|
|
toolPanelModePromptSeen: boolean;
|
|
hasSelectedToolPanelMode: boolean;
|
|
showLegacyToolDescriptions: boolean;
|
|
hasCompletedOnboarding: boolean;
|
|
hasSeenIntroOnboarding: boolean;
|
|
hasSeenCookieBanner: boolean;
|
|
hideUnavailableTools: boolean;
|
|
hideUnavailableConversions: boolean;
|
|
logoVariant: LogoVariant | null;
|
|
pdfRenderMode: PdfRenderMode;
|
|
}
|
|
|
|
export const DEFAULT_PREFERENCES: UserPreferences = {
|
|
autoUnzip: true,
|
|
autoUnzipFileLimit: 4,
|
|
defaultToolPanelMode: DEFAULT_TOOL_PANEL_MODE,
|
|
defaultStartupView: 'tools',
|
|
defaultViewerZoom: 'auto',
|
|
theme: getSystemTheme(),
|
|
toolPanelModePromptSeen: false,
|
|
hasSelectedToolPanelMode: false,
|
|
showLegacyToolDescriptions: false,
|
|
hasCompletedOnboarding: false,
|
|
hasSeenIntroOnboarding: false,
|
|
hasSeenCookieBanner: false,
|
|
hideUnavailableTools: false,
|
|
hideUnavailableConversions: false,
|
|
logoVariant: null,
|
|
pdfRenderMode: 'normal',
|
|
};
|
|
|
|
const STORAGE_KEY = 'stirlingpdf_preferences';
|
|
|
|
class PreferencesService {
|
|
private serverDefaults: Partial<UserPreferences> = {};
|
|
|
|
setServerDefaults(defaults: Partial<UserPreferences>): void {
|
|
this.serverDefaults = defaults;
|
|
}
|
|
|
|
getPreference<K extends keyof UserPreferences>(
|
|
key: K
|
|
): UserPreferences[K] {
|
|
// Explicitly re-read every time in case preferences have changed in another tab etc.
|
|
try {
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
|
if (stored) {
|
|
const preferences = JSON.parse(stored) as Partial<UserPreferences>;
|
|
if (key in preferences && preferences[key] !== undefined) {
|
|
return preferences[key]!;
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.error('Error reading preference:', key, error);
|
|
}
|
|
// Use server defaults if available, otherwise use hardcoded defaults
|
|
if (key in this.serverDefaults && this.serverDefaults[key] !== undefined) {
|
|
return this.serverDefaults[key]!;
|
|
}
|
|
return DEFAULT_PREFERENCES[key];
|
|
}
|
|
|
|
setPreference<K extends keyof UserPreferences>(
|
|
key: K,
|
|
value: UserPreferences[K]
|
|
): void {
|
|
try {
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
|
const preferences = stored ? JSON.parse(stored) : {};
|
|
preferences[key] = value;
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(preferences));
|
|
} catch (error) {
|
|
console.error('Error writing preference:', key, error);
|
|
}
|
|
}
|
|
|
|
getAllPreferences(): UserPreferences {
|
|
try {
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
|
if (stored) {
|
|
const preferences = JSON.parse(stored) as Partial<UserPreferences>;
|
|
// Merge with server defaults first, then stored preferences
|
|
return {
|
|
...DEFAULT_PREFERENCES,
|
|
...this.serverDefaults,
|
|
...preferences,
|
|
};
|
|
}
|
|
} catch (error) {
|
|
console.error('Error reading preferences', error);
|
|
}
|
|
// Merge server defaults with hardcoded defaults
|
|
return { ...DEFAULT_PREFERENCES, ...this.serverDefaults };
|
|
}
|
|
|
|
clearAllPreferences(): void {
|
|
try {
|
|
localStorage.removeItem(STORAGE_KEY);
|
|
} catch (error) {
|
|
console.error('Error clearing preferences:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|
|
export const preferencesService = new PreferencesService();
|