Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rip out the downloadArchive job, and replace it with text instructions #360

Merged
merged 1 commit into from
Jan 7, 2025
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
1 change: 0 additions & 1 deletion src/renderer/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ export const PlausibleEvents = Object.freeze({
X_JOB_STARTED_DELETE_BOOKMARKS: 'X Job Started: deleteBookmarks',
X_JOB_STARTED_DELETE_DMS: 'X Job Started: deleteDMs',
X_JOB_STARTED_ARCHIVE_BUILD: 'X Job Started: archiveBuild',
X_JOB_STARTED_DOWNLOAD_ARCHIVE: 'X Job Started: downloadArchive',
X_JOB_STARTED_UNFOLLOW_EVERYONE: 'X Job Started: unfollowEveryone',
});
68 changes: 2 additions & 66 deletions src/renderer/src/view_models/AccountXViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,6 @@ export class AccountXViewModel extends BaseViewModel {
}
}

async defineJobsDownloadArchive() {
const jobTypes = ["login", "downloadArchive"];

try {
this.jobs = await window.electron.X.createJobs(this.account?.id, jobTypes);
this.log("defineJobsDownloadArchive", JSON.parse(JSON.stringify(this.jobs)));
} catch (e) {
await this.error(AutomationErrorType.x_unknownError, {
exception: (e as Error).toString()
}, {
currentURL: this.webview?.getURL()
});
return;
}
}

