mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2026-03-28 02:31:17 +01:00
# Description of Changes - Added onboarding slides/upgrade banner conditions for all the following cases - 'licensed' - 'no-login-user-under-limit-no-license' - 'no-login-admin-under-limit-no-license' - 'no-login-user-over-limit-no-license' - 'no-login-admin-over-limit-no-license' - 'login-user-under-limit-no-license' - 'login-admin-under-limit-no-license' - 'login-user-over-limit-no-license' - 'login-admin-over-limit-no-license'; --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] 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) - [ ] I have performed a self-review of my own code - [ ] 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) - [ ] 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) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] 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. --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: Connor Yoh <connor@stirlingpdf.com>
97 lines
2.8 KiB
TypeScript
97 lines
2.8 KiB
TypeScript
import { type ToolPanelMode, DEFAULT_TOOL_PANEL_MODE } from '@app/constants/toolPanel';
|
|
import { type ThemeMode, getSystemTheme } from '@app/constants/theme';
|
|
|
|
export interface UserPreferences {
|
|
autoUnzip: boolean;
|
|
autoUnzipFileLimit: number;
|
|
defaultToolPanelMode: ToolPanelMode;
|
|
theme: ThemeMode;
|
|
toolPanelModePromptSeen: boolean;
|
|
hasSelectedToolPanelMode: boolean;
|
|
showLegacyToolDescriptions: boolean;
|
|
hasCompletedOnboarding: boolean;
|
|
hasSeenIntroOnboarding: boolean;
|
|
hasSeenCookieBanner: boolean;
|
|
hideUnavailableTools: boolean;
|
|
hideUnavailableConversions: boolean;
|
|
}
|
|
|
|
export const DEFAULT_PREFERENCES: UserPreferences = {
|
|
autoUnzip: true,
|
|
autoUnzipFileLimit: 4,
|
|
defaultToolPanelMode: DEFAULT_TOOL_PANEL_MODE,
|
|
theme: getSystemTheme(),
|
|
toolPanelModePromptSeen: false,
|
|
hasSelectedToolPanelMode: false,
|
|
showLegacyToolDescriptions: false,
|
|
hasCompletedOnboarding: false,
|
|
hasSeenIntroOnboarding: false,
|
|
hasSeenCookieBanner: false,
|
|
hideUnavailableTools: false,
|
|
hideUnavailableConversions: false,
|
|
};
|
|
|
|
const STORAGE_KEY = 'stirlingpdf_preferences';
|
|
|
|
class PreferencesService {
|
|
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);
|
|
}
|
|
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 defaults to ensure all preferences exist
|
|
return {
|
|
...DEFAULT_PREFERENCES,
|
|
...preferences,
|
|
};
|
|
}
|
|
} catch (error) {
|
|
console.error('Error reading preferences', error);
|
|
}
|
|
return { ...DEFAULT_PREFERENCES };
|
|
}
|
|
|
|
clearAllPreferences(): void {
|
|
try {
|
|
localStorage.removeItem(STORAGE_KEY);
|
|
} catch (error) {
|
|
console.error('Error clearing preferences:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|
|
export const preferencesService = new PreferencesService();
|