summaryrefslogtreecommitdiffhomepage
path: root/gui/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src/main')
-rw-r--r--gui/src/main/changelog.ts65
-rw-r--r--gui/src/main/gui-settings.ts14
-rw-r--r--gui/src/main/index.ts11
3 files changed, 88 insertions, 2 deletions
diff --git a/gui/src/main/changelog.ts b/gui/src/main/changelog.ts
new file mode 100644
index 0000000000..4c169b055b
--- /dev/null
+++ b/gui/src/main/changelog.ts
@@ -0,0 +1,65 @@
+import fs from 'fs';
+import path from 'path';
+import { IChangelog } from '../shared/ipc-types';
+import log from '../shared/logging';
+
+// Reads and parses the changelog file.
+export function readChangelog(): IChangelog {
+ try {
+ const changelogPath = path.join(__dirname, '..', '..', '..', 'changelog.txt');
+ const contents = fs.readFileSync(changelogPath).toString();
+ return parseChangelog(contents);
+ } catch (e) {
+ const error = e as Error;
+ log.error('Failed to read changelog.txt', error.message);
+ return [];
+ }
+}
+
+// Parses the contents of the changelog file and returns all relevant items.
+export function parseChangelog(changelog: string): IChangelog {
+ const items = changelog
+ .split('\n')
+ .map((item) => item.trim())
+ .filter((item) => item !== '');
+ return filterForPlatform(items);
+}
+
+// Filters the changelog items based on platform
+function filterForPlatform(items: Array<string>): IChangelog {
+ return items
+ .map((item) => {
+ // Extracts the platforms from from the string if there are any specified. Platforms are
+ // specified within brackets with separated with a comma.
+ const platforms = item
+ .match(/^\[.*?\]/)
+ ?.flatMap((match) => match.slice(1, -1).split(','))
+ .map((platform) => platform.trim());
+ if (!platforms || isPlatform(platforms)) {
+ // If there are no platforms specified or if the current platform matches one of the
+ // specified, then the item is included.
+ return item.replace(/^\[.*?\]/, '').trim();
+ } else {
+ return undefined;
+ }
+ })
+ .filter((item): item is string => item !== undefined);
+}
+
+// Checks if an OS name corresponds to the current platform.
+function isPlatform(platformNames: Array<string>): boolean {
+ const platforms = platformNames.map((platformName) => {
+ switch (platformName.toLowerCase()) {
+ case 'windows':
+ return 'win32';
+ case 'macos':
+ return 'darwin';
+ case 'linux':
+ return 'linux';
+ default:
+ return platformName;
+ }
+ });
+
+ return platforms.includes(process.platform);
+}
diff --git a/gui/src/main/gui-settings.ts b/gui/src/main/gui-settings.ts
index d5432e2321..73c546a24b 100644
--- a/gui/src/main/gui-settings.ts
+++ b/gui/src/main/gui-settings.ts
@@ -4,7 +4,7 @@ import * as path from 'path';
import { IGuiSettingsState, SYSTEM_PREFERRED_LOCALE_KEY } from '../shared/gui-settings-state';
import log from '../shared/logging';
-const settingsSchema = {
+const settingsSchema: Record<keyof IGuiSettingsState, string> = {
preferredLocale: 'string',
autoConnect: 'boolean',
enableSystemNotifications: 'boolean',
@@ -12,6 +12,7 @@ const settingsSchema = {
startMinimized: 'boolean',
unpinnedWindow: 'boolean',
browsedForSplitTunnelingApplications: 'Array<string>',
+ changelogDisplayedForVersion: 'string',
};
const defaultSettings: IGuiSettingsState = {
@@ -22,6 +23,7 @@ const defaultSettings: IGuiSettingsState = {
startMinimized: false,
unpinnedWindow: process.platform !== 'win32' && process.platform !== 'darwin',
browsedForSplitTunnelingApplications: [],
+ changelogDisplayedForVersion: '',
};
export default class GuiSettings {
@@ -92,6 +94,16 @@ export default class GuiSettings {
return this.stateValue.browsedForSplitTunnelingApplications;
}
+ set changelogDisplayedForVersion(newValue: string | undefined) {
+ this.changeStateAndNotify({ ...this.stateValue, changelogDisplayedForVersion: newValue ?? '' });
+ }
+
+ get changelogDisplayedForVersion(): string | undefined {
+ return this.stateValue.changelogDisplayedForVersion === ''
+ ? undefined
+ : this.stateValue.changelogDisplayedForVersion;
+ }
+
public load() {
try {
const settingsFile = this.filePath();
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index f6567e47ad..a9daa98367 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -41,8 +41,9 @@ import { messages, relayLocations } from '../shared/gettext';
import { SYSTEM_PREFERRED_LOCALE_KEY } from '../shared/gui-settings-state';
import log, { ConsoleOutput, Logger } from '../shared/logging';
import { LogLevel } from '../shared/logging-types';
+import { readChangelog } from './changelog';
import { IpcMainEventChannel } from './ipc-event-channel';
-import { ICurrentAppVersionInfo } from '../shared/ipc-types';
+import { IChangelog, ICurrentAppVersionInfo } from '../shared/ipc-types';
import {
AccountExpiredNotificationProvider,
CloseToAccountExpiryNotificationProvider,
@@ -260,6 +261,8 @@ class ApplicationMain {
private quitWithoutDisconnect = false;
+ private changelog?: IChangelog;
+
public run() {
// Remove window animations to combat window flickering when opening window. Can be removed when
// this issue has been resolved: https://github.com/electron/electron/issues/12130
@@ -301,6 +304,7 @@ class ApplicationMain {
}
this.guiSettings.load();
+ this.changelog = readChangelog();
app.on('render-process-gone', (_event, _webContents, details) => {
log.error(
@@ -1228,6 +1232,7 @@ class ApplicationMain {
translations: this.translations,
windowsSplitTunnelingApplications: this.windowsSplitTunnelingApplications,
macOsScrollbarVisibility: this.macOsScrollbarVisibility,
+ changelog: this.changelog ?? [],
}));
IpcMainEventChannel.settings.handleSetAllowLan((allowLan: boolean) =>
@@ -1461,6 +1466,10 @@ class ApplicationMain {
return response;
});
+ IpcMainEventChannel.currentVersion.handleDisplayedChangelog(() => {
+ this.guiSettings.changelogDisplayedForVersion = this.currentVersion.gui;
+ });
+
if (windowsSplitTunneling) {
this.guiSettings.browsedForSplitTunnelingApplications.forEach(
windowsSplitTunneling.addApplicationPathToCache,