async reset() {
this.progress = emptyXProgress();
this.rateLimitInfo = emptyXRateLimitInfo();
Expand Down Expand Up @@ -2388,36 +2372,6 @@ Hang on while I scroll down to your earliest bookmarks.`;
return true;
}

async runJobDownloadArchive(jobIndex: number): Promise<boolean> {
await window.electron.trackEvent(PlausibleEvents.X_JOB_STARTED_DOWNLOAD_ARCHIVE, navigator.userAgent);

this.showBrowser = true;
this.showAutomationNotice = false;
this.instructions = `
Follow the instructions below to request your archive from X. You will need to verify your identity with X to download your data.`;

await this.loadURL("https://x.com/settings/download_your_data");
await this.sleep(1000);

// Wait for the user to request the archive
// eslint-disable-next-line no-constant-condition
while (true) {
// Check the URL
const currentURL = this.webview?.getURL();
if (currentURL == "https://x.com/settings/download_your_data") {
if (await this.isSelectorLastDisabled('main div div button')) {
// The request archive button is disabled, which means we have requested the archive
await this.sleep(1000);
break;
}
}
await this.sleep(1000);
}

await this.finishJob(jobIndex);
return true;
}

async runJobUnfollowEveryone(jobIndex: number): Promise<boolean> {
await window.electron.trackEvent(PlausibleEvents.X_JOB_STARTED_UNFOLLOW_EVERYONE, navigator.userAgent);

Expand Down Expand Up @@ -2631,10 +2585,6 @@ Follow the instructions below to request your archive from X. You will need to v
case "deleteDMs":
await this.runJobDeleteDMs(jobIndex);
break;

case "downloadArchive":
await this.runJobDownloadArchive(jobIndex);
break;
}
}

Expand All @@ -2644,7 +2594,6 @@ Follow the instructions below to request your archive from X. You will need to v

// Temp variables
let databaseStatsString: string = "";
let downloadArchiveInJobs = false;

this.log("run", `running state: ${this.state}`);
try {
Expand Down Expand Up @@ -2700,7 +2649,7 @@ You can either import an X archive, or I can build it from scratch by scrolling
this.showBrowser = false;
await this.loadURL("about:blank");
this.instructions = `
**Have you already downloaded your archive from X?**`;
**Before you can import your X archive, you need to download it from X. Here's how.**`;
this.state = State.WizardImportStartDisplay;
break;

Expand Down Expand Up @@ -2815,21 +2764,8 @@ You can save all your data for free, but you need a Premium plan to delete your

await this.refreshDatabaseStats();

// See if the jobs include downloadArchives
downloadArchiveInJobs = false;
for (let i = 0; i < this.jobs.length; i++) {
if (this.jobs[i].jobType === "downloadArchive") {
downloadArchiveInJobs = true;
break;
}
}

// Determine the next state
if (downloadArchiveInJobs) {
this.state = State.WizardImportDownload;
} else {
this.state = State.FinishedRunningJobs;
}
this.state = State.FinishedRunningJobs;

this.showBrowser = false;
await this.loadURL("about:blank");
Expand Down
1 change: 0 additions & 1 deletion src/renderer/src/views/x/XJobStatusComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const getStatusIcon = (status: string) => {
const getJobTypeText = (jobType: string) => {
const jobTypeTexts: { [key: string]: string } = {
login: 'Logging in',
downloadArchive: 'Downloading archive',
indexTweets: 'Saving tweets',
indexLikes: 'Saving likes',
indexBookmarks: 'Saving bookmarks',
Expand Down
68 changes: 44 additions & 24 deletions src/renderer/src/views/x/XWizardImportPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {
} from '../../view_models/AccountXViewModel'

import XLastImportOrBuildComponent from './XLastImportOrBuildComponent.vue';
import { openURL } from '../../util';

// Props
const props = defineProps<{
defineProps<{
model: AccountXViewModel;
}>();

Expand All @@ -18,11 +19,6 @@ const emit = defineEmits<{

// Buttons

const downloadClicked = async () => {
await props.model.defineJobsDownloadArchive();
emit('setState', State.RunJobs);
};

const importClicked = async () => {
emit('setState', State.WizardImporting);
};
Expand All @@ -39,39 +35,63 @@ const backClicked = async () => {
Import your X archive
</h2>
<p class="text-muted">
Before you can import your X archive, you need to download it. Have you already done
this?
Before you can import your X archive, you need to download it by following these steps:
</p>
<ul class="x-archive-steps">
<li>
<strong>Visit <a href="#" @click="openURL('https://x.com/settings/download_your_data')">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Probably should be a <button> instead of a <a> since we are adding onclick function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm using <a> tags as buttons in various places, mostly so I could get the bootstrap link styles look right. Maybe we should go clean that up, but let's do it a separate PR.

https://x.com/settings/download_your_data</a>.</strong><br>
<small class="text-muted">You might need to sign in to X first.</small>
</li>
<li>
<strong>Prove your identity.</strong><br>
<small class="text-muted">You'll probably need to type your X password. You might also need to get
a verification code sent to your email, or do other things to verify your identity.</small>
</li>
<li>
<strong>Click the "Request archive" button.</strong>
</li>
<li>
<strong>Be patient.</strong><br>
<small class="text-muted">After requesting your archive, you'll need to wait <strong>at least a
day</strong>, and maybe longer. Sorry!</small>
</li>
<li>
<strong>When it's ready, download the ZIP file from X.</strong><br>
<small class="text-muted">After you've followed these steps and you have your archive ZIP file,
click the button below.</small>
</li>
</ul>

<div class="buttons mb-4">
<button type="submit" class="btn btn-primary text-nowrap m-1" :disabled="!(
model.account?.xAccount?.archiveTweets ||
model.account?.xAccount?.archiveLikes ||
model.account?.xAccount?.archiveDMs)" @click="downloadClicked">
<i class="fa-solid fa-download" />
Help Me Download My Archive
</button>
<button type="submit" class="btn btn-primary text-nowrap m-1" :disabled="!(
model.account?.xAccount?.archiveTweets ||
model.account?.xAccount?.archiveLikes ||
model.account?.xAccount?.archiveDMs)" @click="importClicked">
<i class="fa-solid fa-folder-tree" />
I Have My Archive
<i class="fa-solid fa-file-import" />
I've Downloaded My Archive from X
</button>
</div>

<XLastImportOrBuildComponent :account-i-d="model.account.id" :button-text="'Go to Delete Options'"
:button-text-no-data="'Skip to Delete Options'" :button-state="State.WizardDeleteOptions"
@set-state="emit('setState', $event)" />

<div class="buttons">
<button type="submit" class="btn btn-outline-secondary text-nowrap m-1" @click="backClicked">
<i class="fa-solid fa-backward" />
Back to Import or Build Database
</button>
</div>

<XLastImportOrBuildComponent :account-i-d="model.account.id" :button-text="'Go to Delete Options'"
:button-text-no-data="'Skip to Delete Options'" :button-state="State.WizardDeleteOptions"
@set-state="emit('setState', $event)" />
</div>
</div>
</template>

<style scoped></style>
<style scoped>
ul.x-archive-steps {
list-style-type: none;
padding: 0 1em;
}

ul.x-archive-steps li {
margin-bottom: 1em;
}
</style>
Loading