forked from jsnbuchanan/crowd-funder-for-time-pwa
fix: resolve SVG loading error and improve TypeScript typing
- Fix EntityIcon.vue to import blank-square.svg as module instead of using relative path - Update template to use imported SVG path for proper Electron compatibility - Make contact prop optional in EntityIcon component to fix TypeScript error - Add proper Settings type imports and method signatures in PlatformServiceMixin.ts - Replace console statements with logger calls across multiple files - Resolves SVG loading failures in Electron builds while maintaining web compatibility - Reduces TypeScript 'any' type warnings from 81 to 53
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
import type { PlatformService } from "@/services/PlatformService";
|
||||
import { mapColumnsToValues, parseJsonField } from "@/db/databaseUtil";
|
||||
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
|
||||
import { MASTER_SETTINGS_KEY, type Settings } from "@/db/tables/settings";
|
||||
import * as databaseUtil from "@/db/databaseUtil";
|
||||
import { logger } from "@/utils/logger";
|
||||
|
||||
@@ -246,7 +246,10 @@ export const PlatformServiceMixin = {
|
||||
* Utility method for retrieving and parsing settings
|
||||
* Common pattern used across many components
|
||||
*/
|
||||
async $getSettings(key: string, fallback: any = null) {
|
||||
async $getSettings(
|
||||
key: string,
|
||||
fallback: Settings | null = null,
|
||||
): Promise<Settings | null> {
|
||||
try {
|
||||
const result = await this.$dbQuery(
|
||||
"SELECT * FROM settings WHERE id = ? OR accountDid = ?",
|
||||
@@ -257,10 +260,13 @@ export const PlatformServiceMixin = {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const settings = mapColumnsToValues(
|
||||
result.columns,
|
||||
result.values,
|
||||
)[0] as any;
|
||||
const mappedResults = mapColumnsToValues(result.columns, result.values);
|
||||
|
||||
if (!mappedResults.length) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const settings = mappedResults[0] as Settings;
|
||||
|
||||
// Handle JSON field parsing
|
||||
if (settings.searchBoxes) {
|
||||
@@ -287,8 +293,8 @@ export const PlatformServiceMixin = {
|
||||
async $getMergedSettings(
|
||||
defaultKey: string,
|
||||
accountDid?: string,
|
||||
defaultFallback: any = {},
|
||||
) {
|
||||
defaultFallback: Settings = {},
|
||||
): Promise<Settings> {
|
||||
try {
|
||||
// Get default settings
|
||||
const defaultSettings = await this.$getSettings(
|
||||
@@ -298,7 +304,7 @@ export const PlatformServiceMixin = {
|
||||
|
||||
// If no account DID, return defaults
|
||||
if (!accountDid) {
|
||||
return defaultSettings;
|
||||
return defaultSettings || defaultFallback;
|
||||
}
|
||||
|
||||
// Get account-specific overrides
|
||||
@@ -308,21 +314,30 @@ export const PlatformServiceMixin = {
|
||||
);
|
||||
|
||||
if (!accountResult?.values?.length) {
|
||||
return defaultSettings;
|
||||
return defaultSettings || defaultFallback;
|
||||
}
|
||||
|
||||
// Map and filter non-null overrides
|
||||
const overrideSettings = mapColumnsToValues(
|
||||
const mappedResults = mapColumnsToValues(
|
||||
accountResult.columns,
|
||||
accountResult.values,
|
||||
)[0] as any;
|
||||
);
|
||||
|
||||
if (!mappedResults.length) {
|
||||
return defaultSettings || defaultFallback;
|
||||
}
|
||||
|
||||
const overrideSettings = mappedResults[0] as Settings;
|
||||
|
||||
const filteredOverrides = Object.fromEntries(
|
||||
Object.entries(overrideSettings).filter(([_, v]) => v !== null),
|
||||
);
|
||||
|
||||
// Merge settings with overrides taking precedence
|
||||
const mergedSettings = { ...defaultSettings, ...filteredOverrides };
|
||||
const mergedSettings = {
|
||||
...defaultSettings,
|
||||
...filteredOverrides,
|
||||
} as Settings;
|
||||
|
||||
// Handle JSON field parsing
|
||||
if (mergedSettings.searchBoxes) {
|
||||
@@ -450,7 +465,7 @@ export const PlatformServiceMixin = {
|
||||
* @param defaults Optional default values
|
||||
* @returns Cached settings object
|
||||
*/
|
||||
async $settings(defaults: any = {}): Promise<any> {
|
||||
async $settings(defaults: Settings = {}): Promise<Settings> {
|
||||
const cacheKey = `settings_${String(MASTER_SETTINGS_KEY)}`;
|
||||
const cached = this._getCached<any>(cacheKey);
|
||||
if (cached) {
|
||||
@@ -459,6 +474,10 @@ export const PlatformServiceMixin = {
|
||||
|
||||
const settings = await this.$getSettings(MASTER_SETTINGS_KEY, defaults);
|
||||
|
||||
if (!settings) {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
// **ELECTRON-SPECIFIC FIX**: Apply platform-specific API server override
|
||||
// This ensures Electron always uses production endpoints regardless of cached settings
|
||||
if (process.env.VITE_PLATFORM === "electron") {
|
||||
@@ -482,7 +501,10 @@ export const PlatformServiceMixin = {
|
||||
* @param defaults Optional default values
|
||||
* @returns Cached merged settings object
|
||||
*/
|
||||
async $accountSettings(did?: string, defaults: any = {}): Promise<any> {
|
||||
async $accountSettings(
|
||||
did?: string,
|
||||
defaults: Settings = {},
|
||||
): Promise<Settings> {
|
||||
const currentDid = did || (this as any).activeDid;
|
||||
const cacheKey = `account_settings_${currentDid || "default"}`;
|
||||
|
||||
@@ -515,7 +537,7 @@ export const PlatformServiceMixin = {
|
||||
* @param changes Settings changes to save
|
||||
* @returns Promise<boolean> Success status
|
||||
*/
|
||||
async $saveSettings(changes: any): Promise<boolean> {
|
||||
async $saveSettings(changes: Partial<Settings>): Promise<boolean> {
|
||||
const result = await databaseUtil.updateDefaultSettings(changes);
|
||||
|
||||
// Invalidate related caches
|
||||
@@ -532,7 +554,10 @@ export const PlatformServiceMixin = {
|
||||
* @param changes Settings changes to save
|
||||
* @returns Promise<boolean> Success status
|
||||
*/
|
||||
async $saveUserSettings(did: string, changes: any): Promise<boolean> {
|
||||
async $saveUserSettings(
|
||||
did: string,
|
||||
changes: Partial<Settings>,
|
||||
): Promise<boolean> {
|
||||
const result = await databaseUtil.updateDidSpecificSettings(did, changes);
|
||||
|
||||
// Invalidate related caches
|
||||
@@ -548,7 +573,7 @@ export const PlatformServiceMixin = {
|
||||
* @param changes Settings changes to save
|
||||
* @returns Promise<boolean> Success status
|
||||
*/
|
||||
async $saveMySettings(changes: any): Promise<boolean> {
|
||||
async $saveMySettings(changes: Partial<Settings>): Promise<boolean> {
|
||||
const currentDid = (this as any).activeDid;
|
||||
if (!currentDid) {
|
||||
return await this.$saveSettings(changes);
|
||||
@@ -564,7 +589,7 @@ export const PlatformServiceMixin = {
|
||||
* Manually refresh settings cache - $refreshSettings()
|
||||
* Forces reload of settings from database
|
||||
*/
|
||||
async $refreshSettings(): Promise<any> {
|
||||
async $refreshSettings(): Promise<Settings> {
|
||||
this._invalidateCache(`settings_${MASTER_SETTINGS_KEY}`);
|
||||
const currentDid = (this as any).activeDid;
|
||||
if (currentDid) {
|
||||
@@ -604,12 +629,15 @@ export interface IPlatformServiceMixin {
|
||||
$dbQuery(sql: string, params?: unknown[]): Promise<any>;
|
||||
$dbExec(sql: string, params?: unknown[]): Promise<any>;
|
||||
$dbGetOneRow(sql: string, params?: unknown[]): Promise<any>;
|
||||
$getSettings(key: string, fallback?: any): Promise<any>;
|
||||
$getSettings(
|
||||
key: string,
|
||||
fallback?: Settings | null,
|
||||
): Promise<Settings | null>;
|
||||
$getMergedSettings(
|
||||
defaultKey: string,
|
||||
accountDid?: string,
|
||||
defaultFallback?: any,
|
||||
): Promise<any>;
|
||||
defaultFallback?: Settings,
|
||||
): Promise<Settings>;
|
||||
$withTransaction<T>(callback: () => Promise<T>): Promise<T>;
|
||||
isCapacitor: boolean;
|
||||
isWeb: boolean;
|
||||
@@ -640,22 +668,32 @@ declare module "@vue/runtime-core" {
|
||||
$dbQuery(sql: string, params?: unknown[]): Promise<any>;
|
||||
$dbExec(sql: string, params?: unknown[]): Promise<any>;
|
||||
$dbGetOneRow(sql: string, params?: unknown[]): Promise<any>;
|
||||
$getSettings(key: string, defaults?: any): Promise<any>;
|
||||
$getMergedSettings(key: string, did?: string, defaults?: any): Promise<any>;
|
||||
$getSettings(
|
||||
key: string,
|
||||
defaults?: Settings | null,
|
||||
): Promise<Settings | null>;
|
||||
$getMergedSettings(
|
||||
key: string,
|
||||
did?: string,
|
||||
defaults?: Settings,
|
||||
): Promise<Settings>;
|
||||
$withTransaction<T>(fn: () => Promise<T>): Promise<T>;
|
||||
|
||||
// Cached specialized shortcuts (massive performance boost)
|
||||
$contacts(): Promise<any[]>;
|
||||
$settings(defaults?: any): Promise<any>;
|
||||
$accountSettings(did?: string, defaults?: any): Promise<any>;
|
||||
$settings(defaults?: Settings): Promise<Settings>;
|
||||
$accountSettings(did?: string, defaults?: Settings): Promise<Settings>;
|
||||
|
||||
// Settings update shortcuts (eliminate 90% boilerplate)
|
||||
$saveSettings(changes: any): Promise<boolean>;
|
||||
$saveUserSettings(did: string, changes: any): Promise<boolean>;
|
||||
$saveMySettings(changes: any): Promise<boolean>;
|
||||
$saveSettings(changes: Partial<Settings>): Promise<boolean>;
|
||||
$saveUserSettings(
|
||||
did: string,
|
||||
changes: Partial<Settings>,
|
||||
): Promise<boolean>;
|
||||
$saveMySettings(changes: Partial<Settings>): Promise<boolean>;
|
||||
|
||||
// Cache management methods
|
||||
$refreshSettings(): Promise<any>;
|
||||
$refreshSettings(): Promise<Settings>;
|
||||
$refreshContacts(): Promise<any[]>;
|
||||
$clearAllCaches(): void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user