Skip to content

Commit 2435a82

Browse files
iostreamer-XnsrCodesRuntimeTerror10
authored
Add support to use local disk as storage (#133)
* feat: setup for any RPC Service Over IPC * draft: example of the code structure for using the RPC service class to model local sync implementation * chore: code from group discussion * register open folder dialog event * allow directory creation in fodler dialog * Added basic integration * Add support to fetch all API records * Organized imports * Added getAllRecords * Adding support for env sync * Add result based types * Added support to sanitize parsed resource list * Add getRecord and other utils * expose getAllEnvironments method * Added create record * add variable type in file * Adding support for update record * Added support to create record with id * expose env creation flow * Added support for collection methods * expose update env function * Fixed bug where parent path parsing was incorrect * Added support to duplicate * expose env duplication function * Fixed folder creation bug * Fixed bug where methods were being exposed multiple times * sync remaining request data and types fix * Added support for global config * update optional properties in API record schema * Split building local-sync manager and actual methods * Fixed bug where init was called from constructor as well * Added support for path in fs error * Added support to move entities * fix: validate special characters in collection renaming * Added path to error * Added flag to throw error if fs folder exists * Added support to set collection vars * write sync value in env file * Made deletion idempotent * update queryparam and headers schema to have optional value --------- Co-authored-by: nsrCodes <[email protected]> Co-authored-by: Parth Bhardwaj <[email protected]>
1 parent 3c61c13 commit 2435a82

20 files changed

+2298
-23
lines changed

package-lock.json

Lines changed: 51 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
"@types/node": "17.0.23",
213213
"@types/node-forge": "^1.3.11",
214214
"@types/terser-webpack-plugin": "^5.0.4",
215+
"@types/uuid": "^10.0.0",
215216
"@types/webpack-env": "^1.16.3",
216217
"browserslist-config-erb": "^0.0.3",
217218
"chalk": "^4.1.2",
@@ -258,6 +259,7 @@
258259
"@requestly/requestly-proxy": "^1.3.5",
259260
"@sentry/browser": "^8.34.0",
260261
"@sentry/electron": "^5.6.0",
262+
"@sinclair/typebox": "^0.34.25",
261263
"address": "^2.0.3",
262264
"assert": "^2.0.0",
263265
"async": "^3.2.1",
@@ -287,7 +289,7 @@
287289
"mkdirp": "^1.0.4",
288290
"node-forge": "^1.3.1",
289291
"node-gsettings-wrapper": "^0.5.0",
290-
"node-simctl": "^7.6.2",
292+
"node-simctl": "^7.7.1",
291293
"os-browserify": "^0.3.0",
292294
"path-browserify": "^1.0.1",
293295
"portfinder": "^1.0.28",
@@ -301,7 +303,7 @@
301303
"ts-node": "^10.9.2",
302304
"ua-parser-js": "^1.0.2",
303305
"util": "^0.12.4",
304-
"uuid": "^9.0.0",
306+
"uuid": "^9.0.1",
305307
"ws": "^8.2.3",
306308
"yargs": "^17.2.1"
307309
},

src/main/actions/setupIPCForwarding.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ export const setupIPCForwardingToWebApp = (webAppWindow) => {
2828
});
2929
}
3030
);
31+
32+
ipcMain.on("send-from-background-to-webapp", (event, incomingData) => {
33+
const { payload, channel } = incomingData;
34+
console.log("Sending to webapp", channel, payload);
35+
webAppWindow.webContents.send(channel, payload);
36+
});
3137
};

src/main/events.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,13 @@ export const registerMainProcessCommonEvents = () => {
255255
const fileDialogPromise = dialog.showOpenDialog(options ?? {});
256256
return fileDialogPromise;
257257
});
258+
259+
ipcMain.handle("open-folder-dialog", async (event, options = {}) => {
260+
const dialogOptions = {
261+
...options,
262+
properties: ["openDirectory", "createDirectory"],
263+
};
264+
const folderDialogPromise = await dialog.showOpenDialog(dialogOptions);
265+
return folderDialogPromise;
266+
});
258267
};

