Fixed issue with GPO navigation between tabs (#1822)

This commit is contained in:
Devin Binnie
2021-10-19 09:05:49 -04:00
committed by GitHub
parent f14f4062f6
commit cde76cc15f
3 changed files with 40 additions and 13 deletions

View File

@@ -46,10 +46,16 @@ export default class Config extends EventEmitter {
localConfigData?: ConfigType; localConfigData?: ConfigType;
useNativeWindow: boolean; useNativeWindow: boolean;
predefinedTeams: TeamWithTabs[];
constructor(configFilePath: string) { constructor(configFilePath: string) {
super(); super();
this.configFilePath = configFilePath; this.configFilePath = configFilePath;
this.registryConfig = new RegistryConfig(); this.registryConfig = new RegistryConfig();
this.predefinedTeams = [];
if (buildConfig.defaultTeams) {
this.predefinedTeams.push(...buildConfig.defaultTeams.map((team) => getDefaultTeamWithTabsFromTeam(team)));
}
try { try {
this.useNativeWindow = os.platform() === 'win32' && (parseInt(os.release().split('.')[0], 10) < 10); this.useNativeWindow = os.platform() === 'win32' && (parseInt(os.release().split('.')[0], 10) < 10);
} catch { } catch {
@@ -80,6 +86,9 @@ export default class Config extends EventEmitter {
loadRegistry = (registryData: Partial<RegistryConfigType>): void => { loadRegistry = (registryData: Partial<RegistryConfigType>): void => {
this.registryConfigData = registryData; this.registryConfigData = registryData;
if (this.registryConfigData.teams) {
this.predefinedTeams.push(...this.registryConfigData.teams.map((team) => getDefaultTeamWithTabsFromTeam(team)));
}
this.reload(); this.reload();
} }
@@ -109,7 +118,12 @@ export default class Config extends EventEmitter {
*/ */
set = (key: keyof ConfigType, data: ConfigType[keyof ConfigType]): void => { set = (key: keyof ConfigType, data: ConfigType[keyof ConfigType]): void => {
if (key && this.localConfigData) { if (key && this.localConfigData) {
this.localConfigData = Object.assign({}, this.localConfigData, {[key]: data}); if (key === 'teams') {
this.localConfigData.teams = this.filterOutPredefinedTeams(data as TeamWithTabs[]);
this.predefinedTeams = this.filterInPredefinedTeams(data as TeamWithTabs[]);
} else {
this.localConfigData = Object.assign({}, this.localConfigData, {[key]: data});
}
this.regenerateCombinedConfigData(); this.regenerateCombinedConfigData();
this.saveLocalConfigData(); this.saveLocalConfigData();
} }
@@ -206,9 +220,6 @@ export default class Config extends EventEmitter {
get localTeams() { get localTeams() {
return this.localConfigData?.teams ?? defaultPreferences.version; return this.localConfigData?.teams ?? defaultPreferences.version;
} }
get predefinedTeams() {
return [...this.buildConfigData?.defaultTeams ?? [], ...this.registryConfigData?.teams ?? []];
}
get enableHardwareAcceleration() { get enableHardwareAcceleration() {
return this.combinedData?.enableHardwareAcceleration ?? defaultPreferences.enableHardwareAcceleration; return this.combinedData?.enableHardwareAcceleration ?? defaultPreferences.enableHardwareAcceleration;
} }
@@ -336,21 +347,14 @@ export default class Config extends EventEmitter {
// IMPORTANT: properly combine teams from all sources // IMPORTANT: properly combine teams from all sources
let combinedTeams: TeamWithTabs[] = []; let combinedTeams: TeamWithTabs[] = [];
// - start by adding default teams from buildConfig, if any combinedTeams.push(...this.predefinedTeams);
if (this.buildConfigData?.defaultTeams?.length) {
combinedTeams.push(...this.buildConfigData.defaultTeams.map((team) => getDefaultTeamWithTabsFromTeam(team)));
}
// - add registry defined teams, if any
if (this.registryConfigData?.teams?.length) {
combinedTeams.push(...this.registryConfigData.teams.map((team) => getDefaultTeamWithTabsFromTeam(team)));
}
// - add locally defined teams only if server management is enabled // - add locally defined teams only if server management is enabled
if (this.localConfigData && this.enableServerManagement) { if (this.localConfigData && this.enableServerManagement) {
combinedTeams.push(...this.localConfigData.teams || []); combinedTeams.push(...this.localConfigData.teams || []);
} }
this.predefinedTeams = this.filterOutDuplicateTeams(this.predefinedTeams);
combinedTeams = this.filterOutDuplicateTeams(combinedTeams); combinedTeams = this.filterOutDuplicateTeams(combinedTeams);
combinedTeams = this.sortUnorderedTeams(combinedTeams); combinedTeams = this.sortUnorderedTeams(combinedTeams);
@@ -393,6 +397,21 @@ export default class Config extends EventEmitter {
return newTeams; return newTeams;
} }
/**
* Returns the provided array fo teams with existing teams includes
* @param {array} teams array of teams to check for already defined teams
*/
filterInPredefinedTeams = (teams: TeamWithTabs[]) => {
let newTeams = teams;
// filter out predefined teams
newTeams = newTeams.filter((newTeam) => {
return this.predefinedTeams.findIndex((existingTeam) => newTeam.url === existingTeam.url) >= 0; // eslint-disable-line max-nested-callbacks
});
return newTeams;
}
/** /**
* Apply a default sort order to the team list, if no order is specified. * Apply a default sort order to the team list, if no order is specified.
* @param {array} teams to sort * @param {array} teams to sort

View File

@@ -318,6 +318,8 @@ function handleConfigSynchronize() {
if (process.platform === 'win32' && !didCheckForAddServerModal && typeof config.registryConfigData !== 'undefined') { if (process.platform === 'win32' && !didCheckForAddServerModal && typeof config.registryConfigData !== 'undefined') {
didCheckForAddServerModal = true; didCheckForAddServerModal = true;
updateServerInfos(config.teams);
WindowManager.initializeCurrentServerName();
if (config.teams.length === 0) { if (config.teams.length === 0) {
handleNewServerModal(); handleNewServerModal();
} }

View File

@@ -352,6 +352,12 @@ function initializeViewManager() {
status.viewManager = new ViewManager(status.config, status.mainWindow); status.viewManager = new ViewManager(status.config, status.mainWindow);
status.viewManager.load(); status.viewManager.load();
status.viewManager.showInitial(); status.viewManager.showInitial();
initializeCurrentServerName();
}
}
export function initializeCurrentServerName() {
if (status.config && !status.currentServerName) {
status.currentServerName = (status.config.teams.find((team) => team.order === status.config?.lastActiveTeam) || status.config.teams.find((team) => team.order === 0))?.name; status.currentServerName = (status.config.teams.find((team) => team.order === status.config?.lastActiveTeam) || status.config.teams.find((team) => team.order === 0))?.name;
} }
} }