Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CardStorage services: types in interprocess communication #39

Merged
merged 8 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module.exports = {
}
},
rules: {
indent: "error",
semi: "error",
"@typescript-eslint/ban-ts-comment": "warn",
"no-async-promise-executor": "warn",
"no-void": "off",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Electron test

on:
pull_request:
types: [opened, reopened, edited]
types: [opened, reopened, edited, synchronize]
branches: ['main']

jobs:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test:unit": "vue-cli-service test:unit",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "cp -rf node_modules/eyelog/bin extraResources && electron-builder install-app-deps",
"postinstall": "(copy node_modules\\eyelog\\bin .\\extraResources\\bin\\ || cp -rf node_modules/eyelog/bin extraResources) && electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"dependencies": {
Expand Down
53 changes: 27 additions & 26 deletions src/CardsStorage/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
import { getMethods } from "@/utils/getMethods";

export abstract class ICloudStorage {
static getMethods () {
return getMethods(class extends ICloudStorage {
static getMethods (): Array<keyof ICloudStorage> {
const mockImplementation = class extends ICloudStorage {
getArgv (): Promise<string[]> {
throw new Error("Method not implemented.");
}

downloadAndUnpack (url: string): Promise<void> {

Check warning on line 12 in src/CardsStorage/abstract.ts

View workflow job for this annotation

GitHub Actions / build

'url' is defined but never used
throw new Error("Method not implemented.");
}

getFiles (path: string): Promise<Directory | null> {

Check warning on line 16 in src/CardsStorage/abstract.ts

View workflow job for this annotation

GitHub Actions / build

'path' is defined but never used
throw new Error("Method not implemented.");
}

getConfigFile (path: string): ConfigFile | Promise<ConfigFile | null> | null {

Check warning on line 20 in src/CardsStorage/abstract.ts

View workflow job for this annotation

GitHub Actions / build

'path' is defined but never used
throw new Error("Method not implemented.");
}

getDefaultImage (path: string): Buffer | Promise<Uint8Array | null> | null {

Check warning on line 24 in src/CardsStorage/abstract.ts

View workflow job for this annotation

GitHub Actions / build

'path' is defined but never used
throw new Error("Method not implemented.");
}

getImage (path: string, entry: string): Buffer | Promise<Uint8Array | null> | null {

Check warning on line 28 in src/CardsStorage/abstract.ts

View workflow job for this annotation

GitHub Actions / build

'path' is defined but never used

Check warning on line 28 in src/CardsStorage/abstract.ts

View workflow job for this annotation

GitHub Actions / build

'entry' is defined but never used
throw new Error("Method not implemented.");
}

Expand Down Expand Up @@ -80,30 +80,31 @@
showItemInFolder (file: string): Promise<void> {
throw new Error("Method not implemented.");
}
});
};
return getMethods<ICloudStorage>(mockImplementation);
}

abstract getFiles(path: string): Promise<(Directory | null)>;
abstract getConfigFile(path: string): ConfigFile | null | Promise<ConfigFile | null>;
abstract getDefaultImage(path: string): Buffer | null | Promise<Uint8Array | null>;
abstract getImage(path: string, entry: string): Buffer | null | Promise<Uint8Array | null>;
abstract getAudio(path: string, entry: string): Buffer | null | Promise<Uint8Array | null>;
abstract moveToTrash(path: string): Promise<void>;
abstract copyToTemp(path: string): Promise<string>;
abstract selectImage(path: string): Promise<string | null>;
abstract selectAudio(path: string): Promise<string | null>;
abstract createImageFromText(path: string, text: string): Promise<string | null>;
abstract createAudioFromText(path: string, text: string, voice: string): Promise<string | null>;
abstract defaultToTemp(file: string): string | Promise<string>;
abstract saveSet(path: string, location: string, config: ConfigFile): Promise<void>
abstract moveSet(file: string, location: string): Promise<string>;

abstract mkdir(file: string): Promise<void>
abstract rmdir(file: string): Promise<void>

abstract downloadAndUnpack(url: string): Promise<void>

abstract showItemInFolder(file: string): Promise<void>;

abstract getArgv(): Promise<string[]>
abstract getFiles(path: string): Promise<(Directory | null)>;
abstract getConfigFile(path: string): ConfigFile | null | Promise<ConfigFile | null>;
abstract getDefaultImage(path: string): Buffer | null | Promise<Uint8Array | null>;
abstract getImage(path: string, entry: string): Buffer | null | Promise<Uint8Array | null>;
abstract getAudio(path: string, entry: string): Buffer | null | Promise<Uint8Array | null>;
abstract moveToTrash(path: string): Promise<void>;
abstract copyToTemp(path: string): Promise<string>;
abstract selectImage(path: string): Promise<string | null>;
abstract selectAudio(path: string): Promise<string | null>;
abstract createImageFromText(path: string, text: string): Promise<string | null>;
abstract createAudioFromText(path: string, text: string, voice: string): Promise<string | null>;
abstract defaultToTemp(file: string): string | Promise<string>;
abstract saveSet(path: string, location: string, config: ConfigFile): Promise<void>;
abstract moveSet(file: string, location: string): Promise<string>;

abstract mkdir(file: string): Promise<void>;
abstract rmdir(file: string): Promise<void>;

abstract downloadAndUnpack(url: string): Promise<void>;

abstract showItemInFolder(file: string): Promise<void>;

abstract getArgv(): Promise<string[]>;
}
17 changes: 12 additions & 5 deletions src/CardsStorage/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { get } from "https";
import delay from "delay";
import { createImageFromText } from "@/utils/ImageFromText";
import { HOME_DIR } from "../constants";
import { getMethods } from "@/utils/getMethods";

const DEFAULT_SETS = join(__dirname, "./../extraResources/defaultSets");

Expand All @@ -24,12 +23,20 @@ export class CardsStorage extends ICloudStorage {
constructor () {
super();
this.init();
const methods = ICloudStorage.getMethods();
const methods: Array<keyof ICloudStorage> = ICloudStorage.getMethods();
// binding dispatched events from the frontend-process
// to the corresponding handlers in the backend-process
// (backend-process has its own implementation of the same interface)
// ((you're looking at it rn btw))
for (const method of methods) {
ipcMain.handle("storage:" + method, (_, ...args) => {
ipcMain.handle("storage:" + method, (_, ...args: any) => {
function tuple<T extends any[]> (...args: T): T {
return args;
}
win = BrowserWindow.fromWebContents(_.sender);
// @ts-ignore
return this[method](...args);
const argsAsTuple = tuple<any>(...args);

return (this[method] as (...args: Array<string | ConfigFile>) => void)(...argsAsTuple);
});
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/SetGridButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ export default class SetGridButton extends Vue.with(Props) {
const yOffset = (canvas.height - finalHeight) / 2;

const ctx = canvas.getContext("2d");
// @ts-ignore
ctx.clearRect(0, 0, canvas.width, canvas.height);
// @ts-ignore
ctx.drawImage(img, xOffset, yOffset, finalWidth, finalHeight);

ctx?.clearRect(0, 0, canvas.width, canvas.height);
ctx?.drawImage(img, xOffset, yOffset, finalWidth, finalHeight);
};
}

Expand Down
6 changes: 2 additions & 4 deletions src/tobii/pageWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@ export class PageWatcher {
return;
}

this.exitWatch()
;
this.exitWatch();
});
ipcRenderer.on("eye-click", (event, data) => {
if (data?.id != this.elements.id) return;

const element = this.elements.elements[data.elementIndex];
if (data.count > 1) return;
this.clickWatch(element, true)
;
this.clickWatch(element, true);
});

window.addEventListener("keydown", (event) => {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/getMethods.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

export function getMethods<T> (cls: new (...args: any[]) => T): string[] {
return Object.getOwnPropertyNames(cls.prototype).filter(c => c !== "constructor");
export function getMethods<T> (cls: new (...args: any[]) => T): Array<keyof T> {
return Object.getOwnPropertyNames(cls.prototype)
.filter(protoProp => typeof cls.prototype[protoProp as keyof T] === "function" &&
protoProp !== "constructor") as Array<keyof T>;
}
Loading