From c9147255369031d79a916ad112494dc19100c17b Mon Sep 17 00:00:00 2001 From: "Philippe Ka." Date: Mon, 15 Apr 2024 11:11:54 +0200 Subject: [PATCH] Fix: ServersSidebar feedbacks issues --- src/main/menus/app.ts | 4 ++-- src/main/tokenManager.ts | 4 ++++ src/main/views/MattermostBrowserView.ts | 12 +++++++++++- src/main/views/loadingScreen.ts | 9 +++++++++ src/main/views/serversSidebar.ts | 1 + src/main/views/viewManager.ts | 9 ++++++--- src/renderer/css/components/ServersSidebar.scss | 8 ++++---- 7 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/main/menus/app.ts b/src/main/menus/app.ts index d21fbee0..3938fad7 100644 --- a/src/main/menus/app.ts +++ b/src/main/menus/app.ts @@ -170,7 +170,7 @@ export function createTemplate(config: Config, updateManager: UpdateManager) { label: localizeMessage('main.menus.app.view.reload', 'Reload'), accelerator: 'CmdOrCtrl+R', click() { - ViewManager.reload(); + ViewManager.reload(!TokenManager.hasToken()); }, }, { label: localizeMessage('main.menus.app.view.clearCacheAndReload', 'Clear Cache and Reload'), @@ -179,7 +179,7 @@ export function createTemplate(config: Config, updateManager: UpdateManager) { session.defaultSession.clearCache(); session.defaultSession.clearStorageData(); TokenManager.reset(); - ViewManager.reload(); + ViewManager.reload(true); }, }, { role: 'togglefullscreen', diff --git a/src/main/tokenManager.ts b/src/main/tokenManager.ts index 1e8df1dd..8fffbc09 100644 --- a/src/main/tokenManager.ts +++ b/src/main/tokenManager.ts @@ -100,6 +100,10 @@ export class TokenManager { return this.data; } + hasToken = () => { + return Boolean(this.data.token); + } + // Store token from api response and write to disk. handleStoreToken = (_: IpcMainEvent, message: Token) => { this.data = { diff --git a/src/main/views/MattermostBrowserView.ts b/src/main/views/MattermostBrowserView.ts index 02fbcd3e..dbba78fd 100644 --- a/src/main/views/MattermostBrowserView.ts +++ b/src/main/views/MattermostBrowserView.ts @@ -32,6 +32,7 @@ import ContextMenu from '../contextMenu'; import {getWindowBoundaries, getLocalPreload, composeUserAgent, shouldHaveBackBar} from '../utils'; import WebContentsEventManager from './webContentEvents'; +import LoadingScreen from './loadingScreen'; enum Status { LOADING, @@ -58,6 +59,7 @@ export class MattermostBrowserView extends EventEmitter { private retryLoad?: NodeJS.Timeout; private maxRetries: number; private altPressStatus: boolean; + private isReloading: boolean constructor(view: MattermostView, options: BrowserViewConstructorOptions) { super(); @@ -76,6 +78,7 @@ export class MattermostBrowserView extends EventEmitter { this.isVisible = false; this.loggedIn = false; this.atRoot = true; + this.isReloading = false; this.browserView = new BrowserView(this.options); this.resetLoadingStatus(); @@ -237,9 +240,10 @@ export class MattermostBrowserView extends EventEmitter { } } - reload = () => { + reload = (force = false) => { this.resetLoadingStatus(); AppState.updateExpired(this.id, false); + this.isReloading = !force; this.load(); } @@ -484,6 +488,12 @@ export class MattermostBrowserView extends EventEmitter { this.removeLoading = setTimeout(this.setInitialized, MAX_LOADING_SCREEN_SECONDS, true); this.emit(LOAD_SUCCESS, this.id, loadURL); const mainWindow = MainWindow.get(); + + if (this.isReloading) { + LoadingScreen.hide(); + this.isReloading = false; + } + if (mainWindow && this.currentURL) { this.setBounds(getWindowBoundaries(mainWindow, shouldHaveBackBar(this.view.url || '', this.currentURL))); } diff --git a/src/main/views/loadingScreen.ts b/src/main/views/loadingScreen.ts index 16c10fb5..ffc8673e 100644 --- a/src/main/views/loadingScreen.ts +++ b/src/main/views/loadingScreen.ts @@ -77,6 +77,15 @@ export class LoadingScreen { } } + hide = () => { + if (this.view && this.state === LoadingScreenState.VISIBLE) { + this.state = LoadingScreenState.FADING; + this.view.webContents.send(TOGGLE_LOADING_SCREEN_VISIBILITY, false); + const mainWindow = MainWindow.get(); + mainWindow?.removeBrowserView(this.view!); + } + } + private create = () => { const preload = getLocalPreload('internalAPI.js'); this.view = new BrowserView({webPreferences: { diff --git a/src/main/views/serversSidebar.ts b/src/main/views/serversSidebar.ts index d5d9b705..f2d39bf8 100644 --- a/src/main/views/serversSidebar.ts +++ b/src/main/views/serversSidebar.ts @@ -104,6 +104,7 @@ export class ServerSidebar { log.info(process.env); }); + // this.view.webContents.openDevTools({mode: 'detach'}); this.setOrderedServers(); this.modal = new ServerSidebarShortcutModalView(); diff --git a/src/main/views/viewManager.ts b/src/main/views/viewManager.ts index 5f816742..f6f38cc4 100644 --- a/src/main/views/viewManager.ts +++ b/src/main/views/viewManager.ts @@ -166,7 +166,10 @@ export class ViewManager { newView.show(); if (newView.needsLoadingScreen()) { LoadingScreen.show(); - ServerSidebar.hide(); + + if (!TokenManager.hasToken()) { + ServerSidebar.hide(); + } } } hidePrevious?.(); @@ -192,11 +195,11 @@ export class ViewManager { } }; - reload = () => { + reload = (force = false) => { const currentView = this.getCurrentView(); if (currentView) { LoadingScreen.show(); - currentView.reload(); + currentView.reload(force); } } diff --git a/src/renderer/css/components/ServersSidebar.scss b/src/renderer/css/components/ServersSidebar.scss index 473ca67e..4d4918e4 100644 --- a/src/renderer/css/components/ServersSidebar.scss +++ b/src/renderer/css/components/ServersSidebar.scss @@ -125,10 +125,10 @@ button { &__unread { position: absolute; z-index: 1; - top: -6px; - right: -6px; - width: 8px; - height: 8px; + top: -5px; + right: -5px; + width: 12px; + height: 12px; background-color: #E91E63; border-radius: 100%; }