Skip to content

Commit bff65f8

Browse files
committed
Add option to improve Wayland compatiblity (using xwayland)
1 parent 5480803 commit bff65f8

18 files changed

Lines changed: 197 additions & 108 deletions

File tree

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@tauri-apps/plugin-notification": "2.3.0",
5757
"@tauri-apps/plugin-opener": "2.4.0",
5858
"@tauri-apps/plugin-os": "2.3.0",
59+
"@tauri-apps/plugin-process": "2.3.0",
5960
"browserslist": "4.25.1",
6061
"classnames": "2.5.1",
6162
"lodash-es": "4.17.21",

src-tauri/Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ tauri-plugin-notification = "2.3.0"
2626
tauri-plugin-opener = "2.4.0"
2727
tauri-plugin-os = "2.3.0"
2828
tauri-plugin-prevent-default = "3.0.0"
29+
tauri-plugin-process = "2.3.0"
2930
tauri-plugin-shell = "2.3.0"
3031
tauri-plugin-single-instance = "2.3.2"
3132
tauri-plugin-window-state = "2.4.0"

src-tauri/capabilities/main.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"opener:allow-default-urls",
2525
"opener:allow-reveal-item-in-dir",
2626
"os:allow-os-type",
27+
"process:allow-restart",
2728
"log:allow-log",
2829
"notification:default",
2930
"app-menu:allow-toggle",

src-tauri/src/libs/init.rs

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,50 @@
1-
use std::fs;
1+
use std::{env, fs};
22

3-
use crate::libs::error::AnyResult;
3+
use home_config::HomeConfig;
44

