Skip to content

Commit 16dd540

Browse files
committed
fixed MainWindow not releasing event listeners correctly
1 parent 6694336 commit 16dd540

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/views/MainWindow.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,6 @@ export class MainWindow extends React.Component<IProps, IMainWindowState> {
150150
};
151151

152152
this.applicationButtons = [];
153-
154-
this.props.api.events.on('show-main-page', pageId => {
155-
this.setMainPage(pageId, false);
156-
});
157-
158-
this.props.api.events.on('refresh-main-page', () => {
159-
this.forceUpdate();
160-
});
161-
162-
this.props.api.events.on('show-modal', id => {
163-
this.updateState({
164-
showLayer: { $set: id },
165-
});
166-
});
167153
}
168154

169155
public getChildContext(): IComponentContext {
@@ -183,6 +169,20 @@ export class MainWindow extends React.Component<IProps, IMainWindowState> {
183169

184170
this.updateSize();
185171

172+
this.props.api.events.on('show-main-page', pageId => {
173+
this.setMainPage(pageId, false);
174+
});
175+
176+
this.props.api.events.on('refresh-main-page', () => {
177+
this.forceUpdate();
178+
});
179+
180+
this.props.api.events.on('show-modal', id => {
181+
this.updateState({
182+
showLayer: { $set: id },
183+
});
184+
});
185+
186186
window.addEventListener('resize', this.updateSize);
187187
window.addEventListener('keydown', this.updateModifiers);
188188
window.addEventListener('keyup', this.updateModifiers);
@@ -191,6 +191,9 @@ export class MainWindow extends React.Component<IProps, IMainWindowState> {
191191
}
192192

193193
public componentWillUnmount() {
194+
this.props.api.events.removeAllListeners('show-main-page');
195+
this.props.api.events.removeAllListeners('refresh-main-page');
196+
this.props.api.events.removeAllListeners('show-modal');
194197
window.removeEventListener('resize', this.updateSize);
195198
window.removeEventListener('keydown', this.updateModifiers);
196199
window.removeEventListener('keyup', this.updateModifiers);
@@ -436,7 +439,7 @@ export class MainWindow extends React.Component<IProps, IMainWindowState> {
436439
const state = this.props.api.getState();
437440
const profile = profileById(state, this.props.activeProfileId);
438441
const game = profile !== undefined ? getGame(profile.gameId) : undefined;
439-
const gameName = game?.name || 'Mods';
442+
const gameName = game?.shortName || game?.name || 'Mods';
440443
const pageGroups = [
441444
{ title: undefined, key: 'dashboard' },
442445
{ title: 'General', key: 'global' },

0 commit comments

Comments
 (0)