Skip to content

Commit

Permalink
Pass the webview into the AccountXModel
Browse files Browse the repository at this point in the history
  • Loading branch information
micahflee committed Jun 13, 2024
1 parent a98f01b commit c252875
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 8 additions & 1 deletion packages/renderer/src/view_models/AccountXModel.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Electron from 'electron';

export enum State {
Login = "login",
Dashboard = "dashboard",
Expand All @@ -14,17 +16,21 @@ export class AccountXModel {
private account: XAccount;
private state: string;
private showBrowser: boolean;
private webview: Electron.WebviewTag;

public instructions: string;

constructor(account: XAccount) {
constructor(account: XAccount, webview: Electron.WebviewTag) {
this.account = account;
this.webview = webview;

this.state = State.Login;
this.instructions = "";
this.showBrowser = false;
}

async run() {
console.log("State is " + this.state)
switch (this.state) {
case State.Login:
// Never logged in before
Expand All @@ -34,6 +40,7 @@ Excellent choice! I can help you automatically delete your tweets, likes, and di
except for the ones you want to keep. To start, login to your X account below.
`;
this.showBrowser = true;
this.webview.loadURL("https://twitter.com/login");
} else {
// We have logged in before. Are we currently logged in?
}
Expand Down
13 changes: 9 additions & 4 deletions packages/renderer/src/views/AccountX.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { ref, inject, onMounted, onUnmounted } from 'vue'
import type { Ref } from 'vue';
import { useRoute } from 'vue-router';
import Electron from 'electron';
import SpeechBubble from '../components/SpeechBubble.vue';
Expand All @@ -17,7 +18,7 @@ const accountXModel = ref<AccountXModel | null>(null);
const containerEl = ref<HTMLElement | null>(null);
const speechBubbleComponent = ref<typeof SpeechBubble | null>(null);
const webviewComponent = ref<any>(null);
const webviewComponent = ref<Electron.WebviewTag | null>(null);
const webviewStyle = ref('');
const containerStyle = ref('height: calc(100vh - 0px)');
Expand All @@ -32,8 +33,8 @@ const loadXAccount = async () => {
}
}
if (foundAccount !== null) {
accountXModel.value = new AccountXModel(foundAccount);
if (foundAccount !== null && webviewComponent.value !== null) {
accountXModel.value = new AccountXModel(foundAccount, webviewComponent.value);
}
}
Expand Down Expand Up @@ -66,7 +67,7 @@ onUnmounted(() => {
<template>
<div ref="containerEl" class="d-flex flex-column" :style="containerStyle">
<SpeechBubble ref="speechBubbleComponent" :message="accountXModel?.instructions || ''" class="speech-bubble" />
<webview rel="webviewComponent" src="https://micahflee.com" class="webview" :style="webviewStyle">
<webview ref="webviewComponent" src="about:blank" class="webview" :style="webviewStyle">
</webview>
</div>
</template>
Expand All @@ -79,4 +80,8 @@ onUnmounted(() => {
.speech-bubble {
padding-bottom: 10px;
}
.hidden {
display: none;
}
</style>

0 comments on commit c252875

Please sign in to comment.