mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-11-03 21:43:18 +00:00 
			
		
		
		
	Fix updating of server names and icons at startup.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		@@ -337,7 +337,12 @@ export class ServerManagerView {
 | 
			
		||||
    const servers = DomainUtil.getDomains();
 | 
			
		||||
    if (servers.length > 0) {
 | 
			
		||||
      for (const [i, server] of servers.entries()) {
 | 
			
		||||
        this.initServer(server, i);
 | 
			
		||||
        const tab = this.initServer(server, i);
 | 
			
		||||
        (async () => {
 | 
			
		||||
          const serverConf = await DomainUtil.updateSavedServer(server.url, i);
 | 
			
		||||
          tab.setName(serverConf.alias);
 | 
			
		||||
          tab.setIcon(iconAsUrl(serverConf.icon));
 | 
			
		||||
        })();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      // Open last active tab
 | 
			
		||||
@@ -346,11 +351,7 @@ export class ServerManagerView {
 | 
			
		||||
        lastActiveTab = 0;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      // `checkDomain()` and `webview.load()` for lastActiveTab before the others
 | 
			
		||||
      await DomainUtil.updateSavedServer(
 | 
			
		||||
        servers[lastActiveTab].url,
 | 
			
		||||
        lastActiveTab,
 | 
			
		||||
      );
 | 
			
		||||
      // `webview.load()` for lastActiveTab before the others
 | 
			
		||||
      await this.activateTab(lastActiveTab);
 | 
			
		||||
      await Promise.all(
 | 
			
		||||
        servers.map(async (server, i) => {
 | 
			
		||||
@@ -360,7 +361,6 @@ export class ServerManagerView {
 | 
			
		||||
            return;
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          await DomainUtil.updateSavedServer(server.url, i);
 | 
			
		||||
          const tab = this.tabs[i];
 | 
			
		||||
          if (tab instanceof ServerTab) (await tab.webview).load();
 | 
			
		||||
        }),
 | 
			
		||||
@@ -375,11 +375,9 @@ export class ServerManagerView {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  initServer(server: ServerConf, index: number): void {
 | 
			
		||||
  initServer(server: ServerConf, index: number): ServerTab {
 | 
			
		||||
    const tabIndex = this.getTabIndex();
 | 
			
		||||
 | 
			
		||||
    this.tabs.push(
 | 
			
		||||
      new ServerTab({
 | 
			
		||||
    const tab = new ServerTab({
 | 
			
		||||
      role: "server",
 | 
			
		||||
      icon: iconAsUrl(server.icon),
 | 
			
		||||
      name: server.alias,
 | 
			
		||||
@@ -420,9 +418,10 @@ export class ServerManagerView {
 | 
			
		||||
        onTitleChange: this.updateBadge.bind(this),
 | 
			
		||||
        preload: url.pathToFileURL(path.join(bundlePath, "preload.js")).href,
 | 
			
		||||
      }),
 | 
			
		||||
      }),
 | 
			
		||||
    );
 | 
			
		||||
    });
 | 
			
		||||
    this.tabs.push(tab);
 | 
			
		||||
    this.loading.add(server.url);
 | 
			
		||||
    return tab;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  initActions(): void {
 | 
			
		||||
 
 | 
			
		||||
@@ -140,9 +140,10 @@ export async function saveServerIcon(iconURL: string): Promise<string> {
 | 
			
		||||
export async function updateSavedServer(
 | 
			
		||||
  url: string,
 | 
			
		||||
  index: number,
 | 
			
		||||
): Promise<void> {
 | 
			
		||||
): Promise<ServerConf> {
 | 
			
		||||
  // Does not promise successful update
 | 
			
		||||
  const oldIcon = getDomain(index).icon;
 | 
			
		||||
  const serverConf = getDomain(index);
 | 
			
		||||
  const oldIcon = serverConf.icon;
 | 
			
		||||
  try {
 | 
			
		||||
    const newServerConf = await checkDomain(url, true);
 | 
			
		||||
    const localIconUrl = await saveServerIcon(newServerConf.icon);
 | 
			
		||||
@@ -151,10 +152,13 @@ export async function updateSavedServer(
 | 
			
		||||
      updateDomain(index, newServerConf);
 | 
			
		||||
      reloadDb();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return newServerConf;
 | 
			
		||||
  } catch (error: unknown) {
 | 
			
		||||
    logger.log("Could not update server icon.");
 | 
			
		||||
    logger.log(error);
 | 
			
		||||
    Sentry.captureException(error);
 | 
			
		||||
    return serverConf;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user