mirror of
https://codeberg.org/icewind/originfox.git
synced 2026-06-03 18:24:07 +02:00
prelim chrome support
This commit is contained in:
parent
41049a94d4
commit
c87c8c5682
2 changed files with 15 additions and 14 deletions
|
|
@ -3,14 +3,15 @@ use std::str::FromStr;
|
|||
|
||||
pub enum Browser {
|
||||
Firefox,
|
||||
#[allow(dead_code)]
|
||||
Chrome,
|
||||
}
|
||||
|
||||
impl Browser {
|
||||
pub fn manifest_path(&self, name: &str) -> PathBuf {
|
||||
pub fn manifest_path(&self) -> PathBuf {
|
||||
match self {
|
||||
Browser::Firefox => firefox_user_manifest(name),
|
||||
Browser::Chrome => chrome_user_manifest(name),
|
||||
Browser::Firefox => firefox_user_manifest(),
|
||||
Browser::Chrome => chrome_user_manifest(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,7 +22,7 @@ impl FromStr for Browser {
|
|||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"firefox" => Ok(Browser::Firefox),
|
||||
"chomrium" | "chrome" => Ok(Browser::Chrome),
|
||||
// "chomrium" | "chrome" => Ok(Browser::Chrome),
|
||||
_ => Err("unsupported browser"),
|
||||
}
|
||||
}
|
||||
|
|
@ -34,18 +35,16 @@ fn unix_home_dir() -> PathBuf {
|
|||
.expect("HOME not set")
|
||||
}
|
||||
|
||||
fn chrome_user_manifest(name: &str) -> PathBuf {
|
||||
fn chrome_user_manifest() -> PathBuf {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
unix_home_dir()
|
||||
.join("Library/Application Support/Google/Chrome/NativeMessagingHosts")
|
||||
.join(format!("{name}.json"))
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
unix_home_dir()
|
||||
.join(".config/google-chrome/NativeMessagingHosts")
|
||||
.join(format!("{name}.json"))
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
|
|
@ -53,22 +52,19 @@ fn chrome_user_manifest(name: &str) -> PathBuf {
|
|||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| PathBuf::from(r"C:\Users\Default\AppData\Local"))
|
||||
.join("NativeMessagingHosts")
|
||||
.join(format!("{name}.json"))
|
||||
}
|
||||
}
|
||||
|
||||
fn firefox_user_manifest(name: &str) -> PathBuf {
|
||||
fn firefox_user_manifest() -> PathBuf {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
unix_home_dir()
|
||||
.join("Library/Application Support/Mozilla/NativeMessagingHosts")
|
||||
.join(format!("{name}.json"))
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
unix_home_dir()
|
||||
.join(".mozilla/native-messaging-hosts")
|
||||
.join(format!("{name}.json"))
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
|
|
@ -76,6 +72,5 @@ fn firefox_user_manifest(name: &str) -> PathBuf {
|
|||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| PathBuf::from(r"C:\Users\Default\AppData\Roaming"))
|
||||
.join("Mozilla\\NativeMessagingHosts")
|
||||
.join(format!("{name}.json"))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
src/main.rs
10
src/main.rs
|
|
@ -4,7 +4,7 @@ use main_error::MainResult;
|
|||
use owo_colors::OwoColorize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::env::{args, current_exe};
|
||||
use std::fs::write;
|
||||
use std::fs::{create_dir_all, write};
|
||||
use std::io::{Error as IoError, ErrorKind, IsTerminal, Read, Write, stdin, stdout};
|
||||
use std::str::FromStr;
|
||||
use crate::install::Browser;
|
||||
|
|
@ -23,10 +23,16 @@ fn main() -> MainResult {
|
|||
}
|
||||
"install-manifest" => {
|
||||
let browser = Browser::from_str(&args.next().unwrap_or_default())?;
|
||||
let manifest_dir = browser.manifest_path();
|
||||
create_dir_all(&manifest_dir)?;
|
||||
write(
|
||||
browser.manifest_path("originfox"),
|
||||
manifest_dir.join("originfox.json"),
|
||||
generate_manifest()?,
|
||||
)?;
|
||||
println!("Manifest installed");
|
||||
println!();
|
||||
println!("Note that the installed manifest includes the absolute path to this binary.");
|
||||
println!("If you move this binary you'll need to re-install the manifest.");
|
||||
return Ok(());
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue