Skip to content

Commit a1140f3

Browse files
committed
fix: Log out button does nothing. #188
1 parent a81c874 commit a1140f3

2 files changed

Lines changed: 20 additions & 23 deletions

File tree

src/constants/_other.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { parse } from "url";
33
export const LOGLEVEL = process.env.FIGMA_LOGLEVEL as string | undefined;
44

55
export const HOMEPAGE = "https://www.figma.com";
6+
export const LOGOUT_PAGE = "https://www.figma.com/logout";
7+
export const LOGIN_PAGE = "https://www.figma.com/login";
68
export const RECENT_FILES = "https://www.figma.com/files/recent";
79
export const PARSED_HOMEPAGE = parse("https://www.figma.com");
810

src/main/window/WindowManager.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class WindowManager {
329329
logger.info("The setWorkspaceName not implemented, workspaceName: ", name);
330330
});
331331
E.ipcMain.on("setFigjamEnabled", (event, enabled) => {
332-
logger.info("The setFigjamEnabled not implemented, workspaceName: ", enabled);
332+
logger.info("The setFigjamEnabled not implemented, enabled: ", enabled);
333333
});
334334
E.ipcMain.on("receiveTabs", (event, tabs) => {
335335
this.tabs = tabs;
@@ -755,31 +755,26 @@ class WindowManager {
755755
};
756756

757757
private logoutAndRestart = (event?: E.Event): void => {
758-
E.net
759-
.request(`${this.home}/logout`)
760-
.on("response", response => {
761-
response.on("error", (err: Error) => {
762-
logger.error("Request error: ", err);
763-
});
764-
response.on("end", () => {
765-
if (response.statusCode >= 200 && response.statusCode <= 299) {
766-
E.session.defaultSession.cookies.flushStore().then(() => {
767-
this.mainWindow.setBrowserView(this.mainTab);
768-
this.mainTab.webContents.reload();
758+
const request = E.net.request({
759+
url: Const.LOGOUT_PAGE,
760+
useSessionCookies: true,
761+
});
769762

770-
Tabs.closeAll();
763+
request.on("response", async response => {
764+
this.setFigmaUserIDs([]);
765+
try {
766+
await Promise.all([E.session.defaultSession.clearStorageData(), E.session.defaultSession.clearCache()]);
767+
} finally {
768+
Tabs.closeAll();
771769

772-
this.mainWindow.webContents.send("closeAllTab");
773-
});
774-
}
770+
this.mainWindow.setBrowserView(this.mainTab);
771+
this.mainTab.webContents.loadURL(Const.LOGIN_PAGE);
775772

776-
if (response.statusCode >= 400) {
777-
E.session.defaultSession.clearStorageData();
778-
this.mainWindow.webContents.loadURL(`${this.home}`);
779-
}
780-
});
781-
})
782-
.end();
773+
this.mainWindow.webContents.send("closeAllTab");
774+
}
775+
});
776+
request.on("error", error => logger.error("Logout error: ", error));
777+
request.end();
783778

784779
event && event.preventDefault();
785780
return;

0 commit comments

Comments
 (0)