2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2020-11-13 15:20:26 -05:00
|
|
|
import Controller from '@ember/controller';
|
2025-03-12 08:29:54 -07:00
|
|
|
import { service } from '@ember/service';
|
2024-08-06 12:21:44 -07:00
|
|
|
import { getOwner } from '@ember/application';
|
2024-09-17 16:36:47 -07:00
|
|
|
import { action } from '@ember/object';
|
2025-08-04 16:44:27 -04:00
|
|
|
import { tracked } from '@glimmer/tracking';
|
|
|
|
|
|
2020-11-13 15:20:26 -05:00
|
|
|
export default class ApplicationController extends Controller {
|
|
|
|
|
// =services
|
|
|
|
|
|
2024-09-17 16:36:47 -07:00
|
|
|
@service clusterUrl;
|
2022-08-31 10:24:25 -07:00
|
|
|
@service flashMessages;
|
2025-08-04 16:44:27 -04:00
|
|
|
@service ipc;
|
|
|
|
|
@service session;
|
|
|
|
|
@service('browser/window') window;
|
|
|
|
|
|
2025-10-30 12:49:30 -07:00
|
|
|
// =attributes
|
|
|
|
|
|
2025-08-04 16:44:27 -04:00
|
|
|
@tracked isLoggingOut = false;
|
|
|
|
|
@tracked isAppQuitting = false;
|
|
|
|
|
|
|
|
|
|
removeOnAppQuitListener;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
super(...arguments);
|
|
|
|
|
// Listen for when user attempts to quit app
|
|
|
|
|
// Setup removeOnAppQuitListener to destroy the listener afterwards
|
|
|
|
|
this.removeOnAppQuitListener = this.window.electron?.onAppQuit(() => {
|
|
|
|
|
this.isAppQuitting = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-09-17 16:36:47 -07:00
|
|
|
|
|
|
|
|
// =actions
|
|
|
|
|
|
|
|
|
|
/**
|
2025-08-04 16:44:27 -04:00
|
|
|
* Stop all active/pending target sessions
|
|
|
|
|
* Logout or close app
|
2024-09-17 16:36:47 -07:00
|
|
|
*/
|
|
|
|
|
@action
|
2025-08-04 16:44:27 -04:00
|
|
|
async confirmCloseSessions() {
|
|
|
|
|
await this.ipc.invoke('stopAll');
|
|
|
|
|
if (this.isAppQuitting) {
|
|
|
|
|
this.isAppQuitting = false;
|
|
|
|
|
this.close();
|
|
|
|
|
} else {
|
|
|
|
|
// this.session.invalidate() comes from Ember Simple Auth BaseSessionService
|
|
|
|
|
this.session.invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.isLoggingOut = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Only renders the signout modal if target sessions are running
|
|
|
|
|
*/
|
|
|
|
|
@action
|
|
|
|
|
async showModalOrLogout() {
|
|
|
|
|
const hasRunningSessions = await this.ipc.invoke('hasRunningSessions');
|
|
|
|
|
if (hasRunningSessions) {
|
|
|
|
|
this.isLoggingOut = true;
|
|
|
|
|
} else {
|
|
|
|
|
this.session.invalidate();
|
|
|
|
|
}
|
2024-09-17 16:36:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Disconnects from clusterUrl and invalidates session, thereby resetting
|
|
|
|
|
* the client and reloading to the onboarding clusterUrl screen.
|
|
|
|
|
*/
|
|
|
|
|
@action
|
|
|
|
|
disconnect() {
|
|
|
|
|
this.clusterUrl.resetClusterUrl();
|
2025-08-04 16:44:27 -04:00
|
|
|
this.session.invalidate();
|
2024-09-17 16:36:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
minimize() {
|
|
|
|
|
this.ipc.invoke('minimizeWindow');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
toggleFullScreen() {
|
|
|
|
|
this.ipc.invoke('toggleFullscreenWindow');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
close() {
|
|
|
|
|
this.ipc.invoke('closeWindow');
|
|
|
|
|
}
|
2024-08-06 12:21:44 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Applies the specified color theme to the root ember element.
|
|
|
|
|
* @param {string} theme - "light", "dark", or nullish (system default)
|
|
|
|
|
*/
|
|
|
|
|
@action
|
|
|
|
|
toggleTheme(theme) {
|
|
|
|
|
const rootElementSelector = getOwner(this).rootElement;
|
|
|
|
|
const rootEl = getOwner(this)
|
|
|
|
|
.lookup('service:-document')
|
|
|
|
|
.querySelector(rootElementSelector);
|
|
|
|
|
this.session.set('data.theme', theme);
|
|
|
|
|
switch (theme) {
|
|
|
|
|
case 'light':
|
|
|
|
|
rootEl.classList.add('rose-theme-light');
|
|
|
|
|
rootEl.classList.remove('rose-theme-dark');
|
|
|
|
|
break;
|
|
|
|
|
case 'dark':
|
|
|
|
|
rootEl.classList.add('rose-theme-dark');
|
|
|
|
|
rootEl.classList.remove('rose-theme-light');
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
rootEl.classList.remove('rose-theme-dark');
|
|
|
|
|
rootEl.classList.remove('rose-theme-light');
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-04 16:44:27 -04:00
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
cancel() {
|
|
|
|
|
this.isLoggingOut = false;
|
|
|
|
|
this.isAppQuitting = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
willDestroy() {
|
|
|
|
|
super.willDestroy(...arguments);
|
|
|
|
|
this.removeOnAppQuitListener?.();
|
|
|
|
|
}
|
2020-11-13 15:20:26 -05:00
|
|
|
}
|