Skip to content

Commit

Permalink
#87 - fixed formatting issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirHassanConsulting committed Oct 18, 2024
1 parent 16b80e9 commit 824c80c
Show file tree
Hide file tree
Showing 38 changed files with 428 additions and 294 deletions.
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 824c80c

Please sign in to comment.