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
3 changes: 2 additions & 1 deletion lib/teleterm/autoupdate/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *Service) GetClusterVersions(ctx context.Context, _ *api.GetClusterVersi
mu.Lock()
unreachableClusters = append(unreachableClusters, &api.UnreachableCluster{
ClusterUri: cluster.URI.String(),
ErrorMessage: err.Error(),
ErrorMessage: pingErr.Error(),
})
mu.Unlock()
return nil
Expand Down Expand Up @@ -147,6 +147,7 @@ func (s *Service) GetDownloadBaseUrl(_ context.Context, _ *api.GetDownloadBaseUr
func resolveBaseURL() (string, error) {
envBaseURL := os.Getenv(autoupdate.BaseURLEnvVar)
if envBaseURL != "" {
// TODO(gzdunek): Validate if it's correct URL.
return envBaseURL, nil
}

Expand Down
20 changes: 20 additions & 0 deletions web/packages/teleterm/src/mainProcess/fixtures/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,26 @@ export class MockMainProcessClient implements MainProcessClient {
async selectDirectoryForDesktopSession() {
return '';
}

supportsAppUpdates() {
return true;
}
async changeAppUpdatesManagingCluster() {}
async maybeRemoveAppUpdatesManagingCluster() {}
async checkForAppUpdates() {}
async downloadAppUpdate() {}
async cancelAppUpdateDownload() {}
async quitAndInstallAppUpdate() {}
subscribeToAppUpdateEvents(): {
cleanup: () => void;
} {
return { cleanup: () => undefined };
}
subscribeToOpenAppUpdateDialog(): {
cleanup: () => void;
} {
return { cleanup: () => undefined };
}
}

export const makeRuntimeSettings = (
Expand Down
43 changes: 43 additions & 0 deletions web/packages/teleterm/src/mainProcess/ipcSerializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Teleport
* Copyright (C) 2025 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export type SerializedError = {
name: string;
message: string;
stack?: string;
cause?: unknown;
};

/** Serializes an Error into a plain object for transport through Electron IPC. */
export function serializeError(error: Error): SerializedError {
return {
name: error.name,
message: error.message,
cause: error.cause,
stack: error.stack,
};
}

/** Deserializes a plain object back into an Error instance. */
export function deserializeError(serialized: SerializedError): Error {
const error = new Error(serialized.message);
error.name = serialized.name;
error.cause = serialized.cause;
error.stack = serialized.stack;
return error;
}
76 changes: 73 additions & 3 deletions web/packages/teleterm/src/mainProcess/mainProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import {
removeAgentDirectory,
type CreateAgentConfigFileArgs,
} from './createAgentConfigFile';
import { serializeError } from './ipcSerializer';
import { ResolveError, resolveNetworkAddress } from './resolveNetworkAddress';
import { terminateWithTimeout } from './terminateWithTimeout';
import { WindowsManager } from './windowsManager';
Expand Down Expand Up @@ -161,7 +162,15 @@ export default class MainProcess {
this.appUpdater = new AppUpdater(
makeAppUpdaterStorage(this.appStateFileStorage),
getClusterVersions,
getDownloadBaseUrl
getDownloadBaseUrl,
event => {
if (event.kind === 'error') {
event.error = serializeError(event.error);
}
this.windowsManager
.getWindow()
.webContents.send(RendererIpc.AppUpdateEvent, event);
}
);
}

Expand All @@ -180,8 +189,8 @@ export default class MainProcess {

async dispose(): Promise<void> {
this.windowsManager.dispose();
this.appUpdater.dispose();
await Promise.all([
this.appUpdater.dispose(),
// sending usage events on tshd shutdown has 10-seconds timeout
terminateWithTimeout(this.tshdProcess, 10_000, () => {
this.gracefullyKillTshdProcess();
Expand Down Expand Up @@ -639,6 +648,46 @@ export default class MainProcess {
}
);

ipcMain.on(MainProcessIpc.SupportsAppUpdates, event => {
event.returnValue = this.appUpdater.supportsUpdates();
});

ipcMain.handle(MainProcessIpc.CheckForAppUpdates, () =>
this.appUpdater.checkForUpdates()
);

ipcMain.handle(
MainProcessIpc.ChangeAppUpdatesManagingCluster,
(
event,
args: {
clusterUri: RootClusterUri | undefined;
}
) => this.appUpdater.changeManagingCluster(args.clusterUri)
);

ipcMain.handle(
MainProcessIpc.MaybeRemoveAppUpdatesManagingCluster,
(
event,
args: {
clusterUri: RootClusterUri;
}
) => this.appUpdater.maybeRemoveManagingCluster(args.clusterUri)
);

ipcMain.handle(MainProcessIpc.DownloadAppUpdate, () =>
this.appUpdater.download()
);

ipcMain.handle(MainProcessIpc.CancelAppUpdateDownload, () =>
this.appUpdater.cancelDownload()
);

ipcMain.handle(MainProcessIpc.QuiteAndInstallAppUpdate, () =>
this.appUpdater.quitAndInstall()
);

subscribeToTerminalContextMenuEvent(this.configService);
subscribeToTabContextMenuEvent(
this.settings.availableShells,
Expand Down Expand Up @@ -673,7 +722,28 @@ export default class MainProcess {
};

const macTemplate: MenuItemConstructorOptions[] = [
{ role: 'appMenu' },
{
role: 'appMenu',
submenu: [
{ role: 'about' },
{
label: 'Check for Updates…',
click: () => {
this.windowsManager
.getWindow()
.webContents.send(RendererIpc.OpenAppUpdateDialog);
},
},
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' },
],
},
{ role: 'editMenu' },
viewMenuTemplate,
{
Expand Down
54 changes: 54 additions & 0 deletions web/packages/teleterm/src/mainProcess/mainProcessClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import { ipcRenderer } from 'electron';

import { CreateAgentConfigFileArgs } from 'teleterm/mainProcess/createAgentConfigFile';
import { AppUpdateEvent } from 'teleterm/services/appUpdater';
import { createFileStorageClient } from 'teleterm/services/fileStorage';
import { RootClusterUri } from 'teleterm/ui/uri';

import { createConfigServiceClient } from '../services/config';
import { openTabContextMenu } from './contextMenus/tabContextMenu';
import { openTerminalContextMenu } from './contextMenus/terminalContextMenu';
import { deserializeError } from './ipcSerializer';
import {
AgentProcessState,
ChildProcessAddresses,
Expand Down Expand Up @@ -199,5 +201,57 @@ export default function createMainProcessClient(): MainProcessClient {
args
);
},
supportsAppUpdates() {
return ipcRenderer.sendSync(MainProcessIpc.SupportsAppUpdates);
},
checkForAppUpdates() {
return ipcRenderer.invoke(MainProcessIpc.CheckForAppUpdates);
},
downloadAppUpdate() {
return ipcRenderer.invoke(MainProcessIpc.DownloadAppUpdate);
},
cancelAppUpdateDownload() {
return ipcRenderer.invoke(MainProcessIpc.CancelAppUpdateDownload);
},
quitAndInstallAppUpdate() {
return ipcRenderer.invoke(MainProcessIpc.QuiteAndInstallAppUpdate);
},
changeAppUpdatesManagingCluster(clusterUri) {
Comment thread
gzdunek marked this conversation as resolved.
return ipcRenderer.invoke(
MainProcessIpc.ChangeAppUpdatesManagingCluster,
{
clusterUri,
}
);
},
maybeRemoveAppUpdatesManagingCluster(clusterUri) {
return ipcRenderer.invoke(
MainProcessIpc.MaybeRemoveAppUpdatesManagingCluster,
{
clusterUri,
}
);
},
subscribeToAppUpdateEvents: listener => {
const ipcListener = (_, updateEvent: AppUpdateEvent) => {
if (updateEvent.kind === 'error') {
updateEvent.error = deserializeError(updateEvent.error);
}
listener(updateEvent);
};

ipcRenderer.addListener(RendererIpc.AppUpdateEvent, ipcListener);
return {
cleanup: () =>
ipcRenderer.removeListener(RendererIpc.AppUpdateEvent, ipcListener),
};
},
subscribeToOpenAppUpdateDialog: listener => {
ipcRenderer.addListener(RendererIpc.OpenAppUpdateDialog, listener);
return {
cleanup: () =>
ipcRenderer.removeListener(RendererIpc.OpenAppUpdateDialog, listener),
};
},
};
}
27 changes: 27 additions & 0 deletions web/packages/teleterm/src/mainProcess/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import { DeepLinkParseResult } from 'teleterm/deepLinks';
import { CreateAgentConfigFileArgs } from 'teleterm/mainProcess/createAgentConfigFile';
import { AppUpdateEvent } from 'teleterm/services/appUpdater';
import { FileStorage } from 'teleterm/services/fileStorage';
import { Document } from 'teleterm/ui/services/workspacesService';
import { RootClusterUri } from 'teleterm/ui/uri';
Expand Down Expand Up @@ -206,6 +207,23 @@ export type MainProcessClient = {
desktopUri: string;
login: string;
}): Promise<string>;
changeAppUpdatesManagingCluster(
clusterUri: RootClusterUri | undefined
): Promise<void>;
maybeRemoveAppUpdatesManagingCluster(
clusterUri: RootClusterUri
): Promise<void>;
supportsAppUpdates(): boolean;
checkForAppUpdates(): Promise<void>;
downloadAppUpdate(): Promise<void>;
cancelAppUpdateDownload(): Promise<void>;
quitAndInstallAppUpdate(): Promise<void>;
subscribeToAppUpdateEvents(listener: (args: AppUpdateEvent) => void): {
cleanup: () => void;
};
subscribeToOpenAppUpdateDialog(listener: () => void): {
cleanup: () => void;
};
};

export type ChildProcessAddresses = {
Expand Down Expand Up @@ -311,6 +329,8 @@ export enum RendererIpc {
NativeThemeUpdate = 'renderer-native-theme-update',
ConnectMyComputerAgentUpdate = 'renderer-connect-my-computer-agent-update',
DeepLinkLaunch = 'renderer-deep-link-launch',
OpenAppUpdateDialog = 'renderer-open-app-update-dialog',
AppUpdateEvent = 'renderer-app-update-event',
}

export enum MainProcessIpc {
Expand All @@ -322,6 +342,13 @@ export enum MainProcessIpc {
SaveTextToFile = 'main-process-save-text-to-file',
ForceFocusWindow = 'main-process-force-focus-window',
SelectDirectoryForDesktopSession = 'main-process-select-directory-for-desktop-session',
CheckForAppUpdates = 'main-process-check-for-app-updates',
DownloadAppUpdate = 'main-process-download-app-update',
CancelAppUpdateDownload = 'main-process-cancel-app-update-download',
QuiteAndInstallAppUpdate = 'main-process-quit-and-install-app-update',
ChangeAppUpdatesManagingCluster = 'main-process-change-app-updates-managing-cluster',
MaybeRemoveAppUpdatesManagingCluster = 'main-process-maybe-remove-app-updates-managing-cluster',
SupportsAppUpdates = 'main-process-supports-app-updates',
}

export enum WindowsManagerIpc {
Expand Down
Loading
Loading