5-
pub fn init() -> AnyResult<()> {
6-
let config_dir_check = ensure_new_config_dir()?;
5+
use crate::plugins::config::Config;
6+
use crate::{
7+
libs::error::AnyResult,
8+
plugins::config::{ConfigManager, get_storage_dir},
9+
};
710

8-
match config_dir_check {
9-
Some(message) => println!("[init] {}", message),
10-
None => println!("[init] No actions needed"),
11-
}
12-
13-
Ok(())
14-
}
15-
16-
fn ensure_new_config_dir() -> AnyResult<Option<String>> {
11+
pub fn init() -> AnyResult<ConfigManager> {
12+
// 1. Ensure Config dir is "museeks" and not Museeks
1713
let config_dir = dirs::config_dir().expect("Could not find config directory");
1814

1915
let old_path = config_dir.join("./Museeks");
2016
let new_path = config_dir.join("./museeks");
2117

2218
if old_path.exists() && !new_path.exists() {
2319
fs::rename(&old_path, &new_path)?;
24-
return Ok(Some("Renamed config folder from Museeks to museeks".into()));
20+
println!("Renamed config folder from Museeks to museeks");
21+
}
22+
23+
// 2. Ensure Config is created and return it
24+
let conf_path = get_storage_dir();
25+
let manager = HomeConfig::with_file(conf_path.join("config.toml"));
26+
let existing_config = manager.toml::<Config>();
27+
28+
let config = match existing_config {
29+
Ok(config) => ConfigManager::new(manager, config),
30+
Err(_) => {
31+
// The config does not exist, so let's instantiate it with defaults
32+
// Potential issue: if the config is extended, the defaults will be
33+
// reloaded
34+
let default_config = Config::default();
35+
manager.save_toml(&default_config).unwrap();
36+
37+
ConfigManager::new(manager, default_config)
38+
}
39+
};
40+
41+
// 3. Ensure Wayland compatibility fixes if the user requests them
42+
if config.get()?.wayland_compat {
43+
unsafe {
44+
env::set_var("GDK_BACKEND", "x11");
45+
env::set_var("WEBKIT_DISABLE_COMPOSITING_MODE", "1");
46+
}
2547
}
2648

27-
Ok(None)
49+
Ok(config)
2850
}

src-tauri/src/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use libs::init::init;
88
use libs::utils::get_theme_from_name;
99
use log::{LevelFilter, info};
1010
use plugins::config::{ConfigManager, get_storage_dir};
11+
use std::env;
1112
use tauri::{Manager, WebviewUrl, WebviewWindowBuilder};
1213
use tauri_plugin_log::fern::colors::ColoredLevelConfig;
1314
use tauri_plugin_log::{Target, TargetKind};
@@ -17,17 +18,19 @@ use tauri_plugin_window_state::StateFlags;
1718
* The beast
1819
*/
1920
fn main() {
20-
match init() {
21-
Ok(_) => {
21+
let config = match init() {
22+
Ok(config) => {
2223
println!("[init] Initialization successful");
24+
config
2325
}
2426
Err(e) => {
2527
println!("[init] Error during initialization: {}", e);
2628
std::process::exit(1);
2729
}
28-
}
30+
};
2931

3032
tauri::Builder::default()
33+
.plugin(tauri_plugin_process::init())
3134
// Logging must be setup first, otherwise the logs won't be captured
3235
// while setting up the other plugins.
3336
.plugin(
@@ -58,7 +61,7 @@ fn main() {
5861
// Custom integrations
5962
.plugin(plugins::app_close::init())
6063
.plugin(plugins::app_menu::init())
61-
.plugin(plugins::config::init())
64+
.plugin(plugins::config::init(config))
6265
.plugin(plugins::cover::init())
6366
.plugin(plugins::db::init())
6467
.plugin(plugins::debug::init())

src-tauri/src/plugins/app_close.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use tauri::plugin::{Builder, TauriPlugin};
21
use tauri::Runtime;
2+
use tauri::plugin::{Builder, TauriPlugin};
33

44
/**
55
* Plugin in charge on making sure closing the app does not stop the audio

src-tauri/src/plugins/config.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub struct Config {
7373
pub auto_update_checker: bool,
7474
pub notifications: bool,
7575
pub track_view_density: TrackViewDensity,
76+
pub wayland_compat: bool,
7677
}
7778

7879
pub const SYSTEM_THEME: &str = "__system";
@@ -98,6 +99,7 @@ impl Config {
9899
auto_update_checker: true,
99100
notifications: false,
100101
track_view_density: TrackViewDensity::Normal,
102+
wayland_compat: false,
101103
}
102104
}
103105
}
@@ -108,6 +110,15 @@ pub struct ConfigManager {
108110
pub data: RwLock<Config>,
109111
}
110112

113+
impl ConfigManager {
114+
pub fn new(manager: HomeConfig, config: Config) -> Self {
115+
Self {
116+
manager,
117+
data: RwLock::new(config),
118+
}
119+
}
120+
}
121+
111122
fn config_err<T: Display>(err: T) -> MuseeksError {
112123
MuseeksError::Config(format!("{}", err))
113124
}
@@ -167,30 +178,7 @@ pub fn set_config(config_manager: State<ConfigManager>, config: Config) -> AnyRe
167178
config_manager.update(config)
168179
}
169180

170-
pub fn init<R: Runtime>() -> TauriPlugin<R> {
171-
let conf_path = get_storage_dir();
172-
let manager = HomeConfig::with_file(conf_path.join("config.toml"));
173-
let existing_config = manager.toml::<Config>();
174-
175-
let config = match existing_config {
176-
Ok(config) => ConfigManager {
177-
manager,
178-
data: RwLock::new(config),
179-
},
180-
Err(_) => {
181-
// The config does not exist, so let's instantiate it with defaults
182-
// Potential issue: if the config is extended, the defaults will be
183-
// reloaded
184-
let default_config = Config::default();
185-
manager.save_toml(&default_config).unwrap();
186-
187-
ConfigManager {
188-
manager,
189-
data: RwLock::new(default_config),
190-
}
191-
}
192-
};
193-
181+
pub fn init<R: Runtime>(config: ConfigManager) -> TauriPlugin<R> {
194182
// We need to inject the initial state of the config to the window object of
195183
// our webview, because some of our front-end modules are instantiated at
196184
// parsing time and require data that would otherwise only load-able asynchronously

src-tauri/src/plugins/cover.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::path::PathBuf;
22
use std::str::FromStr;
33

4-
use base64::prelude::{Engine as _, BASE64_STANDARD};
4+
use base64::prelude::{BASE64_STANDARD, Engine as _};
55
use lofty::file::TaggedFileExt;
66
use lofty::picture::{MimeType, PictureType};
7-
use tauri::plugin::{Builder, TauriPlugin};
87
use tauri::Runtime;
8+
use tauri::plugin::{Builder, TauriPlugin};
99

1010
use crate::libs::error::AnyResult;
1111
use crate::libs::utils::scan_dir;

0 commit comments

Comments
 (0)