Skip to content

Commit

Permalink
Fix: ServersSidebar feedbacks issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kpkarle committed Apr 15, 2024
1 parent 3ba05c4 commit c914725
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/menus/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions src/main/tokenManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
12 changes: 11 additions & 1 deletion src/main/views/MattermostBrowserView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand All @@ -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();

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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)));
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/views/loadingScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions src/main/views/serversSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class ServerSidebar {
log.info(process.env);
});

// this.view.webContents.openDevTools({mode: 'detach'});
this.setOrderedServers();

this.modal = new ServerSidebarShortcutModalView();
Expand Down
9 changes: 6 additions & 3 deletions src/main/views/viewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ export class ViewManager {
newView.show();
if (newView.needsLoadingScreen()) {
LoadingScreen.show();
ServerSidebar.hide();

if (!TokenManager.hasToken()) {
ServerSidebar.hide();
}
}
}
hidePrevious?.();
Expand All @@ -192,11 +195,11 @@ export class ViewManager {
}
};

reload = () => {
reload = (force = false) => {
const currentView = this.getCurrentView();
if (currentView) {
LoadingScreen.show();
currentView.reload();
currentView.reload(force);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/renderer/css/components/ServersSidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
}
Expand Down

0 comments on commit c914725

Please sign in to comment.