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

Linux support #22

Merged
merged 4 commits into from
Sep 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: build

on: [push]

env:
CARGO_TERM_COLOR: always

jobs:
build_mac:
runs-on: macos-latest
Expand All @@ -26,3 +29,18 @@ jobs:
with:
name: windows
path: target/release/display_switch.exe

build_linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install build dependencies
run: sudo apt-get install libudev-dev
- name: Build
run: cargo build --verbose --release
- name: Run tests
run: cargo test --verbose
- uses: actions/upload-artifact@v1
with:
name: linux
path: target/release/display_switch
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ simplelog = "^0.8"
ddc = "^0.2"
rusb = "^0.6"

[target.'cfg(linux)'.dependencies]
[target.'cfg(target_os = "linux")'.dependencies]
ddc-hi = "^0.1"
ddc-i2c = "^0.2"
nvapi = "^0.1"

[target.'cfg(windows)'.dependencies]
[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "^0.3", features = ["winuser", "libloaderapi"] }
ddc-hi = "^0.1"
ddc-winapi = "^0.2"
34 changes: 18 additions & 16 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,29 @@ impl Configuration {
}

pub fn config_file_name() -> Result<std::path::PathBuf> {
#[cfg(target_os = "macos")]
let config_dir = dirs::preference_dir().ok_or(anyhow!("Config directory not found"))?;
#[cfg(target_os = "windows")]
let config_dir = dirs::config_dir()
.ok_or(anyhow!("Config directory not found"))?
.join("display-switch");
let config_dir = if cfg!(target_os = "macos") {
dirs::preference_dir().ok_or(anyhow!("Config directory not found"))?
} else {
dirs::config_dir()
.ok_or(anyhow!("Config directory not found"))?
.join("display-switch")
};
std::fs::create_dir_all(&config_dir)?;
Ok(config_dir.join("display-switch.ini"))
}

pub fn log_file_name() -> Result<std::path::PathBuf> {
#[cfg(target_os = "macos")]
let log_dir = dirs::home_dir()
.ok_or(anyhow!("Home directory not found"))?
.join("Library")
.join("Logs")
.join("display-switch");
#[cfg(target_os = "windows")]
let log_dir = dirs::data_local_dir()
.ok_or(anyhow!("Data-local directory not found"))?
.join("display-switch");
let log_dir = if cfg!(target_os = "macos") {
dirs::home_dir()
.ok_or(anyhow!("Home directory not found"))?
.join("Library")
.join("Logs")
.join("display-switch")
} else {
dirs::data_local_dir()
.ok_or(anyhow!("Data-local directory not found"))?
.join("display-switch")
};
std::fs::create_dir_all(&log_dir)?;
Ok(log_dir.join("display-switch.log"))
}
Expand Down