Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
<script setup lang="ts">
import { injectNotificationManager, Slider, StyledInput, Toggle } from '@modrinth/ui'
import {
ButtonStyled,
defineMessages,
injectNotificationManager,
Slider,
StyledInput,
Toggle,
useVIntl,
} from '@modrinth/ui'
import { ref, watch } from 'vue'

import useMemorySlider from '@/composables/useMemorySlider'
import { get, set } from '@/helpers/settings.ts'
import { ensure_default_options_file, get, set } from '@/helpers/settings.ts'
import { openPath } from '@/helpers/utils.js'

const { handleError } = injectNotificationManager()
const { formatMessage } = useVIntl()

const defaultOptionsMessages = defineMessages({
title: {
id: 'app.settings.default-options.title',
defaultMessage: 'Default options.txt',
},
description: {
id: 'app.settings.default-options.description',
defaultMessage:
'This file is copied to every new instance. Edit it to set default keybinds and other options.',
},
openFileLocation: {
id: 'app.settings.default-options.open-file-location',
defaultMessage: 'Open file location',
},
})

async function openDefaultOptionsLocation() {
try {
const path = await ensure_default_options_file()
await openPath(path)
} catch (e) {
handleError(e)
}
}

const fetchSettings = await get()
fetchSettings.launchArgs = fetchSettings.extra_launch_args.join(' ')
Expand Down Expand Up @@ -52,6 +87,22 @@ watch(

<template>
<div>
<h2 class="m-0 text-lg font-extrabold text-contrast">
{{ formatMessage(defaultOptionsMessages.title) }}
</h2>
<p class="m-0 mt-1 mb-2 leading-tight text-secondary">
{{ formatMessage(defaultOptionsMessages.description) }}
</p>
<div class="mt-2 flex flex-wrap gap-2">
<ButtonStyled>
<button type="button" @click="openDefaultOptionsLocation">
{{ formatMessage(defaultOptionsMessages.openFileLocation) }}
</button>
</ButtonStyled>
</div>

<hr class="mt-4 bg-button-border border-none h-[1px]" />

<h2 class="m-0 text-lg font-extrabold text-contrast">Window size</h2>

<div class="flex items-center justify-between gap-4">
Expand Down
4 changes: 4 additions & 0 deletions apps/app-frontend/src/helpers/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ export async function set(settings: AppSettings) {
export async function cancel_directory_change(): Promise<void> {
return await invoke('plugin:settings|cancel_directory_change')
}

export async function ensure_default_options_file(): Promise<string> {
return await invoke('plugin:settings|ensure_default_options_file')
}
9 changes: 9 additions & 0 deletions apps/app-frontend/src/locales/en-US/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@
"app.modal.update-to-play.updated-count": {
"message": "{count} updated"
},
"app.settings.default-options.description": {
"message": "This file is copied to every new instance. Edit it to set default keybinds and other options."
},
"app.settings.default-options.open-file-location": {
"message": "Open file location"
},
"app.settings.default-options.title": {
"message": "Default options.txt"
},
"app.settings.developer-mode-enabled": {
"message": "Developer mode enabled."
},
Expand Down
1 change: 1 addition & 0 deletions apps/app/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ fn main() {
"settings_get",
"settings_set",
"cancel_directory_change",
"ensure_default_options_file",
])
.default_permission(
DefaultPermissionRule::AllowAllCommands,
Expand Down
8 changes: 7 additions & 1 deletion apps/app/src/api/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
.invoke_handler(tauri::generate_handler![
settings_get,
settings_set,
cancel_directory_change
cancel_directory_change,
ensure_default_options_file
])
.build()
}
Expand Down Expand Up @@ -35,3 +36,8 @@ pub async fn cancel_directory_change() -> Result<()> {
settings::cancel_directory_change(identifier).await?;
Ok(())
}

#[tauri::command]
pub async fn ensure_default_options_file() -> Result<std::path::PathBuf> {
Ok(theseus::settings::ensure_default_options_file().await?)
}
6 changes: 6 additions & 0 deletions packages/app-lib/src/api/profile/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ pub async fn profile_create(
crate::launcher::install_minecraft(&profile, None, false).await?;
}

let default_opts = state.directories.default_options_file_path();
let instance_options = full_path.join("options.txt");
if default_opts.exists() && !instance_options.exists() {
io::copy(&default_opts, &instance_options).await?;
}

Ok(profile.path)
}
.await;
Expand Down
13 changes: 13 additions & 0 deletions packages/app-lib/src/api/settings.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
//! Theseus profile management interface

use std::path::PathBuf;

pub use crate::{
State,
state::{Hooks, MemorySettings, Profile, Settings, WindowSize},
};

/// Ensures the default options file exists; creates it empty if missing. Returns its path.
#[tracing::instrument]
pub async fn ensure_default_options_file() -> crate::Result<PathBuf> {
let state = State::get().await?;
let path = state.directories.default_options_file_path();
if !path.exists() {
tokio::fs::write(&path, []).await?;
}
Ok(path)
}

/// Gets entire settings
#[tracing::instrument]
pub async fn get() -> crate::Result<Settings> {
Expand Down
11 changes: 11 additions & 0 deletions packages/app-lib/src/state/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ impl DirectoryInfo {
))
})?;

let default_opts = settings_dir.join("options.txt.default");
if !default_opts.exists() {
let _ = fs::write(&default_opts, []).await;
}

let config_dir =
config_dir.map_or_else(|| settings_dir.clone(), PathBuf::from);

Expand Down Expand Up @@ -178,6 +183,12 @@ impl DirectoryInfo {
.map(|d| d.join(LAUNCHER_LOGS_FOLDER_NAME))
}

/// Path to the global default options.txt copied into new instances when they have none.
#[inline]
pub fn default_options_file_path(&self) -> PathBuf {
self.settings_dir.join("options.txt.default")
}

/// Get the cache directory for Theseus
#[inline]
pub fn caches_dir(&self) -> PathBuf {
Expand Down