Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions src/account_x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,42 +378,6 @@ export class XAccountController {
);
}

async getUsernameStart() {
log.info("XAccountController.getUsernameStart");
const ses = session.fromPartition(`persist:account-${this.account?.id}`);
await ses.clearCache();
await this.mitmController.startMonitoring();
await this.mitmController.startMITM(ses, ["api.x.com/1.1/account/settings.json"]);
}

async getUsernameStop() {
log.info("XAccountController.getUsernameStop");
await this.mitmController.stopMonitoring();
const ses = session.fromPartition(`persist:account-${this.account?.id}`);
await this.mitmController.stopMITM(ses);
}

async getUsername(): Promise<string | null> {
log.info("XAccountController.getUsername");
let username = null;
if (!this.account) {
log.error("XAccountController.getUsername: account not found");
return username;
}

// See if we got settings.json
for (let i = 0; i < this.mitmController.responseData.length; i++) {
// If URL starts with /1.1/account/settings.json
if (this.mitmController.responseData[i].url.includes("/1.1/account/settings.json") && this.mitmController.responseData[i].status == 200) {
const body = JSON.parse(this.mitmController.responseData[i].body);
username = body.screen_name;
break;
}
}

return username;
}

async indexStart() {
const ses = session.fromPartition(`persist:account-${this.account?.id}`);
await ses.clearCache();
Expand Down Expand Up @@ -1575,33 +1539,6 @@ export const defineIPCX = () => {
}
});

ipcMain.handle('X:getUsernameStart', async (_, accountID: number): Promise<void> => {
try {
const controller = getXAccountController(accountID);
await controller.getUsernameStart();
} catch (error) {
throw new Error(packageExceptionForReport(error as Error));
}
});

ipcMain.handle('X:getUsernameStop', async (_, accountID: number): Promise<void> => {
try {
const controller = getXAccountController(accountID);
await controller.getUsernameStop();
} catch (error) {
throw new Error(packageExceptionForReport(error as Error));
}
});

ipcMain.handle('X:getUsername', async (_, accountID: number): Promise<string | null> => {
try {
const controller = getXAccountController(accountID);
return await controller.getUsername();
} catch (error) {
throw new Error(packageExceptionForReport(error as Error));
}
});

ipcMain.handle('X:indexStart', async (_, accountID: number) => {
try {
const controller = getXAccountController(accountID);
Expand Down
9 changes: 0 additions & 9 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ contextBridge.exposeInMainWorld('electron', {
updateJob: (accountID: number, jobJSON: XJob) => {
ipcRenderer.invoke('X:updateJob', accountID, jobJSON)
},
getUsernameStart: (accountID: number): Promise<boolean> => {
return ipcRenderer.invoke('X:getUsernameStart', accountID)
},
getUsernameStop: (accountID: number) => {
ipcRenderer.invoke('X:getUsernameStop', accountID)
},
getUsername: (accountID: number): Promise<string | null> => {
return ipcRenderer.invoke('X:getUsername', accountID)
},
indexStart: (accountID: number) => {
ipcRenderer.invoke('X:indexStart', accountID)
},
Expand Down
3 changes: 0 additions & 3 deletions src/renderer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ declare global {
createJobs: (accountID: number, jobTypes: string[]) => Promise<XJob[]>;
getLastFinishedJob: (accountID: number, jobType: string) => Promise<XJob | null>;
updateJob: (accountID: number, jobJSON: string) => void;
getUsernameStart: (accountID: number) => Promise<boolean>;
getUsernameStop: (accountID: number) => void;
getUsername: (accountID: number) => Promise<string | null>;
indexStart: (accountID: number) => void;
indexStop: (accountID: number) => void;
indexParseTweets: (accountID: number, isFirstRun: boolean) => Promise<XProgress>;
Expand Down
3 changes: 0 additions & 3 deletions src/renderer/src/test_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ export const stubElectron = () => {
createJobs: cy.stub(),
getLastFinishedJob: cy.stub(),
updateJob: cy.stub(),
getUsernameStart: cy.stub(),
getUsernameStop: cy.stub(),
getUsername: cy.stub(),
indexStart: cy.stub(),
indexStop: cy.stub(),
indexParseTweets: cy.stub(),
Expand Down
38 changes: 12 additions & 26 deletions src/renderer/src/view_models/AccountXViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ export class AccountXViewModel extends BaseViewModel {

async login() {
const originalUsername = this.account && this.account.xAccount && this.account.xAccount.username ? this.account.xAccount.username : null;
let tries: number, success: boolean;

this.showBrowser = true;

Expand Down Expand Up @@ -400,33 +399,20 @@ export class AccountXViewModel extends BaseViewModel {

// Get the username
this.log("login", "getting username");
this.instructions = `You've logged in successfully. Now I'm scraping your username...`;
this.instructions = `You're logged in. Now I'm scraping your username...`;
if (this.webview.getURL() != "https://x.com/home") {
await this.loadURLWithRateLimit("https://x.com/home");
}

let username: string | null = null;
success = false;
for (tries = 0; tries < 3; tries++) {
await window.electron.X.getUsernameStart(this.account.id);
await this.loadURLWithRateLimit("https://x.com/settings/account");
await this.waitForSelector('a[href="/settings/your_twitter_data/account"]', "https://x.com/settings/account");
username = await window.electron.X.getUsername(this.account.id);
await window.electron.X.getUsernameStop(this.account.id);
// Wait for profile button to appear, and click it
await this.waitForSelector('a[aria-label="Profile"]', "https://x.com/home");
await this.scriptClickElement('a[aria-label="Profile"]');

if (username) {
success = true;
break;
} else {
this.log("login", `failed to get username, try #${tries}`);
await this.sleep(1000);
}
}
if (!success) {
const latestResponseData = await window.electron.X.getLatestResponseData(this.account.id);
await this.error(AutomationErrorType.X_login_FailedToGetUsername, {}, {
latestResponseData: latestResponseData,
currentURL: this.webview.getURL()
});
return;
}
// Wait for profile page to load, and get the username from the URL
await this.waitForSelector('div[data-testid="UserName"]');
const url = this.webview.getURL();
const urlObj = new URL(url);
const username = urlObj.pathname.substring(1);

if (originalUsername !== null && username != originalUsername) {
this.log("login", `username changed from ${this.account.xAccount?.username} to ${username}`);
Expand Down