Skip to content

Commit

Permalink
chore: use server in electron app
Browse files Browse the repository at this point in the history
  • Loading branch information
rboixaderg committed Dec 22, 2023
1 parent 11c58b4 commit 55a1aae
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 102 deletions.
43 changes: 43 additions & 0 deletions electron-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions electron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "nuclia-sync-agent",
"version": "0.0.1",
"description": "This is a Nuclia Sync Agent App",
"main": "build/electron-app/src/index.js",
"main": "build/index.js",
"scripts": {
"compile": "tsc",
"start": "npm run compile && electron-forge start",
Expand Down Expand Up @@ -34,7 +34,8 @@
"rxjs": "^7.8.1",
"typescript": "^5.2.2",
"uuid": "^9.0.1",
"zod": "^3.22.4"
"zod": "^3.22.4",
"@nuclia/sync-agent": "file:../server"
},
"devDependencies": {
"@electron-forge/cli": "^6.4.2",
Expand Down
57 changes: 0 additions & 57 deletions electron-app/src/fileSystemFn.ts

This file was deleted.

29 changes: 0 additions & 29 deletions electron-app/src/fileSystemServerFn.ts

This file was deleted.

12 changes: 2 additions & 10 deletions electron-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import { Menu, Tray, app, nativeImage } from 'electron';
import os from 'os';
import path from 'path';
import { EVENTS } from '../../server/src/events/events';
import { beforeStartServer } from '../../server/src/fileSystemServerFn';

import { AppFileSystemRoutes } from '../../server/src/presentation/routes';
import { Server, eventEmitter } from '../../server/src/server';
import { initFileSystemSubscribers } from '../../server/src/subscribers';
import { EVENTS, eventEmitter, initFileSystemServer } from '@nuclia/sync-agent';

let contextMenu: Electron.Menu;
let tray = null;
const basePath = `${os.homedir()}/.nuclia`;
const appRoutes = new AppFileSystemRoutes(basePath);
const server = new Server({ port: 8000, routes: appRoutes.getRoutes() });
initFileSystemSubscribers(basePath);

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) {
Expand All @@ -31,7 +24,7 @@ const updateTrayAfterStopServer = () => {

const createWindow = async () => {
const icon = nativeImage.createFromPath(path.join(__dirname, '../public/logo.png'));

const server = await initFileSystemServer(basePath);
tray = new Tray(icon);
contextMenu = Menu.buildFromTemplate([
{
Expand All @@ -58,7 +51,6 @@ const createWindow = async () => {
]);
tray.setToolTip('Nuclia sync');
tray.setContextMenu(contextMenu);
await beforeStartServer(basePath);
server.start();
};

Expand Down
6 changes: 2 additions & 4 deletions electron-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"compilerOptions": {
"baseUrl": ".",
"target": "es2015",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"outDir": "./build",
"paths": {
"@server/*": ["../server/src/*"],
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.spec.ts", "**/*.spec.js"]
"exclude": ["**/*.spec.ts", "**/*.spec.js"]
}
4 changes: 4 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "0.0.1",
"description": "This is a sync agent to synchronize user files from diferent sources to nuclia",
"main": "build/index.js",
"types": "build/types/index.d.ts",
"files": [
"build/events/index.js"
],
"keywords": [
"Nuclia"
],
Expand Down
1 change: 1 addition & 0 deletions server/src/events/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './events';
15 changes: 15 additions & 0 deletions server/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { EVENTS } from './events';
import { beforeStartServer } from './fileSystemServerFn';
import { AppFileSystemRoutes } from './presentation/routes';
import { Server, eventEmitter } from './server';
import { initFileSystemSubscribers } from './subscribers';

export const initFileSystemServer = async (basePath: string) => {
const appRoutes = new AppFileSystemRoutes(basePath);
const server = new Server({ port: 8000, routes: appRoutes.getRoutes() });
initFileSystemSubscribers(basePath);
await beforeStartServer(basePath);
return server;
};

export { EVENTS, eventEmitter };

0 comments on commit 55a1aae

Please sign in to comment.