-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle dynamic gauzy api host from desktop config
- Loading branch information
1 parent
b80062b
commit 6296acf
Showing
17 changed files
with
268 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { hideBin } from 'yargs/helpers'; | ||
import yargs from 'yargs'; | ||
|
||
const argv: any = yargs(hideBin(process.argv)).argv; | ||
|
||
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.`); | ||
} | ||
} | ||
|
||
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() { | ||
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'); | ||
} | ||
|
||
|
||
if (argv.type === 'server') { | ||
modifiedNextServer(); | ||
revertWebConstant(); | ||
} else if (argv.type === 'constant') { | ||
modifiedWebConstant(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export type Channels = 'setting-page' | 'ipc-renderer' | 'language-set' | 'updater-page' | 'server-page' | 'theme-change' | 'current-theme'; | ||
export type Channels = 'setting-page' | 'ipc-renderer' | 'language-set' | 'updater-page' | 'server-page' | 'theme-change' | 'current-theme' | 'current-language'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
apps/server-web/src/renderer/components/LanguageSelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { SelectComponent } from './Select'; | ||
import { useState } from 'react'; | ||
import { ILanguages } from '../libs/interfaces'; | ||
import { SettingPageTypeMessage } from '../../main/helpers/constant'; | ||
|
||
type LanguageSelector = { | ||
lang: string; | ||
}; | ||
const LanguageSelector = ({ lang }: LanguageSelector) => { | ||
const [langs] = useState<ILanguages[]>([ | ||
{ | ||
code: 'en', | ||
label: 'English', | ||
}, | ||
{ | ||
code: 'bg', | ||
label: 'Bulgarian', | ||
}, | ||
]); | ||
const { t } = useTranslation(); | ||
|
||
const changeLanguage = (data: ILanguages) => { | ||
window.electron.ipcRenderer.sendMessage('setting-page', { | ||
type: SettingPageTypeMessage.langChange, | ||
data: data.code, | ||
}); | ||
setLng(data.code); | ||
}; | ||
|
||
const [lng, setLng] = useState<string>(lang); | ||
|
||
const language = langs.find((lg) => lg.code === lng) || { | ||
code: 'en', | ||
label: 'English', | ||
}; | ||
return ( | ||
<SelectComponent | ||
items={langs.map((i) => ({ | ||
value: i.code, | ||
label: `LANGUAGES.${i.code}`, | ||
}))} | ||
title={t('FORM.LABELS.LANGUAGES')} | ||
defaultValue={language.code} | ||
onValueChange={(val) => { | ||
changeLanguage({ code: val }); | ||
}} | ||
disabled={false} | ||
value={language.code} | ||
/> | ||
); | ||
}; | ||
|
||
export default LanguageSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.