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

feat: engine selection #1469

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions public/locales/af/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "Pas Uitnodigingskode Toe",
"audio-enabled": "Audio enabled",
"cancel": "Cancel",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "Verander taal",
"confirm": "Bevestig",
"confirm-action": "Bevestig aksie",
Expand Down
1 change: 1 addition & 0 deletions public/locales/cn/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "应用邀请代码",
"audio-enabled": "Audio enabled",
"cancel": "取消",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "更改语言",
"confirm": "确认",
"confirm-action": "确认操作",
Expand Down
1 change: 1 addition & 0 deletions public/locales/de/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "Einladungscode anwenden",
"audio-enabled": "Audio enabled",
"cancel": "Abbrechen",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "Sprache",
"confirm": "Bestätigen",
"confirm-action": "Aktion bestätigen",
Expand Down
1 change: 1 addition & 0 deletions public/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "Apply Invite Code",
"audio-enabled": "Audio enabled",
"cancel": "Cancel",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "Language",
"confirm": "Confirm",
"confirm-action": "Confirm action",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fr/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "Appliquer le code d\"invitation",
"audio-enabled": "Audio enabled",
"cancel": "Cancel",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "Langue",
"confirm": "Confirmer",
"confirm-action": "Confirmer l\"action",
Expand Down
1 change: 1 addition & 0 deletions public/locales/hi/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "आमंत्रण कोड लागू करें",
"audio-enabled": "Audio enabled",
"cancel": "रद्द करें",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "भाषा",
"confirm": "पुष्टि करें",
"confirm-action": "क्रिया की पुष्टि करें",
Expand Down
1 change: 1 addition & 0 deletions public/locales/id/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "Terapkan Kode Undangan",
"audio-enabled": "Audio enabled",
"cancel": "Batal",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "Bahasa",
"confirm": "Konfirmasi",
"confirm-action": "Konfirmasi tindakan",
Expand Down
1 change: 1 addition & 0 deletions public/locales/ja/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "招待コードを適用",
"audio-enabled": "Audio enabled",
"cancel": "キャンセル",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "言語",
"confirm": "確認",
"confirm-action": "アクションを確認",
Expand Down
1 change: 1 addition & 0 deletions public/locales/ko/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "초대 코드 적용",
"audio-enabled": "Audio enabled",
"cancel": "취소",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "언어",
"confirm": "확인",
"confirm-action": "작업 확인",
Expand Down
1 change: 1 addition & 0 deletions public/locales/pl/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "Zastosuj Kod Zaproszenia",
"audio-enabled": "Audio enabled",
"cancel": "Anuluj",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "Zmień język",
"confirm": "Potwierdź",
"confirm-action": "Potwierdź działanie",
Expand Down
1 change: 1 addition & 0 deletions public/locales/ru/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "Применить код приглашения",
"audio-enabled": "Audio enabled",
"cancel": "Отмена",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "Язык",
"confirm": "Подтвердить",
"confirm-action": "Подтвердить действие",
Expand Down
1 change: 1 addition & 0 deletions public/locales/tr/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"applyInviteCode": "Davet Kodunu Uygula",
"audio-enabled": "Audio enabled",
"cancel": "İptal",
"change-gpu-engine": "Change Gpu Engine",
"change-language": "Dil Değiştir",
"confirm": "Onayla",
"confirm-action": "İşlemi onayla",
Expand Down
25 changes: 25 additions & 0 deletions src-tauri/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use crate::credential_manager::{Credential, KEYRING_ACCESSED};
use crate::gpu_miner::EngineType;
use semver::Version;
use std::{path::PathBuf, time::SystemTime};
use sys_locale::get_locale;
Expand Down Expand Up @@ -119,6 +120,8 @@ pub struct AppConfigFromFile {
airdrop_tokens: Option<AirdropTokens>,
#[serde(default = "default_true")]
audio_enabled: bool,
#[serde(default = "default_gpu_engine")]
gpu_engine: String,
}

impl Default for AppConfigFromFile {
Expand Down Expand Up @@ -164,6 +167,7 @@ impl Default for AppConfigFromFile {
last_changelog_version: default_changelog_version(),
airdrop_tokens: None,
audio_enabled: true,
gpu_engine: default_gpu_engine(),
}
}
}
Expand Down Expand Up @@ -285,6 +289,7 @@ pub(crate) struct AppConfig {
last_changelog_version: String,
airdrop_tokens: Option<AirdropTokens>,
audio_enabled: bool,
gpu_engine: String,
}

impl AppConfig {
Expand Down Expand Up @@ -332,6 +337,7 @@ impl AppConfig {
last_changelog_version: default_changelog_version(),
airdrop_tokens: None,
audio_enabled: true,
gpu_engine: EngineType::OpenCL.to_string(),
}
}

