Skip to content

Commit dab1c4c

Browse files
committed
Refactor code and reuse dialog+button component in install failure
1 parent e8a3ae3 commit dab1c4c

File tree

4 files changed

+49
-30
lines changed

4 files changed

+49
-30
lines changed

src/renderer/views/SetupUI.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,13 @@
671671
<a href="https://rentry.org/winboat_retry_install" @click="openAnchorLink">these</a>
672672
instructions.
673673
</x-label>
674+
<LogButton
675+
childrenClass="text-lg text-gray-400 text-center"
676+
title="Install log (winboat.log)"
677+
logFile="install.log"
678+
:dialog="logDialog!!"
679+
/>
680+
<LogDialog ref="logDialog"></LogDialog>
674681
</div>
675682

676683
<!-- Completed -->
@@ -698,11 +705,13 @@ import { computed, onMounted, onUnmounted, ref } from "vue";
698705
import { useRouter } from "vue-router";
699706
import { computedAsync } from "@vueuse/core";
700707
import { InstallConfiguration, Specs } from "../../types";
701-
import { getSpecs, getMemoryInfo, defaultSpecs, satisfiesPrequisites, type MemoryInfo } from "../lib/specs";
702-
import { WINDOWS_VERSIONS, WINDOWS_LANGUAGES, type WindowsVersionKey, GUEST_NOVNC_PORT } from "../lib/constants";
708+
import { defaultSpecs, getMemoryInfo, getSpecs, type MemoryInfo, satisfiesPrequisites } from "../lib/specs";
709+
import { GUEST_NOVNC_PORT, WINDOWS_LANGUAGES, WINDOWS_VERSIONS, type WindowsVersionKey } from "../lib/constants";
703710
import { InstallManager, type InstallState, InstallStates } from "../lib/install";
704711
import { openAnchorLink } from "../utils/openLink";
705712
import license from "../assets/LICENSE.txt?raw";
713+
import LogButton from "./buttons/LogButton.vue";
714+
import LogDialog from "./dialogs/LogDialog.vue";
706715
707716
const path: typeof import("path") = require("node:path");
708717
const electron: typeof import("electron") = require("electron").remote || require("@electron/remote");
@@ -811,6 +820,7 @@ const confirmPassword = ref("");
811820
const homeFolderSharing = ref(false);
812821
const installState = ref<InstallState>(InstallStates.IDLE);
813822
const preinstallMsg = ref("");
823+
const logDialog = ref<typeof LogDialog | null>(null);
814824
815825
let installManager: InstallManager | null = null;
816826
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script setup lang="ts">
2+
import { WINBOAT_DIR } from "../../lib/constants";
3+
import LogDialog from "../dialogs/LogDialog.vue";
4+
const fs: typeof import("fs") = require("node:fs");
5+
const path: typeof import("path") = require("node:path");
6+
7+
defineProps({ title: String, dialog: LogDialog, logFile: String, childrenClass: String });
8+
</script>
9+
10+
<template>
11+
<x-button
12+
@click="
13+
dialog!.setTitle(title!!);
14+
dialog!.setContent(fs.readFileSync(path.join(WINBOAT_DIR, logFile!!), 'utf8'));
15+
dialog!.showModal();
16+
"
17+
:class="childrenClass"
18+
>
19+
<x-label>Winboat log (winboat.log)</x-label>
20+
</x-button>
21+
</template>
Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<script setup lang="ts">
22
import { ref } from "vue";
3-
const fs: typeof import("fs") = require("node:fs");
4-
const path: typeof import("path") = require("node:path");
5-
const logContent = ref("");
6-
const logTitle = ref("");
7-
const logDialog = ref<typeof LogDialog | null>(null);
8-
import { WINBOAT_DIR } from "../../lib/constants";
93
import LogDialog from "../dialogs/LogDialog.vue";
104
import { Icon } from "@iconify/vue";
5+
import LogButton from "../buttons/LogButton.vue";
6+
7+
const logDialog = ref<typeof LogDialog | null>(null);
118
</script>
129

1310
<template>
@@ -22,25 +19,9 @@ import { Icon } from "@iconify/vue";
2219
<p class="text-neutral-400 text-[0.9rem] !pt-0 !mt-0">Select the log you want to open</p>
2320
</div>
2421
<div class="flex flex-row gap-2 justify-center items-center" style="font-size: 0.8125rem">
25-
<x-button
26-
@click="
27-
logTitle = 'Winboat log (winboat.log)';
28-
logContent = fs.readFileSync(path.join(WINBOAT_DIR, 'winboat.log'), 'utf8');
29-
logDialog!.showModal();
30-
"
31-
>
32-
Winboat log (winboat.log)
33-
</x-button>
34-
<x-button
35-
@click="
36-
logTitle = 'Install log (install.log)';
37-
logContent = fs.readFileSync(path.join(WINBOAT_DIR, 'install.log'), 'utf8');
38-
logDialog!.showModal();
39-
"
40-
>
41-
Install log (install.log)
42-
</x-button>
22+
<LogButton title="Winboat log (winboat.log)" logFile="winboat.log" :dialog="logDialog!!" />
23+
<LogButton title="Install log (install.log)" logFile="install.log" :dialog="logDialog!!" />
4324
</div>
44-
<LogDialog :title="logTitle" :content="logContent" ref="logDialog"></LogDialog>
25+
<LogDialog ref="logDialog"></LogDialog>
4526
</x-card>
4627
</template>

src/renderer/views/dialogs/LogDialog.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@ import { ref } from "vue";
33
import { Icon } from "@iconify/vue";
44
const electron: typeof import("electron") = require("electron");
55
6-
defineProps({ title: String, content: String });
6+
defineProps({ title: String });
77
const dialogRef = ref<HTMLDialogElement | null>(null);
88
const copied = ref(false);
9+
const title = ref("");
10+
const content = ref("");
911
function showModal() {
1012
copied.value = false;
1113
dialogRef.value!.showModal();
1214
}
13-
14-
defineExpose({ showModal });
15+
function setTitle(newTitle: string) {
16+
title.value = newTitle;
17+
}
18+
function setContent(newContent: string) {
19+
content.value = newContent;
20+
}
21+
defineExpose({ showModal, setTitle, setContent });
1522
</script>
1623

1724
<template>

0 commit comments

Comments
 (0)