src/main/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { trackEventViaWebApp } from "./actions/events";
2929
import EVENTS from "./actions/events/constants";
3030
import fs from "fs";
3131
import logger from "../utils/logger";
32+
import { setupIPCForwardingToWebApp } from "./actions/setupIPCForwarding";
3233

3334
// Init remote so that it could be consumed in renderer
3435
const remote = require("@electron/remote/main");
@@ -430,6 +431,7 @@ app.on("ready", () => {
430431
// Create Renderer Window
431432
await createWindow();
432433
// Register Remaining IPC Events that involve browser windows
434+
setupIPCForwardingToWebApp(webAppWindow);
433435
registerMainProcessEventsForWebAppWindow(webAppWindow);
434436
registerMainProcessCommonEvents();
435437

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Define all methods invokable from webapp here, dummy for now */
2+
export function test(serializableData: any, secodArg: any) {
3+
return new Promise((resolve) => {
4+
console.log("test", serializableData);
5+
console.log("second arg", secodArg);
6+
const result = Math.floor(Math.random() * 100);
7+
console.log("Random result: ", result);
8+
resolve(`Test result: ${result}`);
9+
});
10+
}
11+
12+
export function magic(anything: any) {
13+
return new Promise((resolve) => {
14+
setTimeout(() => {
15+
console.log("Magic: ", anything);
16+
resolve("Magic done");
17+
}, 2000);
18+
});
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { RPCServiceOverIPC } from "../../lib/RPCServiceOverIPC";
2+
3+
import * as MethodsToExpose from "./actions";
4+
5+
/* only contains template code right now but can be THE place for files code */
6+
7+
export class LocalFileSync extends RPCServiceOverIPC {
8+
constructor() {
9+
super("fs"); // namespace for this service
10+
this.init();
11+
}
12+
13+
init() {
14+
// any initialization logic if needed
15+
16+
// setup all methods to be exposed over IPC
17+
Object.values(MethodsToExpose).forEach((method) => {
18+
this.exposeMethodOverIPC(method.name, method);
19+
});
20+
21+
// setup OS event listener however
22+
// setInterval(() => {
23+
// /* GARGBAGE POC CODE FOR NOW */
24+
// const randomMessage = Math.floor(Math.random() * 100);
25+
// console.log(`${Date.now()} - Sending event to webapp: `, randomMessage);
26+
27+
// // relay those events over to webapp
28+
// this.sendServiceEvent({
29+
// type: "test",
30+
// data: { test: "data - non-changing", message: randomMessage },
31+
// });
32+
// }, 7500);
33+
}
34+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { RPCServiceOverIPC } from "renderer/lib/RPCServiceOverIPC";
2+
3+
export class TestClass {
4+
constructor(
5+
readonly base: number,
6+
// readonly emitter: (event: any)=> void
7+
readonly emitter: typeof RPCServiceOverIPC.prototype.sendServiceEvent
8+
) {
9+
this.base = base;
10+
console.log("DBG: Event emitter set");
11+
setInterval(() => {
12+
emitter(`${this.base}: time${Date.now()}`);
13+
}, 3000);
14+
}
15+
16+
async add(x: number) {
17+
console.log("DBG: add called with x having type", x);
18+
return this.base + x;
19+
}
20+
21+
async multiply(x: number) {
22+
return this.base * x;
23+
}
24+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { RPCServiceOverIPC } from "renderer/lib/RPCServiceOverIPC";
2+
import { TestClass } from "./base";
3+
4+
export class TestService extends RPCServiceOverIPC {
5+
instance?: TestClass;
6+
7+
constructor() {
8+
super("test"); // namespace for this service
9+
// const instance = new TestClass(base);
10+
// this.instance = instance;
11+
this.init();
12+
}
13+
14+
init() {
15+
console.log("DBG: exposed build method");
16+
this.exposeMethodOverIPC("build", this.build.bind(this));
17+
}
18+
19+
async build(base: number) {
20+
console.log("DBG: build called");
21+
this.instance = new TestClass(base, this.sendServiceEvent.bind(this));
22+
this.exposeMethodOverIPC("add", this.instance.add.bind(this.instance));
23+
this.exposeMethodOverIPC(
24+
"multiply",
25+
this.instance.multiply.bind(this.instance)
26+
);
27+
}
28+
}

0 commit comments

Comments
 (0)