diff --git a/.scripts/configure.electron.ts b/.scripts/configure.electron.ts index daaa8a419..109114340 100644 --- a/.scripts/configure.electron.ts +++ b/.scripts/configure.electron.ts @@ -3,62 +3,75 @@ import * as path from 'path'; import { hideBin } from 'yargs/helpers'; import yargs from 'yargs'; -const argv: any = yargs(hideBin(process.argv)).argv; +interface Arguments { + type: 'server' | 'constant' +} +const argv = yargs(hideBin(process.argv)) + .options({ + type: { + type: 'string', + choices: ['server', 'constant'], + demandOption: true, + description: 'Type of configuration to modify' + } + }) + .parseSync() as Arguments; function modifiedNextServer() { const filePath = path.resolve(__dirname, '../apps/server-web/release/app/dist/standalone/apps/web/server.js'); - - let fileContent = fs.readFileSync(filePath, 'utf8'); - const searchString = 'process.env.__NEXT_PRIVATE_STANDALONE_CONFIG'; - const codeToInsert = ` - nextConfig.serverRuntimeConfig = { - "GAUZY_API_SERVER_URL": process.env.GAUZY_API_SERVER_URL, - "NEXT_PUBLIC_GAUZY_API_SERVER_URL": process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL - } - `; - - let lines = fileContent.split('\n'); - const index = lines.findIndex((line) => line.includes(searchString)); - - if (index !== -1) { - lines.splice(index - 1, 0, codeToInsert); - - fileContent = lines.join('\n'); - fs.writeFileSync(filePath, fileContent, 'utf8'); - console.log('Line of code successfully inserted.'); - } else { - console.log(`The string "${searchString}" was not found in the file.`); + try { + let fileContent = fs.readFileSync(filePath, 'utf8'); + const searchString = 'process.env.__NEXT_PRIVATE_STANDALONE_CONFIG'; + const codeToInsert = ` + nextConfig.serverRuntimeConfig = { + "GAUZY_API_SERVER_URL": process.env.GAUZY_API_SERVER_URL, + "NEXT_PUBLIC_GAUZY_API_SERVER_URL": process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL + } + `; + + let lines = fileContent.split('\n'); + const index = lines.findIndex((line) => line.includes(searchString)); + + if (index !== -1) { + lines.splice(index - 1, 0, codeToInsert); + + fileContent = lines.join('\n'); + fs.writeFileSync(filePath, fileContent, 'utf8'); + console.log('Line of code successfully inserted.'); + } else { + console.log(`The string "${searchString}" was not found in the file.`); + } + } catch (error) { + console.error('Failed to change static server configuration'); } } -function modifiedWebConstant() { - const filePath = path.resolve(__dirname, '../apps/web/app/constants.ts'); - - let fileContent = fs.readFileSync(filePath, 'utf8'); - const searchString = `export const IS_DESKTOP_APP = process.env.IS_DESKTOP_APP === 'true';`; - const codeToReplace = `export const IS_DESKTOP_APP = true;`; - - fileContent = fileContent.replace(searchString, codeToReplace); - - fs.writeFileSync(filePath, fileContent, 'utf8'); -} - -function revertWebConstant() { +function updateWebConstant(setDesktopApp) { const filePath = path.resolve(__dirname, '../apps/web/app/constants.ts'); - - let fileContent = fs.readFileSync(filePath, 'utf8'); - const codeToReplace = `export const IS_DESKTOP_APP = process.env.IS_DESKTOP_APP === 'true';`; - const searchString = `export const IS_DESKTOP_APP = true;`; - - fileContent = fileContent.replace(searchString, codeToReplace); - - fs.writeFileSync(filePath, fileContent, 'utf8'); + try { + let fileContent = fs.readFileSync(filePath, 'utf8'); + const envCheck = `export const IS_DESKTOP_APP = process.env.IS_DESKTOP_APP === 'true';`; + const hardcoded = `export const IS_DESKTOP_APP = true;`; + + const [from, to] = setDesktopApp ? [envCheck, hardcoded] : [hardcoded, envCheck]; + + if (!fileContent.includes(from)) { + throw new Error(`Expected content not found in ${filePath}`); + } + + fileContent = fileContent.replace(from, to); + fs.writeFileSync(filePath, fileContent, 'utf8'); + console.log(`Successfully ${setDesktopApp ? 'set' : 'reverted'} IS_DESKTOP_APP`); + } catch (error) { + console.error('Failed to update constants:', error); + process.exit(1); + } } if (argv.type === 'server') { modifiedNextServer(); - revertWebConstant(); + updateWebConstant(true); } else if (argv.type === 'constant') { - modifiedWebConstant(); + updateWebConstant(false); } diff --git a/.scripts/copy-web-build.ts b/.scripts/copy-web-build.ts new file mode 100644 index 000000000..859337a2b --- /dev/null +++ b/.scripts/copy-web-build.ts @@ -0,0 +1,34 @@ +import { copy } from 'fs-extra'; +import { join } from 'path'; + +async function copyWebBuild() { + const webDir = join(process.cwd(), 'apps/web'); + const distDir = join(process.cwd(), 'apps/server-web/release/app/dist'); + + try { + // Copy standalone build + await copy( + join(webDir, '.next/standalone'), + join(distDir) + ); + + // Copy static files + await copy( + join(webDir, '.next/static'), + join(distDir, 'standalone/apps/web/.next/static') + ); + + // Copy public files + await copy( + join(webDir, 'public'), + join(distDir, 'standalone/apps/web/public') + ); + + console.log('Build files copied successfully'); + } catch (error) { + console.error('Failed to copy build files:', error); + process.exit(1); + } +} + +copyWebBuild(); diff --git a/apps/server-web/src/main/helpers/constant.ts b/apps/server-web/src/main/helpers/constant.ts index b7d47c829..bcd77553f 100644 --- a/apps/server-web/src/main/helpers/constant.ts +++ b/apps/server-web/src/main/helpers/constant.ts @@ -40,8 +40,7 @@ export const SettingPageTypeMessage = { updateSettingResponse: 'update-setting-response', updateCancel: 'update-cancel', restartServer: 'restart-server', - themeChange: 'theme-change', - autoUpdateSetting: 'auto-update-setting' + themeChange: 'theme-change' } export const ServerPageTypeMessage = { diff --git a/apps/server-web/src/main/helpers/interfaces/i-menu.ts b/apps/server-web/src/main/helpers/interfaces/i-menu.ts index a12984192..158bc6011 100644 --- a/apps/server-web/src/main/helpers/interfaces/i-menu.ts +++ b/apps/server-web/src/main/helpers/interfaces/i-menu.ts @@ -1,15 +1,15 @@ +import { MenuItemConstructorOptions } from 'electron'; export interface AppMenu { id?: string; - label?: string; - click?: () => void; - submenu?: AppSubMenu[] -} + label: string; // Menu label + submenu?: (AppMenu | ElectronMenuItem)[]; // Nested menus or Electron menu items + role?: 'appMenu' | 'fileMenu' | 'editMenu' | 'viewMenu' | 'windowMenu' | 'help'; // Predefined menu roles + type?: 'normal' | 'separator' | 'submenu' | 'checkbox' | 'radio'; // Menu item type + click?: () => void; // Click handler for the menu item + accelerator?: string; // Keyboard shortcut + enabled?: boolean; // Whether the item is enabled + visible?: boolean; // Whether the item is visible + checked?: boolean; // For 'checkbox' or 'radio' type + } -export interface AppSubMenu { - id?: string; - label?: string; - click?: () => void; - selector?: string; - type?: string; - accelerator?: string; -} + export type ElectronMenuItem = MenuItemConstructorOptions; diff --git a/apps/server-web/src/main/helpers/interfaces/i-server.ts b/apps/server-web/src/main/helpers/interfaces/i-server.ts index a51b06d35..146e8ea31 100644 --- a/apps/server-web/src/main/helpers/interfaces/i-server.ts +++ b/apps/server-web/src/main/helpers/interfaces/i-server.ts @@ -1,7 +1,7 @@ export interface GeneralConfig { lang?: string autoUpdate?: boolean - updateCheckPeriode?: string + updateCheckPeriod?: string theme?: string setup?: boolean [key: string]: any diff --git a/apps/server-web/src/main/helpers/replace-config.ts b/apps/server-web/src/main/helpers/replace-config.ts index 155f6aa18..5e80d8730 100644 --- a/apps/server-web/src/main/helpers/replace-config.ts +++ b/apps/server-web/src/main/helpers/replace-config.ts @@ -43,14 +43,26 @@ export const replaceConfig = async (folderPath: string, envOptions: EnvOptions) } } -export const clearDesktopConfig = (folderPath: string) => { - const fileNames = ['desktop-server.body', 'desktop-server.meta']; +export const clearDesktopConfig = async (folderPath: string): Promise => { + if (!folderPath || typeof folderPath !== 'string') { + throw new Error('Invalid folder path provided'); + } + const DESKTOP_CONFIG_FILES = ['desktop-server.body', 'desktop-server.meta'] as const; try { // remove cached desktop server config - fileNames.forEach((file) => { - fs.unlinkSync(path.join(folderPath, file)); - }) + await Promise.all( + DESKTOP_CONFIG_FILES.map(async (file) => { + const filePath = path.join(folderPath, file); + try { + await fs.promises.unlink(filePath) + } catch (error: any) { + console.log('error unlink static web file', error.message) + } + }) + ) + return true; } catch (error) { - console.log('skip unlink file on not exists'); + console.log('Failed to clear static config'); + return false; } } diff --git a/apps/server-web/src/main/helpers/services/desktop-server-factory.ts b/apps/server-web/src/main/helpers/services/desktop-server-factory.ts index 4f0b09a10..8206cc2a9 100644 --- a/apps/server-web/src/main/helpers/services/desktop-server-factory.ts +++ b/apps/server-web/src/main/helpers/services/desktop-server-factory.ts @@ -8,7 +8,7 @@ export class DesktopServerFactory { if (!this.apiInstance && !!env) { this.apiInstance = new WebService(path, env, win, signal, eventEmitter); } - this.apiInstance.env = env; + this.apiInstance.updateEnv(env) return this.apiInstance; } } diff --git a/apps/server-web/src/main/helpers/services/libs/desktop-store.ts b/apps/server-web/src/main/helpers/services/libs/desktop-store.ts index eb21ec651..1875ee9c2 100644 --- a/apps/server-web/src/main/helpers/services/libs/desktop-store.ts +++ b/apps/server-web/src/main/helpers/services/libs/desktop-store.ts @@ -11,7 +11,7 @@ const DEFAULT_CONFIG:WebServer = { general: { lang: 'en', autoUpdate: true, - updateCheckPeriode: '1140' // Time in minutes + updateCheckPeriod: '1140' // Time in minutes } } export const LocalStore = { diff --git a/apps/server-web/src/main/helpers/services/web-service.ts b/apps/server-web/src/main/helpers/services/web-service.ts index 03ef62036..ffb0b59b7 100644 --- a/apps/server-web/src/main/helpers/services/web-service.ts +++ b/apps/server-web/src/main/helpers/services/web-service.ts @@ -5,7 +5,7 @@ import { EventEmitter } from 'stream'; export class WebService extends ServerTask { constructor( readonly path: string, - public env: any, + private env: any, readonly window: BrowserWindow, readonly signal: AbortSignal, readonly eventEmitter: EventEmitter @@ -41,4 +41,8 @@ export class WebService extends ServerTask { public setApiConfig(): void { Object.assign(this.args, {...this.env}); } -} + + public updateEnv(env: any): void { + this.env = {...env}; + } + } diff --git a/apps/server-web/src/main/main.ts b/apps/server-web/src/main/main.ts index 404f20d97..a8718b4dd 100644 --- a/apps/server-web/src/main/main.ts +++ b/apps/server-web/src/main/main.ts @@ -213,13 +213,13 @@ const runServer = async () => { try { const envVal: ServerConfig | undefined = getEnvApi(); const folderPath = getWebDirPath(); - clearDesktopConfig(folderPath); + await clearDesktopConfig(folderPath); // Instantiate API and UI servers await desktopServer.start( { api: serverPath }, { - ...envVal, + ...(envVal || {}), IS_DESKTOP_APP: true }, undefined, @@ -462,7 +462,6 @@ const initTrayMenu = () => { } if (setupWindow) { setupWindow?.show(); - setupWindow?. setupWindow?.webContents.once('did-finish-load', () => { setTimeout(() => { setupWindow?.webContents.send('languageSignal', storeConfig.general?.lang); @@ -492,31 +491,33 @@ const getWebDirPath = () => { ipcMain.on(IPC_TYPES.SETTING_PAGE, async (event, arg) => { switch (arg.type) { case SettingPageTypeMessage.saveSetting: - LocalStore.updateConfigSetting({ - server: arg.data - }); - const diFilesPath = getWebDirPath(); - clearDesktopConfig( - diFilesPath - ) - if (arg.isSetup) { + { LocalStore.updateConfigSetting({ - general: { - setup: true - } - }); - setupWindow?.close(); - eventEmitter.emit(EventLists.SERVER_WINDOW); - } else { - event.sender.send(IPC_TYPES.SETTING_PAGE, { - type: SettingPageTypeMessage.mainResponse, data: { - status: true, - isServerRun: isServerRun - } + server: arg.data }); + const diFilesPath = getWebDirPath(); + await clearDesktopConfig( + diFilesPath + ) + if (arg.isSetup) { + LocalStore.updateConfigSetting({ + general: { + setup: true + } + }); + setupWindow?.close(); + eventEmitter.emit(EventLists.SERVER_WINDOW); + } else { + event.sender.send(IPC_TYPES.SETTING_PAGE, { + type: SettingPageTypeMessage.mainResponse, data: { + status: true, + isServerRun: isServerRun + } + }); + } + break; } - break; - case SettingPageTypeMessage.checkUpdate: + case SettingPageTypeMessage.checkUpdate: updater.checkUpdate(); break; case SettingPageTypeMessage.installUpdate: @@ -540,7 +541,7 @@ ipcMain.on(IPC_TYPES.SETTING_PAGE, async (event, arg) => { LocalStore.updateConfigSetting({ general: { autoUpdate: arg.data.autoUpdate, - updateCheckPeriode: arg.data.updateCheckPeriode + updateCheckPeriod: arg.data.updateCheckPeriod } }) createIntervalAutoUpdate() @@ -581,8 +582,8 @@ const createIntervalAutoUpdate = () => { clearInterval(intervalUpdate) } const setting: WebServer = LocalStore.getStore('config'); - if (setting.general?.autoUpdate && setting.general.updateCheckPeriode) { - const checkIntervalSecond = parseInt(setting.general.updateCheckPeriode); + if (setting.general?.autoUpdate && setting.general.updateCheckPeriod) { + const checkIntervalSecond = parseInt(setting.general.updateCheckPeriod); if (!Number.isNaN(checkIntervalSecond)) { const intervalMS = checkIntervalSecond * 60 * 1000; intervalUpdate = setInterval(() => { diff --git a/apps/server-web/src/main/menu.ts b/apps/server-web/src/main/menu.ts index c374a32fe..e95f8f8ba 100644 --- a/apps/server-web/src/main/menu.ts +++ b/apps/server-web/src/main/menu.ts @@ -26,7 +26,6 @@ export default class MenuBuilder { { id: 'MENU_APP_ABOUT', label: `MENU_APP.APP_ABOUT`, - selector: 'orderFrontStandardAboutPanel:', click: () => { this.eventEmitter.emit(EventLists.gotoAbout) } diff --git a/apps/server-web/src/renderer/components/LanguageSelector.tsx b/apps/server-web/src/renderer/components/LanguageSelector.tsx index fb816f536..0cebc1a71 100644 --- a/apps/server-web/src/renderer/components/LanguageSelector.tsx +++ b/apps/server-web/src/renderer/components/LanguageSelector.tsx @@ -4,28 +4,28 @@ import { useState } from 'react'; import { ILanguages } from '../libs/interfaces'; import { SettingPageTypeMessage } from '../../main/helpers/constant'; +export const SUPPORTED_LANGUAGES: ILanguages[] = [ + { code: 'en', label: 'English' }, + { code: 'bg', label: 'Bulgarian' }, +]; + type LanguageSelector = { lang: string; }; const LanguageSelector = ({ lang }: LanguageSelector) => { - const [langs] = useState([ - { - code: 'en', - label: 'English', - }, - { - code: 'bg', - label: 'Bulgarian', - }, - ]); + const [langs] = useState(SUPPORTED_LANGUAGES); const { t } = useTranslation(); const changeLanguage = (data: ILanguages) => { - window.electron.ipcRenderer.sendMessage('setting-page', { - type: SettingPageTypeMessage.langChange, - data: data.code, - }); - setLng(data.code); + try { + window.electron.ipcRenderer.sendMessage('setting-page', { + type: SettingPageTypeMessage.langChange, + data: data.code, + }); + setLng(data.code); + } catch (error) { + console.error('Failed to change language:', error); + } }; const [lng, setLng] = useState(lang); diff --git a/apps/server-web/src/renderer/components/Updater.tsx b/apps/server-web/src/renderer/components/Updater.tsx index eb70dd816..5e5d110b4 100644 --- a/apps/server-web/src/renderer/components/Updater.tsx +++ b/apps/server-web/src/renderer/components/Updater.tsx @@ -70,11 +70,11 @@ export const UpdaterComponent = (props: IUpdaterComponent) => { const onSelectPeriode = (value: string) => { props.changeAutoUpdate({ autoUpdate: props.data.autoUpdate, - updateCheckPeriode: value, + updateCheckPeriod: value, }); props.saveSettingUpdate({ autoUpdate: props.data.autoUpdate, - updateCheckPeriode: value, + updateCheckPeriod: value, }); }; @@ -123,11 +123,11 @@ export const UpdaterComponent = (props: IUpdaterComponent) => { setOpen(); props.changeAutoUpdate({ autoUpdate: value, - updateCheckPeriode: props.data.updateCheckPeriode, + updateCheckPeriod: props.data.updateCheckPeriod, }); props.saveSettingUpdate({ autoUpdate: value, - updateCheckPeriode: props.data.updateCheckPeriode, + updateCheckPeriod: props.data.updateCheckPeriod, }); }} checked={props.data.autoUpdate} @@ -149,8 +149,8 @@ export const UpdaterComponent = (props: IUpdaterComponent) => { ...i, label: `FORM.LABELS.UPDATE_OPTIONS.${i.label}`, }))} - value={props.data.updateCheckPeriode} - defaultValue={props.data.updateCheckPeriode} + value={props.data.updateCheckPeriod} + defaultValue={props.data.updateCheckPeriod} disabled={!props.data.autoUpdate} onValueChange={onSelectPeriode} /> diff --git a/apps/server-web/src/renderer/libs/interfaces/i-setting.ts b/apps/server-web/src/renderer/libs/interfaces/i-setting.ts index e54d327a6..d061ed869 100644 --- a/apps/server-web/src/renderer/libs/interfaces/i-setting.ts +++ b/apps/server-web/src/renderer/libs/interfaces/i-setting.ts @@ -45,7 +45,7 @@ interface ILanguages { type IUpdateSetting = { autoUpdate: boolean; - updateCheckPeriode: string; + updateCheckPeriod: string; }; type IAbout = { diff --git a/apps/server-web/src/renderer/pages/Setting.tsx b/apps/server-web/src/renderer/pages/Setting.tsx index 477d0a84f..c938f2e6d 100644 --- a/apps/server-web/src/renderer/pages/Setting.tsx +++ b/apps/server-web/src/renderer/pages/Setting.tsx @@ -6,14 +6,12 @@ import { ServerComponent, UpdaterComponent, AboutComponent, - GeneralComponent, } from '../components'; import { IUpdaterStates, IUpdateSetting, IServerSetting, IPopup, - ILanguages, ISideMenu, } from '../libs/interfaces'; import { useTranslation } from 'react-i18next'; @@ -40,20 +38,9 @@ export function Setting() { const [updateSetting, setUpdateSetting] = useState({ autoUpdate: false, - updateCheckPeriode: '180', + updateCheckPeriod: '180', }); - const [langs, setLangs] = useState([ - { - code: 'en', - label: 'English', - }, - { - code: 'bg', - label: 'Bulgarian', - }, - ]); - const [lng, setLng] = useState('en'); const [updateStates, setUpdateState] = useState({ @@ -91,11 +78,6 @@ export function Setting() { setMenu(newMenu); }; - const changeLanguage = (lang: ILanguages) => { - sendingMessageToMain(lang.code, SettingPageTypeMessage.langChange); - setLng(lang.code); - }; - const saveSettingUpdate = (data: IUpdateSetting) => { sendingMessageToMain(data, SettingPageTypeMessage.updateSetting); }; @@ -202,12 +184,6 @@ export function Setting() { sendingMessageToMain({}, SettingPageTypeMessage.showVersion); return ; } - - if (activeMenu() === 'general') { - return ( - - ); - } return ; }; @@ -268,7 +244,7 @@ export function Setting() { setLng(arg.data.general.lang); setUpdateSetting({ autoUpdate: arg.data.general.autoUpdate, - updateCheckPeriode: arg.data.general.updateCheckPeriode, + updateCheckPeriod: arg.data.general.updateCheckPeriod, }); break; case SettingPageTypeMessage.mainResponse: diff --git a/apps/server-web/src/renderer/pages/setup/Landing.tsx b/apps/server-web/src/renderer/pages/setup/Landing.tsx index e0e8ad77f..072b6ee06 100644 --- a/apps/server-web/src/renderer/pages/setup/Landing.tsx +++ b/apps/server-web/src/renderer/pages/setup/Landing.tsx @@ -11,8 +11,13 @@ const Landing = (props: props) => { const [defaultLang, setDefaultLang] = useState('en'); const getCurrentLanguage = async () => { - const lang = await window.electron.ipcRenderer.invoke('current-language'); - setDefaultLang(lang); + try { + const lang = await window.electron.ipcRenderer.invoke('current-language'); + setDefaultLang(lang); + } catch (error) { + console.error('Failed to get current language:', error); + setDefaultLang('en'); // Fallback to English + } }; useEffect(() => { diff --git a/apps/web/app/constants.ts b/apps/web/app/constants.ts index c4f477e63..016df0a8b 100644 --- a/apps/web/app/constants.ts +++ b/apps/web/app/constants.ts @@ -1,6 +1,6 @@ import { JitsuOptions } from '@jitsu/jitsu-react/dist/useJitsu'; import { I_SMTPRequest } from './interfaces/ISmtp'; -import { getNextPublicEnv, getServerSideProps } from './env'; +import { getNextPublicEnv, getServerRuntimeConfig } from './env'; import enLanguage from '../locales/en.json'; import { BG, CN, DE, ES, FR, IS, IT, NL, PL, PT, RU, SA, US } from 'country-flag-icons/react/1x1'; import { ManualTimeReasons } from './interfaces/timer/IManualTimeReasons'; @@ -40,7 +40,7 @@ export const RECAPTCHA_SITE_KEY = getNextPublicEnv( export const RECAPTCHA_SECRET_KEY = process.env.CAPTCHA_SECRET_KEY; let basePath = process.env.GAUZY_API_SERVER_URL ? process.env.GAUZY_API_SERVER_URL : 'https://api.ever.team'; if (IS_DESKTOP_APP) { - const serverRuntimeConfig = getServerSideProps() + const serverRuntimeConfig = getServerRuntimeConfig() basePath = serverRuntimeConfig?.GAUZY_API_SERVER_URL || basePath; } diff --git a/apps/web/app/env.ts b/apps/web/app/env.ts index 187f7bfeb..983803f66 100644 --- a/apps/web/app/env.ts +++ b/apps/web/app/env.ts @@ -39,10 +39,9 @@ export function getNextPublicEnv>(name: string, optio }; } -export function getServerSideProps() { +export function getServerRuntimeConfig() { try { const { serverRuntimeConfig } = getConfig(); - return { GAUZY_API_SERVER_URL: serverRuntimeConfig.GAUZY_API_SERVER_URL, }; diff --git a/apps/web/app/interfaces/IRuntimeServerConfig.ts b/apps/web/app/interfaces/IRuntimeServerConfig.ts new file mode 100644 index 000000000..cff07e845 --- /dev/null +++ b/apps/web/app/interfaces/IRuntimeServerConfig.ts @@ -0,0 +1,5 @@ +export interface ServerRuntimeConfig { + GAUZY_API_SERVER_URL?: string; + NEXT_PUBLIC_GAUZY_API_SERVER_URL?: string; + [key: string]: any; +} diff --git a/apps/web/app/services/client/axios.ts b/apps/web/app/services/client/axios.ts index df61a233d..b1d4f20f2 100644 --- a/apps/web/app/services/client/axios.ts +++ b/apps/web/app/services/client/axios.ts @@ -107,7 +107,7 @@ async function apiConfig(config?: APIConfig) { if (IS_DESKTOP_APP) { // dynamic api host while on desktop mode const runtimeConfig = await desktopServerOverride(); - baseURL = runtimeConfig; + baseURL = runtimeConfig || GAUZY_API_BASE_SERVER_URL.value; } baseURL = baseURL ? `${baseURL}/api` : undefined; diff --git a/apps/web/app/services/server/requests/desktop-source.ts b/apps/web/app/services/server/requests/desktop-source.ts index 24eb4fb0e..92d5f2c09 100644 --- a/apps/web/app/services/server/requests/desktop-source.ts +++ b/apps/web/app/services/server/requests/desktop-source.ts @@ -1,11 +1,16 @@ import getConfig from 'next/config'; +import { ServerRuntimeConfig } from '@app/interfaces/IRuntimeServerConfig'; +import { GAUZY_API_SERVER_URL, GAUZY_API_BASE_SERVER_URL } from '@app/constants'; -export function getDesktopConfig() { +export function getDesktopConfig(): Partial { try { const { serverRuntimeConfig } = getConfig(); return serverRuntimeConfig; } catch (error) { console.log('skip get server runtime config'); - return {}; + return { + GAUZY_API_SERVER_URL, + NEXT_PUBLIC_GAUZY_API_SERVER_URL: GAUZY_API_BASE_SERVER_URL.value + }; } } diff --git a/package.json b/package.json index e1d99a5f5..3048c8ad2 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "config:server-web": "yarn run config:electron -- --environment=prod --desktop=server-web", "dev:server-web": "cross-env NODE_ENV=production yarn prepare:config:server-web && yarn build:web:desktop && yarn run prepare:server-web && yarn copy:build:web && yarn run start:server-web", "build:web:desktop": "yarn config:electron:web:build -- --type=constant && cross-env NEXT_BUILD_OUTPUT_TYPE=standalone NEXT_SHARP_PATH=/tmp/node_modules/sharp yarn build:web", - "copy:build:web": "pwd && cp -r apps/web/.next/standalone apps/server-web/release/app/dist && cp -r apps/web/.next/static apps/server-web/release/app/dist/standalone/apps/web/.next && cp -r apps/web/public apps/server-web/release/app/dist/standalone/apps/web/ && yarn config:electron:web:build -- --type=server", + "copy:build:web": "yarn ts-node .scripts/copy-web-build.ts && yarn config:electron:web:build -- --type=server", "start:server-web": "cd apps/server-web && yarn run start", "prepare:server-web": "cd apps/server-web && yarn run prepare:electron && yarn run build", "pack:server-web:mac": "cd apps/server-web && yarn run pack:mac",