Skip to content

Commit

Permalink
Use window instead of iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
Excellify committed Jun 6, 2024
1 parent fcae9c6 commit 49d9070
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/app/settings/SettingsViewProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,45 @@
You are authenticated with 7TV <br />
Try using the the custom 7TV commands if a channel where you have editor rights
</div>
<iframe v-if="!token" ref="iframe" :src="src" width="100%" height="100%" />
</template>
<script setup lang="ts">
import { onBeforeMount, onUnmounted } from "vue";
import { onMounted, onUnmounted } from "vue";
import { Pausable, useIntervalFn } from "@vueuse/core";
import { useActor } from "@/composable/useActor";
import { useConfig } from "@/composable/useSettings";

const src = import.meta.env.VITE_APP_SITE + "/extension/auth";

const actor = useActor();
const token = useConfig<string>("app.7tv.token");

let w: Window | null = null;
let s: Pausable | null = null;

const listener = (ev: MessageEvent) => {
const data = ev.data;
if (data && data.type === "7tv-token") {
token.value = data.token;
if (!ev.data) return;

switch (ev.data.type) {
case "7tv-token":
token.value = ev.data.token;
w?.close();
s?.pause();
window.removeEventListener("message", listener);
break;
}
};

onBeforeMount(() => {
onMounted(() => {
w = window.open(src, "7tv-auth", "width=400,height=600");
if (!w) return;
window.addEventListener("message", listener);
s = useIntervalFn(() => {
w?.postMessage("7tv-token-request", "*");
}, 100);
});

onUnmounted(() => {
w?.close();
window.removeEventListener("message", listener);
});
</script>
Expand Down

0 comments on commit 49d9070

Please sign in to comment.