Skip to content

Commit

Permalink
fix: firefox scaffolding and custom profiles dir
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Feb 15, 2024
1 parent 7e9e411 commit 91c923c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion ext/mv2/after.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class FlooedApi {
ws = null;
version = null;
Expand Down
7 changes: 7 additions & 0 deletions src/compat/firefox.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use webui_rs::webui::bindgen::*;

Check failure on line 1 in src/compat/firefox.rs

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

unused import: `webui_rs::webui::bindgen::*`

Check failure on line 1 in src/compat/firefox.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-20.04)

unused import: `webui_rs::webui::bindgen::*`

Check failure on line 1 in src/compat/firefox.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

unused import: `webui_rs::webui::bindgen::*`

pub unsafe fn move_firefox_extension() {
// Take the extension file (should be beside the binary)
let ext = std::env::current_dir().unwrap().join("ext").join("mv2.xpi");

Check failure on line 5 in src/compat/firefox.rs

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

unused variable: `ext`

Check warning on line 5 in src/compat/firefox.rs

View workflow job for this annotation

GitHub Actions / rustfmt (windows-latest)

Diff in \\?\D:\a\Flooed\Flooed\src\compat\firefox.rs

Check warning on line 5 in src/compat/firefox.rs

View workflow job for this annotation

GitHub Actions / rustfmt (ubuntu-20.04)

Diff in /home/runner/work/Flooed/Flooed/src/compat/firefox.rs

Check warning on line 5 in src/compat/firefox.rs

View workflow job for this annotation

GitHub Actions / rustfmt (macos-latest)

Diff in /Users/runner/work/Flooed/Flooed/src/compat/firefox.rs
// get the firefox profile path
}
1 change: 1 addition & 0 deletions src/compat/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod firefox;

Check warning on line 1 in src/compat/mod.rs

View workflow job for this annotation

GitHub Actions / rustfmt (ubuntu-20.04)

Diff in /home/runner/work/Flooed/Flooed/src/compat/mod.rs

Check warning on line 1 in src/compat/mod.rs

View workflow job for this annotation

GitHub Actions / rustfmt (macos-latest)

Diff in /Users/runner/work/Flooed/Flooed/src/compat/mod.rs
48 changes: 41 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,49 @@
windows_subsystem = "windows"
)]

mod compat;
mod config;
mod util;

use std::fs;

Check warning on line 10 in src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt (ubuntu-20.04)

Diff in /home/runner/work/Flooed/Flooed/src/main.rs

Check warning on line 10 in src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt (macos-latest)

Diff in /Users/runner/work/Flooed/Flooed/src/main.rs

use config::get_config;
use util::logger;
use util::{logger, paths::get_profile_dir};
use util::ws::WsConnector;
use webui_rs::webui::{wait, WebUIBrowser, Window};
//use webui_rs::webui::bindgen::webui_get_best_browser;
use webui_rs::webui::{bindgen::webui_set_profile, wait, WebUIBrowser, Window};

const VERSION: &str = env!("CARGO_PKG_VERSION");

