Skip to content

Commit

Permalink
fix: format! formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Oct 6, 2024
1 parent 19f7702 commit 1491411
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn disable_hardware_accel_windows() {
let existing_args = std::env::var("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS").unwrap_or_default();
std::env::set_var(
"WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS",
format!("{} --disable-gpu", existing_args),
format!("{existing_args} --disable-gpu"),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/injection/client_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn load_mods_js() -> String {
continue;
}

exec = format!("{};{}", exec, result);
exec = format!("{exec};{result}");
}

exec
Expand Down Expand Up @@ -175,7 +175,7 @@ pub fn load_mods_css() -> String {
continue;
}

exec = format!("{} {}", exec, result);
exec = format!("{exec};{result}");
}

exec
Expand Down
14 changes: 4 additions & 10 deletions src-tauri/src/injection/injection_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,18 @@ pub fn load_plugins(win: &tauri::WebviewWindow, plugins: HashMap<String, String>
}
}

// Scuffed logging solution.
win
.eval(format!("console.log('Executing plugin: {}')", name).as_str())
.unwrap_or(());

// Execute the plugin in a try/catch, so we can capture whatever error occurs
win
.eval(
format!(
"
console.log('Executing plugin: {name}')
try {{
{}
{script}
}} catch(e) {{
console.error(`Plugin {} returned error: ${{e}}`)
console.error(`Plugin {name} returned error: ${{e}}`)
console.log('The plugin could still work! Just don\\'t expect it to.')
}}
",
script, name
}}"
)
.as_str(),
)
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/injection/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub fn get_themes() -> Result<String, String> {
let themes = get_theme_dir();
let mut all_contents = String::new();

for entry in fs::read_dir(themes).map_err(|e| format!("Error reading theme directory: {}", e))? {
let entry = entry.map_err(|e| format!("Error reading theme directory: {}", e))?;
for entry in fs::read_dir(themes).map_err(|e| format!("Error reading theme directory: {e}"))? {
let entry = entry.map_err(|e| format!("Error reading theme directory: {e}"))?;
let file_name = entry
.file_name()
.to_str()
Expand All @@ -37,7 +37,7 @@ pub fn get_themes() -> Result<String, String> {
pub fn get_theme_names() -> Result<Vec<String>, String> {
let themes_dir = get_theme_dir();
let theme_folders =
fs::read_dir(themes_dir).map_err(|e| format!("Error reading theme directory: {}", e))?;
fs::read_dir(themes_dir).map_err(|e| format!("Error reading theme directory: {e}"))?;
let names = theme_folders
.filter_map(|entry| {
entry.ok().and_then(|file| {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn main() {
if client_type == "default" {
url += "https://discord.com/app";
} else {
url = format!("https://{}.discord.com/app", client_type);
url = format!("https://{client_type}.discord.com/app");
}

let parsed = reqwest::Url::parse(&url).unwrap();
Expand Down
12 changes: 6 additions & 6 deletions src-tauri/src/processors/css_preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn localize_imports(win: tauri::WebviewWindow, css: String, name: String) ->
if get_config().cache_css.unwrap_or(true) {
let cache_path = get_theme_dir().join("cache");

let cache_file = cache_path.join(format!("{}_cache.css", name));
let cache_file = cache_path.join(format!("{name}_cache.css"));

if fs::metadata(&cache_file).is_ok() {
log!("Using cached CSS for {}", name);
Expand Down Expand Up @@ -154,7 +154,7 @@ pub fn localize_imports(win: tauri::WebviewWindow, css: String, name: String) ->
fs::create_dir(&cache_path).expect("Failed to create cache directory!");
}

let cache_file = cache_path.join(format!("{}_cache.css", name));
let cache_file = cache_path.join(format!("{name}_cache.css"));

fs::write(cache_file, new_css.clone()).expect("Failed to write cache file!");
}
Expand Down Expand Up @@ -194,8 +194,8 @@ pub fn localize_imports(_win: tauri::WebviewWindow, css: String, _name: String)

// Now add all the @import statements to the top
for import in seen_imports {
let import = format!("@import url(\"https://{}\");", import);
new_css = format!("{}\n{}", import, new_css);
let import = format!("@import url(\"https://{import}\");");
new_css = format!("{import}\n{new_css}");
}

new_css
Expand Down Expand Up @@ -225,7 +225,7 @@ pub fn localize_images(win: tauri::WebviewWindow, css: String) -> String {
win
.emit(
"loading_log",
format!("Too many images to process ({}), skipping...", count),
format!("Too many images to process ({count}), skipping...",),
)
.unwrap_or_default();
return new_css;
Expand Down Expand Up @@ -304,7 +304,7 @@ pub fn localize_images(win: tauri::WebviewWindow, css: String) -> String {

Some((
url.to_owned(),
format!("data:image/{};base64,{}", filetype, b64),
format!("data:image/{filetype};base64,{b64}"),
))
}));
}
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/processors/js_preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn eval_js_imports(window: &tauri::WebviewWindow, scripts: Vec<String>) {
for script in scripts {
match window.eval(script.as_str()) {
Ok(r) => r,
Err(e) => log(format!("Error evaluating import: {}", e)),
Err(e) => log(format!("Error evaluating import: {e}")),
};
}
}
2 changes: 1 addition & 1 deletion src-tauri/src/util/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn fetch_image(url: String) -> Option<String> {

let bytes = response.bytes().await.unwrap();
let base64 = general_purpose::STANDARD.encode(bytes);
let image = format!("data:{};base64,{}", content_type, base64);
let image = format!("data:{content_type};base64,{base64}");

Some(image)
}
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/util/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub unsafe fn set_notif_icon(_: &tauri::WebviewWindow, amount: i32) {
use objc2_foundation::{MainThreadMarker, NSString};

let label = if amount > 0 {
Some(NSString::from_str(&format!("{}", amount)))
Some(NSString::from_str(&format!("{amount}")))
} else if amount == -1 {
Some(NSString::from_str("●"))
} else {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/util/window_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn window_zoom_level(win: tauri::WebviewWindow, value: Option<f64>) {
);

win
.eval(&format!("document.body.style.zoom = '{}'", zoom))
.eval(&format!("document.body.style.zoom = '{zoom}'"))
.expect("Failed to set zoom level!");
}

Expand Down
9 changes: 4 additions & 5 deletions updater/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ pub fn get_release(user: impl AsRef<str>, repo: impl AsRef<str>) -> Result<Relea
.get(url)
.header("User-Agent", "Dorion")
.send()
.map_err(|e| format!("Failed to get latest release from GitHub: {}", e))?;
.map_err(|e| format!("Failed to get latest release from GitHub: {e}"))?;

let text = response
.text()
.map_err(|e| format!("Failed to read response text: {}", e))?;
.map_err(|e| format!("Failed to read response text: {e}"))?;

let release: Value =
serde_json::from_str(&text).map_err(|e| format!("Failed to parse JSON: {}", e))?;
serde_json::from_str(&text).map_err(|e| format!("Failed to parse JSON: {e}"))?;

let asset_array = release["assets"].as_array();

Expand Down Expand Up @@ -55,8 +55,7 @@ pub fn download_release(
path: PathBuf,
) -> PathBuf {
let url = format!(
"https://github.com/{}/{}/releases/download/{}/{}",
user, repo, tag_name, release_name
"https://github.com/{user}/{repo}/releases/download/{tag_name}/{release_name}",
);

let client = reqwest::blocking::Client::new();
Expand Down
2 changes: 1 addition & 1 deletion updater/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn reopen_as_elevated() {
// get program args (without first one) and join by ,
std::env::args()
.skip(1)
.map(|arg| format!("'\"{}\"'", arg))
.map(|arg| format!("'\"{arg}\"'"))
.collect::<Vec<String>>()
.join(",")
));
Expand Down

0 comments on commit 1491411

Please sign in to comment.