aboutsummaryrefslogtreecommitdiff
path: root/src-vue/src/views/SettingsView.vue
blob: dcc787aea66be13599289834c03e5db600950dda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<template>
    <div class="fc-container">
        <el-scrollbar>
            <div class="fc_settings__container">
                <!-- Game folder location -->
                <div class="fc_parameter__panel">
                    <h3>{{ $t('settings.manage_install') }}</h3>
                    <el-input
                        v-model="$store.state.game_install.game_path"
                        :placeholder="$t('settings.choose_folder')"
                        @click="updateGamePath"
                    >
                        <template #prepend>
                            <el-button icon="Folder" @click="updateGamePath"/>
                        </template>
                        <template #append>
                            <el-button @click="openGameInstallFolder">
                                {{ $t('settings.open_game_folder') }}
                            </el-button>
                        </template>
                    </el-input>
                </div>

                <!-- Thunderstore mods per page configuration -->
                <div class="fc_parameter__panel">
                    <h3>{{ $t('settings.nb_ts_mods_per_page') }}</h3>
                    <h6>
                        {{ $t('settings.nb_ts_mods_per_page_desc1') }}<br>
                        {{ $t('settings.nb_ts_mods_per_page_desc2') }}
                    </h6>
                    <el-input
                        v-model="modsPerPage"
                        type="number"
                    >
                        <template #append>
                            <el-button @click="modsPerPage = 20">
                                {{ $t('settings.nb_ts_mods_reset') }}
                            </el-button>
                        </template>
                    </el-input>
                </div>

                <div class="fc_parameter__panel">
                    <h3>{{ $t('settings.show_deprecated_mods') }}</h3>
                    <h6>
                        {{ $t('settings.show_deprecated_mods_desc1') }}<br/>
                        {{ $t('settings.show_deprecated_mods_desc2') }}
                    </h6>
                    <span>
                        {{ $t('settings.show_deprecated_mods') }}
                        <el-switch v-model="showDeprecatedMods"></el-switch>
                    </span>
                </div>

                <!-- Interface localization -->
                <div class="fc_parameter__panel">
                    <h3>{{ $t('settings.language') }}</h3>
                    <language-selector/>
                </div>

                <!-- Repair window -->
                <div class="fc_parameter__panel">
                    <h3>{{ $t('settings.repair.title') }}</h3>
                    <el-button type="primary" @click="openRepairWindow">
                        {{ $t('settings.repair.open_window') }}
                    </el-button>
                </div>

                <!-- About section -->
                <div class="fc_parameter__panel">
                    <h3>{{ $t('settings.about') }}</h3>
                    <div class="fc_northstar__version" @click="activateDeveloperMode">
                        {{ $t('settings.flightcore_version') }} {{ flightcoreVersion === '' ? 'Unknown version' : `${flightcoreVersion}` }}
                    </div>
                </div>

                <!-- Testing section -->
                <div class="fc_parameter__panel">
                    <h3>{{ $t('settings.testing') }}</h3>
                    <span>
                        {{ $t('settings.enable_test_channels') }}
                        <el-switch v-model="enableReleasesSwitch"></el-switch>
                    </span>
                </div>
            </div>
        </el-scrollbar>
    </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { invoke } from "@tauri-apps/api";
import { ReleaseCanal } from "../utils/ReleaseCanal";
import { Store } from 'tauri-plugin-store-api';
import { showErrorNotification, showNotification } from "../utils/ui";
import LanguageSelector from "../components/LanguageSelector.vue";
const persistentStore = new Store('flight-core-settings.json');
import { open } from '@tauri-apps/api/shell';

export default defineComponent({
    name: "SettingsView",
    components: {
        LanguageSelector
    },
    data() {
        return {
            developerModeClicks: 0
        }
    },
    computed: {
        showDeprecatedMods: {
            get(): boolean {
                return this.$store.state.search.showDeprecatedMods;
            },
            set(value: boolean) {
                this.$store.state.search.showDeprecatedMods = value;
            }
        },
        flightcoreVersion(): string {
            return this.$store.state.flightcore_version;
        },
        enableReleasesSwitch: {
            get(): boolean {
                return this.$store.state.enableReleasesSwitch;
            },
            async set(value: boolean): Promise<void> {
                this.$store.state.enableReleasesSwitch = value;
                persistentStore.set('northstar-releases-switching', { value });
                await persistentStore.save(); // explicit save to disk

                // When disabling switch, we switch release canal to stable release, to avoid users being
                // stuck with release candidate after disabling release switching.
                if (!value && this.$store.state.northstar_release_canal !== ReleaseCanal.RELEASE) {
                    this.$store.commit('toggleReleaseCandidate');
                }
            }
        },
        modsPerPage: {
            get(): number {
                return this.$store.state.mods_per_page;
            },
            async set(value: number) {
                this.$store.state.mods_per_page = value;
                persistentStore.set('thunderstore-mods-per-page', { value });
                await persistentStore.save(); // explicit save to disk
            }
        }
    },
    methods: {
        activateDeveloperMode() {
            this.developerModeClicks += 1;
            if (this.developerModeClicks >= 6 && !this.$store.state.developer_mode) {
                this.$store.commit('toggleDeveloperMode');
                showNotification(
                    this.$t('settings.dev_mode_enabled_title'),
                    this.$t('settings.dev_mode_enabled_text'),
                    'info'
                );
                this.developerModeClicks = 0;
            }
        },
        async updateGamePath() {
            this.$store.commit('updateGamePath');
        },
        async openRepairWindow() {
            await invoke("open_repair_window")
                .then((message) => { })
                .catch((error) => {
                    showErrorNotification(error);
                });
        },
        async openGameInstallFolder() {
            // Opens the folder in default file explorer application
            await open(`${this.$store.state.game_install.game_path}`);
        }
    },
    mounted() {
        document.querySelector('input')!.disabled = true;
    },
    unmounted() {
        if (('' + this.modsPerPage) === '') {
            console.warn('Incorrect value for modsPerPage, resetting it to 20.');
            this.modsPerPage = 20;
        }
    }
});
</script>

<style scoped>
.fc_settings__container {
    max-width: 1200px;
    margin: 0 auto;
}

h3:first-of-type {
    margin-top: 0;
    margin-bottom: 1em;
    text-transform: uppercase;
    font-weight: unset;
}

.el-input,
.el-select {
    width: 50%;
}

.el-switch {
    margin-left: 50px;
}


/* Parameter panel styles */
.fc_parameter__panel {
    margin-bottom: 30px;
}

.fc_parameter__panel h3 {
    margin-bottom: 5px;
}

.fc_parameter__panel h6 {
    margin-top: 0;
    margin-bottom: 12px;
}
</style>