Skip to content

Commit

Permalink
Merge pull request #8754 from ever-co/fix/deep-scan
Browse files Browse the repository at this point in the history
[Fix] Deep Scan
  • Loading branch information
rahul-rocket authored Jan 25, 2025
2 parents 7be64a4 + e85e65c commit e8b67d5
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 17 deletions.
5 changes: 2 additions & 3 deletions apps/desktop-timer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const pathWindow = {
LocalStore.setFilePath({
iconPath: path.join(__dirname, 'assets', 'icons', 'menu', 'icon.png')
});

// Instance detection
const gotTheLock = app.requestSingleInstanceLock();

Expand Down Expand Up @@ -260,9 +261,7 @@ async function startServer(value, restart = false) {
pathWindow.preloadPath
);
} else {
await timeTrackerWindow.loadURL(
timeTrackerPage(pathWindow.timeTrackerUi)
);
await timeTrackerWindow.loadURL(timeTrackerPage(pathWindow.timeTrackerUi));
}
notificationWindow = new ScreenCaptureNotification(pathWindow.timeTrackerUi);
await notificationWindow.loadURL();
Expand Down
96 changes: 82 additions & 14 deletions packages/desktop-lib/src/lib/desktop-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,49 @@ import {
IProject,
IAuth,
localStore,
store
store,
FilePath
} from '@gauzy/desktop-core';

/**
* Local Store Facade for Desktop App
*/
export const LocalStore = {
getStore: (source) => {
/**
* Retrieves the value stored under a specific key from the local store.
*
* @param {string} source - The key under which the value is stored.
* @returns {any} - The value associated with the given key.
*/
getStore: (source: string): any => {
return store.get(source);
},

/**
* Retrieves the server URL based on local server settings.
*
* @returns {string} - The server URL, either local or remote.
*/
getServerUrl: (): string => {
const { config } = localStore.find();
return config?.isLocalServer ? `http://localhost:${config.port}` : config.serverUrl;
const { config } = localStore.find() ?? {};

return config?.isLocalServer
? `http://localhost:${config?.port ?? 3000}` // Defaults to port 3000 if missing
: config?.serverUrl ?? 'https://api.gauzy.co'; // Default external server URL
},

beforeRequestParams: () => {
/**
* Retrieves parameters required for API requests.
*
* @returns {object | null} - Object containing API host, authentication, project, and settings.
*/
beforeRequestParams: (): Record<string, any> | null => {
try {
const { config, auth, project, setting } = localStore.find();

return {
apiHost: config?.isLocalServer ? `http://localhost:${config.port}` : config.serverUrl,
apiHost: config.isLocalServer
? `http://localhost:${config.port ?? 3000}`
: config.serverUrl ?? 'https://api.gauzy.co',
token: auth?.token || null,
employeeId: auth?.employeeId || null,
organizationId: auth?.organizationId || null,
Expand All @@ -45,48 +66,88 @@ export const LocalStore = {
}
},

/**
* Sets the default application settings in the local store.
*/
setDefaultApplicationSetting: (): void => {
try {
localStore.setDefaults();
} catch (error) {
console.log('error set store', error);
console.error('Error setting default application settings:', error);
}
},

/**
* Resets all configuration settings to their default values.
*/
setAllDefaultConfig: (): void => {
localStore.projectService.setDefault();
localStore.authService.setDefault();
localStore.applicationSettingService.setDefault();
localStore.configService.setDefault();
},

/**
* Updates the application settings.
*
* @param {Partial<IApplicationSetting>} values - Partial object containing the updated settings.
*/
updateApplicationSetting: (values: Partial<IApplicationSetting>): void => {
localStore.applicationSettingService.update(values);
},

/**
* Updates the configuration settings.
*
* @param {Partial<IConfig>} values - Partial object containing the updated configuration values.
*/
updateConfigSetting: (values: Partial<IConfig>): void => {
localStore.configService.update(values);
},

/**
* Updates the project configuration settings.
*
* @param {Partial<IProject>} values - Partial object containing the updated project values.
*/
updateConfigProject: (values: Partial<IProject>): void => {
localStore.projectService.update(values);
},

/**
* Updates the authentication settings.
*
* @param {Partial<IAuth>} values - Partial object containing the updated authentication values.
*/
updateAuthSetting: (values: Partial<IAuth>): void => {
localStore.authService.update(values);
},

/**
* Updates the additional settings.
*
* @param {Partial<IAdditionalSetting>} values - Partial object containing the updated additional settings.
*/
updateAdditionalSetting: (values: Partial<IAdditionalSetting>): void => {
localStore.additionalSettingService.update(values);
},

/**
* Retrieves additional configuration settings.
*
* @returns {IAdditionalSetting} - The additional settings stored in local storage.
*/
getAdditionalConfig: (): IAdditionalSetting => {
return localStore.find().additionalSetting;
},

getApplicationConfig: () => {
/**
* Retrieves the entire application configuration.
*
* @returns {object} - The complete application configuration, including settings, auth, and project info.
*/
getApplicationConfig: (): Record<string, any> => {
const { config, auth, project: activeProject, setting, additionalSetting } = localStore.find();

return {
config,
auth,
Expand All @@ -96,12 +157,19 @@ export const LocalStore = {
};
},

setFilePath: (filePath): void => {
store.set({
filePath
});
/**
* Sets the file path in the local store.
*
* @param {FilePath} filePath - The file path object to store.
* @throws {Error} If `filePath` is invalid.
*/
setFilePath: (filePath: FilePath): void => {
store.set({ filePath });
},

/**
* Resets the server configuration to its default values.
*/
setDefaultServerConfig: (): void => {
localStore.configService.setDefault();
}
Expand Down

0 comments on commit e8b67d5

Please sign in to comment.