Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed how you allocate Ram in the launcher from percent to now mb and fix #329

Open
wants to merge 1 commit into
base: tauri_v1
Choose a base branch
from
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
11 changes: 7 additions & 4 deletions src-tauri/src/app/app_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{path::Path, collections::HashMap};
use anyhow::Result;
use serde::{Deserialize, Serialize};
use tokio::fs;
use crate::{auth::ClientAccount, minecraft::auth::MinecraftAccount};
use crate::{auth::ClientAccount, minecraft::auth::MinecraftAccount, utils::total_system_memory_in_mb};

fn default_concurrent_downloads() -> i32 {
10
Expand All @@ -36,10 +36,12 @@ pub(crate) struct LauncherOptions {
pub custom_data_path: String,
#[serde(rename = "showNightlyBuilds")]
pub show_nightly_builds: bool,
#[serde(rename = "memoryPercentage")]
pub memory_percentage: i32,
#[serde(rename = "customJavaPath", default)]
pub custom_java_path: String,
#[serde(rename = "systemMemory")]
pub system_memory: i64,
Comment on lines +41 to +42
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should consider to re-add mem_percentage instead of storing the system memory inside the config.

#[serde(rename = "allocatedMemory")]
pub allocated_memory: i64,
#[serde(rename = "selectedBranch")]
pub selected_branch: Option<String>,
#[serde(rename = "selectedBuild")]
Expand Down Expand Up @@ -86,8 +88,9 @@ impl Default for LauncherOptions {
keep_launcher_open: false,
custom_data_path: String::new(),
show_nightly_builds: false,
memory_percentage: 80, // 80% memory of computer allocated to game
custom_java_path: String::new(),
system_memory: total_system_memory_in_mb(),
allocated_memory: total_system_memory_in_mb() / 2,
selected_branch: None,
selected_build: None,
client_account: None,
Expand Down
9 changes: 1 addition & 8 deletions src-tauri/src/app/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use uuid::Uuid;

use crate::{auth::{ClientAccountAuthenticator, ClientAccount}, minecraft::{auth::{self, MinecraftAccount}, launcher::{LauncherData, LaunchingParameter}, prelauncher, progress::ProgressUpdate}, HTTP_CLIENT, LAUNCHER_DIRECTORY, LAUNCHER_VERSION};
use crate::app::api::{Branches, Changelog, ContentDelivery, News};
use crate::utils::percentage_of_total_memory;

use super::{api::{ApiEndpoints, Build, LoaderMod, ModSource}, app_data::LauncherOptions};

Expand Down Expand Up @@ -299,7 +298,7 @@ async fn run_client(
let xuid = Uuid::new_v4().to_string();

let parameters = LaunchingParameter {
memory: percentage_of_total_memory(options.memory_percentage),
memory: options.allocated_memory,
custom_data_path: if !options.custom_data_path.is_empty() { Some(options.custom_data_path) } else { None },
custom_java_path: if !options.custom_java_path.is_empty() { Some(options.custom_java_path) } else { None },
auth_player_name: account_name,
Expand Down Expand Up @@ -402,11 +401,6 @@ async fn logout(account_data: MinecraftAccount) -> Result<(), String> {
account_data.logout().await.map_err(|e| format!("unable to logout: {:?}", e))
}

#[tauri::command]
async fn mem_percentage(memory_percentage: i32) -> i64 {
percentage_of_total_memory(memory_percentage)
}

#[tauri::command]
async fn fetch_news() -> Result<Vec<News>, String> {
ContentDelivery::news()
Expand Down Expand Up @@ -505,7 +499,6 @@ pub fn gui_main() {
fetch_news,
fetch_changelog,
clear_data,
mem_percentage,
default_data_folder_path,
terminate,
get_launcher_version,
Expand Down
5 changes: 2 additions & 3 deletions src-tauri/src/utils/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ use serde::Deserialize;
use sysinfo::{RefreshKind, System, SystemExt};

/// Get the total memory of the system in bytes
pub fn percentage_of_total_memory(memory_percentage: i32) -> i64 {
pub fn total_system_memory_in_mb() -> i64 {
let sys = System::new_with_specifics(RefreshKind::new().with_memory());

((sys.total_memory() / 1000000) as f64 * (memory_percentage as f64 / 100.0)) as i64
(sys.total_memory() / 1024 / 1024) as i64
}

pub const OS: OperatingSystem = if cfg!(target_os = "windows") {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/main/MainScreen.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@
windowTitle="Select custom data directory"
/>
<RangeSetting
title="Memory"
min={20}
max={100}
bind:value={options.memoryPercentage}
valueSuffix="%"
title="Allocated Memory"
min={1}
max={options.systemMemory}
bind:value={options.allocatedMemory}
valueSuffix="MB"
step={1}
/>

Expand Down