From 0cb5a51969b85d9ad92bb7afb46c3e2c076d7b36 Mon Sep 17 00:00:00 2001 From: hmcclew <122323895+hmcclew@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:59:13 -0500 Subject: [PATCH 1/6] fixing electron routes --- frontend/src/App.tsx | 10 +++---- frontend/src/components/RoutingComponent.tsx | 30 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 frontend/src/components/RoutingComponent.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index ff52163..7f1b967 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,6 +1,7 @@ import React from 'react'; -import { BrowserRouter as Router, Route, Routes } from "react-router-dom"; +import { Route } from "react-router-dom"; import HomePage from './pages/HomePage'; +import RoutingComponent from './components/RoutingComponent'; import AboutPage from './pages/AboutPage'; import MainPage from './pages/MainPage'; import PersuasivePage from './pages/PersuasivePage'; @@ -9,17 +10,14 @@ import ReviewsPage from './pages/ReviewsPage'; function App() { return ( - - + } /> } /> } /> } /> } /> } /> - - - + ); } diff --git a/frontend/src/components/RoutingComponent.tsx b/frontend/src/components/RoutingComponent.tsx new file mode 100644 index 0000000..cbdb214 --- /dev/null +++ b/frontend/src/components/RoutingComponent.tsx @@ -0,0 +1,30 @@ +import React, { ReactNode } from 'react'; +import { BrowserRouter as BrowserRouterImpl, HashRouter as HashRouterImpl, Routes } from 'react-router-dom'; + +interface RoutingComponentProps { + children: ReactNode; +} + +const RoutingComponent: React.FC = ({ children }) => { + if (isElectron()) { + return ( + + {children} + + ); + } else { + return ( + + {children} + + ); + } +} + +function isElectron() { + // Check if running in Electron environment + const isElectron = navigator.userAgent.toLowerCase().indexOf(' electron/') > -1; + return isElectron; +} + +export default RoutingComponent; From 3e62283c3b005c8d0a9c6719f61da329670ef9c3 Mon Sep 17 00:00:00 2001 From: hmcclew <122323895+hmcclew@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:57:22 -0500 Subject: [PATCH 2/6] build --- .github/workflows/backend.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index cfa528e..982c638 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -15,7 +15,7 @@ jobs: run: sudo apt-get install -y cmake - name: Install OCCT dependencies - run: sudo apt-get install -y libfreetype6-dev libgl2ps-dev libx11-dev libxt-dev libxmu-dev libxi-dev + run: sudo apt-get install -y libocct-* libfreetype6-dev libgl2ps-dev libx11-dev libxt-dev libxmu-dev libxi-dev - name: Create build directory working-directory: backend From 27842c48078c0266a12589eed937c21d3709bff5 Mon Sep 17 00:00:00 2001 From: hmcclew <122323895+hmcclew@users.noreply.github.com> Date: Mon, 19 Feb 2024 16:02:33 -0500 Subject: [PATCH 3/6] random stuff trying to fix build --- .github/workflows/backend.yaml | 4 ++-- backend/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index 982c638..9704e12 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -15,7 +15,7 @@ jobs: run: sudo apt-get install -y cmake - name: Install OCCT dependencies - run: sudo apt-get install -y libocct-* libfreetype6-dev libgl2ps-dev libx11-dev libxt-dev libxmu-dev libxi-dev + run: sudo apt-get install -y libfreetype6-dev libgl2ps-dev libx11-dev libxt-dev libxmu-dev libxi-dev - name: Create build directory working-directory: backend @@ -23,7 +23,7 @@ jobs: - name: Cmake Build working-directory: backend/build - run: cmake .. + run: cmake -DOpenCASCADE_DIR=/usr/local/Cellar/opencascade/7.7.2_2/lib/cmake/opencascade .. - name: Build Backend Project working-directory: backend/build diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index b252c39..9abeb02 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.5) project(Tubender) set(CMAKE_CXX_STANDARD 14) From 415d6a9cbfcd17a2a26d2354a72b58ce0124fc2c Mon Sep 17 00:00:00 2001 From: hmcclew <122323895+hmcclew@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:24:06 -0500 Subject: [PATCH 4/6] electron versioning --- .github/workflows/backend.yaml | 2 +- frontend/electron.js | 13 +++++++++++-- frontend/package-lock.json | 8 ++++---- frontend/package.json | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index 9704e12..cfa528e 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -23,7 +23,7 @@ jobs: - name: Cmake Build working-directory: backend/build - run: cmake -DOpenCASCADE_DIR=/usr/local/Cellar/opencascade/7.7.2_2/lib/cmake/opencascade .. + run: cmake .. - name: Build Backend Project working-directory: backend/build diff --git a/frontend/electron.js b/frontend/electron.js index 5a26f02..2dd656d 100644 --- a/frontend/electron.js +++ b/frontend/electron.js @@ -2,6 +2,14 @@ const { app, BrowserWindow } = require('electron'); const path = require('path'); const isDev = require('electron-is-dev'); +if (app.setNSApplicationDelegate) { + app.setNSApplicationDelegate({ + applicationSupportsSecureRestorableState: () => true, + }); +} else { + console.warn("NSApplicationDelegate is not supported on this platform."); +} + let mainWindow; function createWindow() { @@ -15,10 +23,11 @@ function createWindow() { }, }); + // Use 127.0.0.1 instead of localhost const startURL = isDev - ? 'http://localhost:3000' + ? 'http://127.0.0.1:3000' : `file://${path.join(__dirname, '../build/index.html')}`; - + mainWindow.loadURL(startURL); mainWindow.on('closed', () => (mainWindow = null)); diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 9d61c6e..0bb5889 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -22,7 +22,7 @@ "@types/electron": "^1.6.10", "@types/react": "^18.2.53", "@types/react-dom": "^18.2.18", - "electron": "^28.1.1", + "electron": "^28.2.3", "electron-builder": "^24.9.1", "electron-is-dev": "^2.0.0", "tailwindcss": "^3.4.1", @@ -8230,9 +8230,9 @@ } }, "node_modules/electron": { - "version": "28.1.1", - "resolved": "https://registry.npmjs.org/electron/-/electron-28.1.1.tgz", - "integrity": "sha512-HJSbGHpRl46jWCp5G4OH57KSm2F5u15tB10ixD8iFiz9dhwojqlSQTRAcjSwvga+Vqs1jv7iqwQRrolXP4DgOA==", + "version": "28.2.3", + "resolved": "https://registry.npmjs.org/electron/-/electron-28.2.3.tgz", + "integrity": "sha512-he9nGphZo03ejDjYBXpmFVw0KBKogXvR2tYxE4dyYvnfw42uaFIBFrwGeenvqoEOfheJfcI0u4rFG6h3QxDwnA==", "dev": true, "hasInstallScript": true, "dependencies": { diff --git a/frontend/package.json b/frontend/package.json index 9142521..b929294 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -51,7 +51,7 @@ "@types/electron": "^1.6.10", "@types/react": "^18.2.53", "@types/react-dom": "^18.2.18", - "electron": "^28.1.1", + "electron": "^28.2.3", "electron-builder": "^24.9.1", "electron-is-dev": "^2.0.0", "tailwindcss": "^3.4.1", From a9a7af00f8abeb809e3942da3d62bd3d241e8400 Mon Sep 17 00:00:00 2001 From: hmcclew <122323895+hmcclew@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:33:05 -0500 Subject: [PATCH 5/6] electron versioning --- frontend/electron.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/frontend/electron.js b/frontend/electron.js index 2dd656d..43e2f52 100644 --- a/frontend/electron.js +++ b/frontend/electron.js @@ -2,13 +2,8 @@ const { app, BrowserWindow } = require('electron'); const path = require('path'); const isDev = require('electron-is-dev'); -if (app.setNSApplicationDelegate) { - app.setNSApplicationDelegate({ - applicationSupportsSecureRestorableState: () => true, - }); -} else { - console.warn("NSApplicationDelegate is not supported on this platform."); -} +// Implement NSApplicationDelegate.applicationSupportsSecureRestorableState +app.applicationSupportsSecureRestorableState = () => true; let mainWindow; From bdd4e24581be6bcc535bf08665d3f09c5cc2d2c5 Mon Sep 17 00:00:00 2001 From: hmcclew <122323895+hmcclew@users.noreply.github.com> Date: Tue, 20 Feb 2024 14:51:04 -0500 Subject: [PATCH 6/6] running desktop application without linking to local host browser --- frontend/electron.js | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/frontend/electron.js b/frontend/electron.js index 43e2f52..420530f 100644 --- a/frontend/electron.js +++ b/frontend/electron.js @@ -1,6 +1,6 @@ const { app, BrowserWindow } = require('electron'); const path = require('path'); -const isDev = require('electron-is-dev'); +const express = require('express'); // Implement NSApplicationDelegate.applicationSupportsSecureRestorableState app.applicationSupportsSecureRestorableState = () => true; @@ -12,23 +12,34 @@ function createWindow() { width: 800, height: 600, webPreferences: { - nodeIntegration: false, // nodeIntegration is set to false - contextIsolation: true, // enable context isolation - preload: path.join(__dirname, 'preload.js'), // specify preload script + nodeIntegration: false, + contextIsolation: true, }, }); - // Use 127.0.0.1 instead of localhost - const startURL = isDev - ? 'http://127.0.0.1:3000' - : `file://${path.join(__dirname, '../build/index.html')}`; - - mainWindow.loadURL(startURL); + // Load the production build of the React application + mainWindow.loadFile(path.join(__dirname, 'build', 'index.html')); mainWindow.on('closed', () => (mainWindow = null)); } -app.on('ready', createWindow); +app.on('ready', () => { + createWindow(); + + // Create an express server to serve static files + const expressApp = express(); + const staticPath = path.join(__dirname, 'build', 'static'); + expressApp.use(express.static(staticPath)); + + // Error handling + expressApp.on('error', (err) => { + console.error('Express server error:', err); + }); + + expressApp.listen(3000, () => { + console.log('Static server running on port 3000'); + }); +}); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { @@ -40,4 +51,4 @@ app.on('activate', () => { if (mainWindow === null) { createWindow(); } -}); \ No newline at end of file +});