Skip to content

Commit

Permalink
#87 - Fixes formatting issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirHassanConsulting committed Oct 22, 2024
1 parent 62cbdfd commit fd855f9
Show file tree
Hide file tree
Showing 71 changed files with 1,356 additions and 939 deletions.
32 changes: 20 additions & 12 deletions forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ import { rendererConfig } from './webpack.renderer.config';
const config: ForgeConfig = {
packagerConfig: {
asar: true,
icon: './images/icon'
icon: './images/icon',
},
rebuildConfig: {},
makers: [new MakerSquirrel({}), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({})],
makers: [
new MakerSquirrel({}),
new MakerZIP({}, ['darwin']),
new MakerRpm({}),
new MakerDeb({}),
],
plugins: [
new AutoUnpackNativesPlugin({}),
new WebpackPlugin({
Expand All @@ -30,16 +35,19 @@ const config: ForgeConfig = {
js: './src/renderer/index.tsx',
name: 'main_window',
preload: {
js: './src/main/preload.ts'
}
}
]
js: './src/main/preload.ts',
},
},
],
},
devServer: {
client: {
overlay: { runtimeErrors: error => !error.message.startsWith('ResizeObserver loop') }
}
}
overlay: {
runtimeErrors: (error) =>
!error.message.startsWith('ResizeObserver loop'),
},
},
},
}),
// Fuses are used to enable/disable various Electron functionality
// at package time, before code signing the application
Expand All @@ -50,9 +58,9 @@ const config: ForgeConfig = {
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: true
})
]
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
],
};

export default config;
6 changes: 3 additions & 3 deletions scripts/setup-jest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import streams from 'web-streams-polyfill';
import {TextDecoder, TextEncoder} from 'util';
import { TextDecoder, TextEncoder } from 'util';

Object.assign(global, streams);
Object.assign(global, {
TextDecoder,
TextEncoder,
setImmediate: setTimeout,
clearImmediate: clearTimeout
});
clearImmediate: clearTimeout,
});
7 changes: 3 additions & 4 deletions src/main/environment/service/environment-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class EnvironmentService implements Initializable {
*/
public setVariablesInStream(stream: Readable) {
return stream.pipe(
new TemplateReplaceStream(this.getVariableValue.bind(this)),
new TemplateReplaceStream(this.getVariableValue.bind(this))
);
}

Expand Down Expand Up @@ -80,9 +80,8 @@ export class EnvironmentService implements Initializable {
* @param path The path of the collection to load and set as the current collection.
*/
public async changeCollection(path: string) {
return (this.currentCollection = await persistenceService.loadCollection(
path,
));
return (this.currentCollection =
await persistenceService.loadCollection(path));
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/main/error/internal-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export enum InternalErrorType {
}

export class InternalError extends Error {
constructor(public readonly type: InternalErrorType, message: string, public readonly cause?: Error) {
constructor(
public readonly type: InternalErrorType,
message: string,
public readonly cause?: Error
) {
super(message);
this.name = 'InternalError';
}
Expand Down
24 changes: 8 additions & 16 deletions src/main/event/main-event-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ import tmp from 'tmp';
import fs from 'fs/promises';
import { MainEventService } from './main-event-service';

jest.mock(
'electron',
() => ({
ipcMain: {
handle: jest.fn()
},
app: {
getPath: jest.fn().mockReturnValue('')
}
})
);
jest.mock('electron', () => ({
ipcMain: {
handle: jest.fn(),
},
app: {
getPath: jest.fn().mockReturnValue(''),
},
}));

const eventService = MainEventService.instance;

Expand All @@ -29,7 +26,6 @@ describe('MainEventService', () => {
});

it('should get the file info correctly', async () => {

// Act
const fileInfo = await eventService.getFileInfo(TEST_FILE_PATH);

Expand All @@ -40,7 +36,6 @@ describe('MainEventService', () => {
});

it('should read the file correctly providing no parameters', async () => {

// Act
const buffer = await eventService.readFile(TEST_FILE_PATH);

Expand All @@ -49,7 +44,6 @@ describe('MainEventService', () => {
});

it('should read the file correctly with offset', async () => {

// Act
const buffer = await eventService.readFile(TEST_FILE_PATH, 1);

Expand All @@ -58,12 +52,10 @@ describe('MainEventService', () => {
});

it('should read the file correctly with offset and length', async () => {

// Act
const buffer = await eventService.readFile(TEST_FILE_PATH, 1, 2);

// Assert
expect(Buffer.from(buffer).toString()).toBe(TEST_STRING.substring(1, 3));
});

});
11 changes: 4 additions & 7 deletions src/main/event/main-event-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ declare type AsyncFunction<R> = (...args: unknown[]) => Promise<R>;
* @param fn The function to wrap.
*/
function wrapWithErrorHandler<F extends AsyncFunction<R>, R>(fn: F) {
return async function(...args: Parameters<F>) {
return async function (...args: Parameters<F>) {
try {
return (await fn(...args)) as R;
} catch (error) {
Expand All @@ -44,7 +44,7 @@ function registerEvent<T>(instance: T, functionName: keyof T) {
if (typeof method === 'function') {
console.debug(`Registering event function "${functionName}()" on backend`);
ipcMain.handle(functionName as string, (_event, ...args) =>
wrapWithErrorHandler(method as unknown as AsyncFunction<unknown>)(...args),
wrapWithErrorHandler(method as unknown as AsyncFunction<unknown>)(...args)
);
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@ export class MainEventService implements IEventService {
offset,
'and length limited to',
length ?? 'unlimited',
'bytes',
'bytes'
);
if (offset === 0 && length === undefined) {
return (await readFile(filePath)).buffer;
Expand All @@ -122,10 +122,7 @@ export class MainEventService implements IEventService {
}
}

async saveRequest(
request: RufusRequest,
textBody?: string,
) {
async saveRequest(request: RufusRequest, textBody?: string) {
await persistenceService.saveRequest(request, textBody);
}

Expand Down
17 changes: 7 additions & 10 deletions src/main/filesystem/filesystem-service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import tmp from "tmp";
import {app} from "electron";
import tmp from 'tmp';
import { app } from 'electron';
import fs from 'fs';

/**
* Singleton service for file system operations
*/
export class FileSystemService {
private static readonly _instance: FileSystemService =
new FileSystemService();
private static readonly _tempDir = app?.getPath('temp') ?? '';

private static readonly _instance: FileSystemService = new FileSystemService();
private static readonly _tempDir = app?.getPath('temp') ?? "";

constructor() {

}
constructor() {}

public static get instance() {
return this._instance;
Expand All @@ -24,7 +22,7 @@ export class FileSystemService {
* @returns the temporary file object containing the file descriptor and the file name
*/
public temporaryFile() {
return tmp.fileSync({dir: FileSystemService._tempDir});
return tmp.fileSync({ dir: FileSystemService._tempDir });
}

/**
Expand All @@ -36,5 +34,4 @@ export class FileSystemService {
// how does this even work...
return fs.createReadStream(filePath);
}

}
Loading

0 comments on commit fd855f9

Please sign in to comment.