Expand Down Expand Up @@ -412,6 +418,7 @@ impl AppConfig {
self.last_changelog_version = config.last_changelog_version;
self.airdrop_tokens = config.airdrop_tokens;
self.audio_enabled = config.audio_enabled;
self.gpu_engine = config.gpu_engine;

KEYRING_ACCESSED.store(
config.keyring_accessed,
Expand Down Expand Up @@ -495,6 +502,13 @@ impl AppConfig {
&self.last_changelog_version
}

pub fn gpu_engine(&self) -> EngineType {
match EngineType::from_string(&self.gpu_engine) {
Ok(engine) => engine,
Err(_) => EngineType::OpenCL,
}
}

pub async fn set_mode(
&mut self,
mode: String,
Expand Down Expand Up @@ -800,6 +814,12 @@ impl AppConfig {
Ok(())
}

pub async fn set_gpu_engine(&mut self, engine: &str) -> Result<(), anyhow::Error> {
self.gpu_engine = engine.to_string();
self.update_config_file().await?;
Ok(())
}

// Allow needless update because in future there may be fields that are
// missing
#[allow(clippy::needless_update)]
Expand Down Expand Up @@ -850,6 +870,7 @@ impl AppConfig {
last_changelog_version: self.last_changelog_version.clone(),
airdrop_tokens: self.airdrop_tokens.clone(),
audio_enabled: self.audio_enabled,
gpu_engine: self.gpu_engine.clone(),
};
let config = serde_json::to_string(config)?;
debug!(target: LOG_TARGET, "Updating config file: {:?} {:?}", file, self.clone());
Expand Down Expand Up @@ -899,6 +920,10 @@ fn default_monero_address() -> String {
DEFAULT_MONERO_ADDRESS.to_string()
}

fn default_gpu_engine() -> String {
EngineType::OpenCL.to_string()
}

async fn create_monereo_address(path: PathBuf) -> Result<String, anyhow::Error> {
let cm = CredentialManager::default_with_dir(path);

Expand Down
59 changes: 52 additions & 7 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ use crate::credential_manager::{CredentialError, CredentialManager};
use crate::external_dependencies::{
ExternalDependencies, ExternalDependency, RequiredExternalDependency,
};
use crate::gpu_miner::EngineType;
use crate::gpu_miner_adapter::{GpuMinerStatus, GpuNodeSource};
use crate::hardware::hardware_status_monitor::PublicDeviceProperties;
use crate::gpu_status_file::GpuStatus;
use crate::internal_wallet::{InternalWallet, PaperWalletConfig};
use crate::p2pool::models::{Connections, P2poolStats};
use crate::progress_tracker::ProgressTracker;
Expand Down Expand Up @@ -92,7 +93,7 @@ pub struct CpuMinerMetrics {

#[derive(Debug, Serialize, Clone)]
pub struct GpuMinerMetrics {
hardware: Vec<PublicDeviceProperties>,
hardware: Vec<GpuStatus>,
mining: GpuMinerStatus,
}

Expand Down Expand Up @@ -1010,17 +1011,22 @@ pub async fn set_display_mode(

Ok(())
}

#[tauri::command]
pub async fn set_excluded_gpu_devices(
excluded_gpu_devices: Vec<u8>,
pub async fn toggle_device_exclusion(
device_index: u32,
excluded: bool,
app: tauri::AppHandle,
state: tauri::State<'_, UniverseAppState>,
) -> Result<(), String> {
let mut gpu_miner = state.gpu_miner.write().await;
let config_dir = app
.path()
.app_config_dir()
.expect("Could not get config dir");
gpu_miner
.set_excluded_device(excluded_gpu_devices)
.toggle_device_exclusion(config_dir, device_index, excluded)
.await
.inspect_err(|e| error!("error at set_excluded_gpu_devices {:?}", e))
.inspect_err(|e| error!("error at toggle_device_exclusion {:?}", e))
.map_err(|e| e.to_string())?;
Ok(())
}
Expand Down Expand Up @@ -1805,3 +1811,42 @@ pub async fn proceed_with_update(
}
Ok(())
}

#[tauri::command]
pub async fn set_selected_engine(
selected_engine: &str,
state: tauri::State<'_, UniverseAppState>,
app: tauri::AppHandle,
) -> Result<(), String> {
info!(target: LOG_TARGET, "set_selected_engine called with engine: {:?}", selected_engine);
let timer = Instant::now();

info!(target: LOG_TARGET, "Setting selected engine");
let engine_type = EngineType::from_string(selected_engine).map_err(|e| e.to_string())?;
info!(target: LOG_TARGET, "Selected engine set to {:?}", engine_type);
let config = app
.path()
.app_config_dir()
.expect("Could not get config dir");
state
.gpu_miner
.write()
.await
.set_selected_engine(engine_type, config, app)
.await
.map_err(|e| e.to_string())?;

state
.config
.write()
.await
.set_gpu_engine(selected_engine)
.await
.map_err(|e| e.to_string())?;

if timer.elapsed() > MAX_ACCEPTABLE_COMMAND_TIME {
warn!(target: LOG_TARGET, "proceed_with_update took too long: {:?}", timer.elapsed());
}

Ok(())
}
13 changes: 13 additions & 0 deletions src-tauri/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use serde::Serialize;
use std::collections::HashMap;

use crate::gpu_status_file::{GpuDevice, GpuStatus};

#[derive(Debug, Serialize, Clone)]
pub struct SetupStatusEvent {
pub event_type: String,
Expand All @@ -37,3 +39,14 @@ pub struct ReleaseNotesHandlerEvent {
pub is_app_update_available: bool,
pub should_show_dialog: bool,
}

#[derive(Debug, Serialize, Clone)]
pub struct DetectedAvailableGpuEngines {
pub engines: Vec<String>,
pub selected_engine: String,
}

#[derive(Debug, Serialize, Clone)]
pub struct DetectedDevices {
pub devices: Vec<GpuDevice>,
}
Loading
Loading