fn main() {
logger::init(true);
let config = get_config();
let mut win = Window::new();
let browser = WebUIBrowser::ChromiumBased;
//let browser = unsafe { WebUIBrowser::from_usize(webui_get_best_browser(win.id)) };

Check warning on line 26 in src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt (windows-latest)

Diff in \\?\D:\a\Flooed\Flooed\src\main.rs

Check warning on line 26 in src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt (ubuntu-20.04)

Diff in /home/runner/work/Flooed/Flooed/src/main.rs

Check warning on line 26 in src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt (macos-latest)

Diff in /Users/runner/work/Flooed/Flooed/src/main.rs
// Ensure profile dir exists
let profile_dir = get_profile_dir(browser.to_usize());

if fs::metadata(&profile_dir).is_err() {
println!("Creating profile dir: {:?}", profile_dir);
fs::create_dir_all(&profile_dir).expect("Failed to create profile dir");
}

logger::log(format!("Profile dir: {:?}", profile_dir));

// Set the profile dir

Check warning on line 37 in src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt (windows-latest)

Diff in \\?\D:\a\Flooed\Flooed\src\main.rs

Check warning on line 37 in src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt (ubuntu-20.04)

Diff in /home/runner/work/Flooed/Flooed/src/main.rs

Check warning on line 37 in src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt (macos-latest)

Diff in /Users/runner/work/Flooed/Flooed/src/main.rs
unsafe {
let path_cstr = std::ffi::CString::new(
profile_dir.to_str().expect("Failed to convert profile dir to string"),
).expect("Failed to convert profile dir to CString");

webui_set_profile(
win.id,
"Flooed".as_ptr() as *const i8,
path_cstr.as_ptr() as *const i8,

Check failure on line 46 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

casting raw pointers to the same type and constness is unnecessary (`*const i8` -> `*const i8`)
);
}

let client = match config.client_type.unwrap_or("default".to_string()).as_str() {
"default" => "https://discord.com/app",
Expand All @@ -33,11 +62,16 @@ fn main() {

// Get current working dir
let cwd = std::env::current_dir().unwrap();
// Append ./ext
let ext = cwd.join("ext").join("mv2");

// This should load our extension
win.add_extension(ext.to_str().unwrap());
if browser == WebUIBrowser::Firefox {
unsafe {
compat::firefox::move_firefox_extension();
}
} else {
// Append ./ext
let ext = cwd.join("ext").join("mv2");
win.add_extension(ext.to_str().unwrap());
}

// Start the websocket connector
let mut ws = WsConnector::new();
Expand All @@ -47,7 +81,7 @@ fn main() {
ws.start();

// Start the browser
win.show_browser(client, WebUIBrowser::ChromiumBased);
win.show_browser(client, browser);

wait();
}
Expand Down
20 changes: 20 additions & 0 deletions src/util/paths.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{fs, path::PathBuf};

use webui_rs::webui::WebUIBrowser;

Check failure on line 3 in src/util/paths.rs

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

unused import: `webui_rs::webui::WebUIBrowser`

Check failure on line 3 in src/util/paths.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-20.04)

unused import: `webui_rs::webui::WebUIBrowser`

Check failure on line 3 in src/util/paths.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

unused import: `webui_rs::webui::WebUIBrowser`

use crate::util::logger::log;

pub fn get_config_dir() -> PathBuf {
Expand Down Expand Up @@ -129,6 +131,24 @@ pub fn get_theme_dir() -> std::path::PathBuf {
theme_dir
}

pub fn get_profile_dir(browser: usize) -> PathBuf {
let current_exe = std::env::current_exe().unwrap_or_default();
let local_config_dir = current_exe.parent().unwrap().join("config.json");

if fs::metadata(local_config_dir).is_ok() {
// This is a portable install, so we can use the local injection dir
return current_exe.parent().unwrap().join("profile");
}

#[cfg(target_os = "windows")]
let appdata = dirs::data_dir().unwrap_or_default();

#[cfg(not(target_os = "windows"))]

Check warning on line 146 in src/util/paths.rs

View workflow job for this annotation

GitHub Actions / rustfmt (windows-latest)

Diff in \\?\D:\a\Flooed\Flooed\src\util\paths.rs

Check warning on line 146 in src/util/paths.rs

View workflow job for this annotation

GitHub Actions / rustfmt (ubuntu-20.04)

Diff in /home/runner/work/Flooed/Flooed/src/util/paths.rs

Check warning on line 146 in src/util/paths.rs

View workflow job for this annotation

GitHub Actions / rustfmt (macos-latest)

Diff in /Users/runner/work/Flooed/Flooed/src/util/paths.rs
let appdata = dirs::config_dir().unwrap_or_default();

appdata.join("flooed").join("profile").join(format!("{}", browser))
}

pub fn custom_detectables_path() -> PathBuf {

Check failure on line 152 in src/util/paths.rs

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

function `custom_detectables_path` is never used
let current_exe = std::env::current_exe().unwrap_or_default();
let local_config_dir = current_exe.parent().unwrap().join("config.json");
Expand Down

0 comments on commit 91c923c

Please sign in to comment.