Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions desktop/src/__test__/main/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,13 @@ describe('Settings', () => {
})

describe('setServerUrl', () => {
test('write than read', () => {
const expectedUrl = 'https://new.server.com'

systemUnderTest.setServerUrl(expectedUrl)
const expectedUrl = 'https://new.server.com'
test.each([
{ serverUrl: 'https://new.server.com' },
{ serverUrl: 'https://new.server.com/' },
{ serverUrl: 'https://new.server.com//' }
])('write $serverUrl than read', ({ serverUrl }) => {
systemUnderTest.setServerUrl(serverUrl)

expect(systemUnderTest.readServerUrl()).toBe(expectedUrl)
})
Expand Down
35 changes: 25 additions & 10 deletions desktop/src/main/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,9 @@ export class Settings {
}

readServerUrl (): string {
if (this.isDev) {
return process.env.FRONT_URL ?? 'http://huly.local:8087'
}
return (
(this.store as any).get(Settings.SETTINGS_KEY_SERVER) as string ??
this.packedConfig?.server ??
process.env.FRONT_URL ??
'https://huly.app'
)
const url = this.extractUrl()
// Motivation: fix existing Huly installations (saved on disk URLs).
return Settings.sanitizeUrl(url)
}

isMinimizeToTrayEnabled (): boolean {
Expand All @@ -52,7 +46,8 @@ export class Settings {
}

setServerUrl (serverUrl: string): void {
(this.store as any).set(Settings.SETTINGS_KEY_SERVER, serverUrl)
const sanitizedUrl: string = Settings.sanitizeUrl(serverUrl)
;(this.store as any).set(Settings.SETTINGS_KEY_SERVER, sanitizedUrl)
}

getWindowBounds (): any {
Expand All @@ -62,4 +57,24 @@ export class Settings {
setWindowBounds (bounds: any): void {
(this.store as any).set(Settings.SETTINGS_KEY_WINDOW_BOUNDS, bounds)
}

private extractUrl (): string {
if (this.isDev) {
return process.env.FRONT_URL ?? 'http://huly.local:8087'
}
return (
(this.store as any).get(Settings.SETTINGS_KEY_SERVER) as string ??
this.packedConfig?.server ??
process.env.FRONT_URL ??
'https://huly.app'
)
}

private static sanitizeUrl (serverUrl: string): string {
let cleanUrl: string = serverUrl
while (cleanUrl.endsWith('/')) {
cleanUrl = cleanUrl.slice(0, -1)
}
return cleanUrl
}
}
Loading