mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-11 22:49:54 +00:00
Set up deep links as soon as possible (#61668)
This commit is contained in:
@@ -71,7 +71,15 @@ async function initializeApp(): Promise<void> {
|
||||
updateSessionDataPath();
|
||||
const settings = await getRuntimeSettings();
|
||||
const logger = initMainLogger(settings);
|
||||
|
||||
process.on('uncaughtException', (error, origin) => {
|
||||
logger.error('Uncaught exception', origin, error);
|
||||
showDialogWithError(`Uncaught exception (${origin} origin)`, error);
|
||||
app.exit(1);
|
||||
});
|
||||
|
||||
logger.info(`Starting ${app.getName()} version ${app.getVersion()}`);
|
||||
|
||||
const {
|
||||
appStateFileStorage,
|
||||
configFileStorage,
|
||||
@@ -84,6 +92,36 @@ async function initializeApp(): Promise<void> {
|
||||
settings,
|
||||
});
|
||||
|
||||
nativeTheme.themeSource = configService.get('theme').value;
|
||||
const windowsManager = new WindowsManager(
|
||||
appStateFileStorage,
|
||||
settings,
|
||||
configService
|
||||
);
|
||||
|
||||
// On Windows/Linux: Re-launching the app while it's already running
|
||||
// triggers 'second-instance' (because of app.requestSingleInstanceLock()).
|
||||
//
|
||||
// On macOS: Re-launching the app (from places like Finder, Spotlight, or Dock)
|
||||
// does not trigger 'second-instance'. Instead, the system emits 'activate'.
|
||||
// However, launching the app outside the desktop manager (e.g., from the command
|
||||
// line) does trigger 'second-instance'.
|
||||
app.on('second-instance', () => {
|
||||
windowsManager.focusWindow();
|
||||
});
|
||||
app.on('activate', () => {
|
||||
windowsManager.focusWindow();
|
||||
});
|
||||
|
||||
// Since setUpDeepLinks adds another listener for second-instance, it's important to call it after
|
||||
// the listener which calls windowsManager.focusWindow. This way the focus will be brought to the
|
||||
// window before processing the listener for deep links.
|
||||
//
|
||||
// This must be called as early as possible, before an async code.
|
||||
// Otherwise, if the app is launched via a macOS deep link, the 'open-url' event may be emitted
|
||||
// before a handler is registered, causing the link to be lost.
|
||||
setUpDeepLinks(logger, windowsManager, settings);
|
||||
|
||||
const tshHome = configService.get('tshHome').value;
|
||||
// Ensure the tsh directory exist.
|
||||
await fs.mkdir(tshHome, {
|
||||
@@ -95,19 +133,6 @@ async function initializeApp(): Promise<void> {
|
||||
// and address the TODO in teleport-connect.mdx > ##Troubleshooting.
|
||||
await migrateOldTshHomeOnce(logger, tshHome, appStateFileStorage);
|
||||
|
||||
nativeTheme.themeSource = configService.get('theme').value;
|
||||
const windowsManager = new WindowsManager(
|
||||
appStateFileStorage,
|
||||
settings,
|
||||
configService
|
||||
);
|
||||
|
||||
process.on('uncaughtException', (error, origin) => {
|
||||
logger.error('Uncaught exception', origin, error);
|
||||
showDialogWithError(`Uncaught exception (${origin} origin)`, error);
|
||||
app.exit(1);
|
||||
});
|
||||
|
||||
let mainProcess: MainProcess;
|
||||
try {
|
||||
mainProcess = new MainProcess({
|
||||
@@ -142,24 +167,14 @@ async function initializeApp(): Promise<void> {
|
||||
app.exit();
|
||||
});
|
||||
|
||||
// On Windows/Linux: Re-launching the app while it's already running
|
||||
// triggers 'second-instance' (because of app.requestSingleInstanceLock()).
|
||||
//
|
||||
// On macOS: Re-launching the app (from places like Finder, Spotlight, or Dock)
|
||||
// does not trigger 'second-instance'. Instead, the system emits 'activate'.
|
||||
// However, launching the app outside the desktop manager (e.g., from the command
|
||||
// line) does trigger 'second-instance'.
|
||||
app.on('second-instance', () => {
|
||||
windowsManager.focusWindow();
|
||||
app.on('web-contents-created', (_, webContents) => {
|
||||
registerNavigationHandlers(
|
||||
webContents,
|
||||
settings,
|
||||
mainProcess.clusterStore,
|
||||
logger
|
||||
);
|
||||
});
|
||||
app.on('activate', () => {
|
||||
windowsManager.focusWindow();
|
||||
});
|
||||
|
||||
// Since setUpDeepLinks adds another listener for second-instance, it's important to call it after
|
||||
// the listener which calls windowsManager.focusWindow. This way the focus will be brought to the
|
||||
// window before processing the listener for deep links.
|
||||
setUpDeepLinks(logger, windowsManager, settings);
|
||||
|
||||
app
|
||||
.whenReady()
|
||||
@@ -178,15 +193,6 @@ async function initializeApp(): Promise<void> {
|
||||
showDialogWithError(message, error);
|
||||
app.exit(1);
|
||||
});
|
||||
|
||||
app.on('web-contents-created', (_, webContents) => {
|
||||
registerNavigationHandlers(
|
||||
webContents,
|
||||
settings,
|
||||
mainProcess.clusterStore,
|
||||
logger
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user