add linting CI jobs

This commit is contained in:
daniel.eades 2023-11-17 07:04:57 +00:00 committed by Ashley Wulber
parent 9974b2f99f
commit aa2d9fe374
12 changed files with 98 additions and 68 deletions

6
.github/dependabot.yml vendored Normal file
View file

@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily

29
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,29 @@
name: Continuous Integration
on: [push, pull_request]
jobs:
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- name: Run rustfmt
run: cargo +nightly fmt --all -- --check
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-11-18
components: clippy
- name: install dependencies
run: sudo apt install -y libxkbcommon-dev libwayland-dev libdbus-1-dev libpulse-dev
- uses: actions-rs-plus/clippy-check@v2
with:
toolchain: nightly-2023-11-18
args: --all --all-targets --all-features

2
.gitignore vendored
View file

@ -14,7 +14,7 @@ build-aux/.flatpak-builder/
flatpak_app
.flatpak-builder
.*
.vscode/
debian/*
!debian/*install
!debian/*postinst

View file

@ -336,9 +336,7 @@ fn index_in_list(
}
let total_len = list_len as f32 * (item_size + divider_size) - divider_size;
let pos_in_list = pos_in_list * total_len;
let index = if list_len == 0 {
0
} else if pos_in_list < item_size / 2.0 {
let index = if (list_len == 0) || (pos_in_list < item_size / 2.0) {
0
} else {
let mut i = 1;

View file

@ -27,10 +27,10 @@ pub struct PlayerStatus {
impl PlayerStatus {
async fn new(player: Player) -> Self {
let metadata = player.metadata().await.unwrap();
let title = metadata.title().map(|t| Cow::from(t));
let title = metadata.title().map(Cow::from);
let artists = metadata
.artists()
.map(|a| a.into_iter().map(|a| Cow::from(a)).collect::<Vec<_>>());
.map(|a| a.into_iter().map(Cow::from).collect::<Vec<_>>());
let icon = metadata
.art_url()
.and_then(|u| url::Url::parse(&u).ok())
@ -53,7 +53,7 @@ impl PlayerStatus {
icon,
title,
artists,
status: playback_status.unwrap_or_else(|_| PlaybackStatus::Stopped),
status: playback_status.unwrap_or(PlaybackStatus::Stopped),
can_pause: can_pause.unwrap_or_default(),
can_play: can_play.unwrap_or_default(),
can_go_previous: can_go_previous.unwrap_or_default(),
@ -109,33 +109,32 @@ async fn update(state: State, output: &mut futures::channel::mpsc::Sender<MprisU
.unwrap_or_else(|_| Vec::new());
if players.is_empty() {
let Ok(dbus) = zbus::fdo::DBusProxy::builder(&conn)
.path("/org/freedesktop/DBus").unwrap()
.path("/org/freedesktop/DBus")
.unwrap()
.build()
.await else {
tracing::error!("Failed to create dbus proxy.");
return State::Finished;
};
loop {
let Ok(mut stream) = dbus.receive_name_owner_changed().await else {
tracing::error!("Failed to receive name owner changed signal.");
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
// restart from the beginning
return State::Setup;
};
while let Some(c) = stream.next().await {
if let Ok(args) = c.args() {
if args.name.contains("org.mpris.MediaPlayer2") {
break;
}
.await
else {
tracing::error!("Failed to create dbus proxy.");
return State::Finished;
};
let Ok(mut stream) = dbus.receive_name_owner_changed().await else {
tracing::error!("Failed to receive name owner changed signal.");
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
// restart from the beginning
return State::Setup;
};
while let Some(c) = stream.next().await {
if let Ok(args) = c.args() {
if args.name.contains("org.mpris.MediaPlayer2") {
break;
}
}
if let Ok(p) = mpris2_zbus::media_player::MediaPlayer::new_all(&conn).await {
players = p;
break;
} else {
// restart from the beginning
return State::Setup;
}
}
if let Ok(p) = mpris2_zbus::media_player::MediaPlayer::new_all(&conn).await {
players = p;
} else {
// restart from the beginning
return State::Setup;
}
}

View file

@ -159,7 +159,7 @@ impl PulseHandle {
// Create pulse server thread, and bidirectional comms
pub fn new() -> Self {
let (to_pulse, mut to_pulse_recv) = tokio::sync::mpsc::channel(10);
let (mut from_pulse_send, from_pulse) = tokio::sync::mpsc::channel(10);
let (from_pulse_send, from_pulse) = tokio::sync::mpsc::channel(10);
// get initial connection status
to_pulse
.try_send(Message::UpdateConnection)
@ -195,7 +195,7 @@ impl PulseHandle {
.send(Message::SetDefaultSink(sink))
.await
.unwrap(),
Err(_) => Self::send_disconnected(&mut from_pulse_send).await,
Err(_) => Self::send_disconnected(&from_pulse_send).await,
}
}
Message::GetDefaultSource => {
@ -210,7 +210,7 @@ impl PulseHandle {
.unwrap(),
Err(e) => {
tracing::error!("ERROR! {:?}", e);
Self::send_disconnected(&mut from_pulse_send).await;
Self::send_disconnected(&from_pulse_send).await;
}
}
}
@ -224,7 +224,7 @@ impl PulseHandle {
.send(Message::SetSinks(sinks))
.await
.unwrap(),
Err(_) => Self::send_disconnected(&mut from_pulse_send).await,
Err(_) => Self::send_disconnected(&from_pulse_send).await,
}
}
Message::GetSources => {
@ -237,7 +237,7 @@ impl PulseHandle {
.send(Message::SetSources(sinks))
.await
.unwrap(),
Err(_) => Self::send_disconnected(&mut from_pulse_send).await,
Err(_) => Self::send_disconnected(&from_pulse_send).await,
}
}
Message::SetSinkVolumeByName(name, channel_volumes) => {
@ -263,7 +263,7 @@ impl PulseHandle {
tracing::trace!("getting server info...");
if cur_server.get_server_info().is_err() {
tracing::warn!("got error, server must be disconnected...");
Self::send_disconnected(&mut from_pulse_send).await;
Self::send_disconnected(&from_pulse_send).await;
} else {
tracing::trace!("got server info, still connected...");
server = Some(cur_server);
@ -272,7 +272,7 @@ impl PulseHandle {
match PulseServer::connect().and_then(|server| server.init()) {
Ok(new_server) => {
tracing::info!("Connected to server");
Self::send_connected(&mut from_pulse_send).await;
Self::send_connected(&from_pulse_send).await;
server = Some(new_server);
}
Err(err) => {

View file

@ -63,15 +63,15 @@ impl NewConnectionState {
}
}
impl Into<AccessPoint> for NewConnectionState {
fn into(self) -> AccessPoint {
match self {
Self::EnterPassword {
impl From<NewConnectionState> for AccessPoint {
fn from(connection_state: NewConnectionState) -> Self {
match connection_state {
NewConnectionState::EnterPassword {
access_point,
password: _,
} => access_point,
Self::Waiting(access_point) => access_point,
Self::Failure(access_point) => access_point,
NewConnectionState::Waiting(access_point) => access_point,
NewConnectionState::Failure(access_point) => access_point,
}
}
}

View file

@ -21,7 +21,7 @@ pub async fn active_connections(
let state = connection
.state()
.await
.unwrap_or_else(|_| ActiveConnectionState::Unknown);
.unwrap_or(ActiveConnectionState::Unknown);
if connection.vpn().await.unwrap_or_default() {
info.push(ActiveConnectionInfo::Vpn {

View file

@ -114,8 +114,7 @@ impl cosmic::Application for App {
])
}
status_notifier_watcher::Event::Unregistered(name) => {
if let Some((id, _)) =
self.menus.iter().find(|(_id, menu)| menu.name() == &name)
if let Some((id, _)) = self.menus.iter().find(|(_id, menu)| menu.name() == name)
{
let id = *id;
self.menus.remove(&id);

View file

@ -16,7 +16,7 @@ use std::time::Instant;
use tracing::error;
const ID: &str = "com.system76.CosmicAppletTiling";
const ON: &str = "com.system76.CosmicAppletTiling.On";
//const ON: &str = "com.system76.CosmicAppletTiling.On";
const OFF: &str = "com.system76.CosmicAppletTiling.Off";
static TILE_WINDOWS: Lazy<id::Toggler> = Lazy::new(id::Toggler::unique);

View file

@ -158,7 +158,7 @@ impl cosmic::Application for IcedWorkspacesApplet {
cosmic::theme::iced::Button::Primary
}
Some(zcosmic_workspace_handle_v1::State::Urgent) => {
let appearence = |theme: &Theme| button::Appearance {
let appearance = |theme: &Theme| button::Appearance {
background: Some(Background::Color(
theme.cosmic().palette.neutral_3.into(),
)),
@ -167,29 +167,29 @@ impl cosmic::Application for IcedWorkspacesApplet {
..button::Appearance::default()
};
cosmic::theme::iced::Button::Custom {
active: Box::new(appearence),
active: Box::new(appearance),
hover: Box::new(move |theme| button::Appearance {
background: Some(Background::Color(
theme.current_container().component.hover.into(),
)),
..appearence(theme)
..appearance(theme)
}),
}
}
None => {
let appearence = |theme: &Theme| button::Appearance {
let appearance = |theme: &Theme| button::Appearance {
background: None,
border_radius: theme.cosmic().radius_xl().into(),
text_color: theme.current_container().component.on.into(),
..button::Appearance::default()
};
cosmic::theme::iced::Button::Custom {
active: Box::new(appearence),
active: Box::new(appearance),
hover: Box::new(move |theme| button::Appearance {
background: Some(Background::Color(
theme.current_container().component.hover.into(),
)),
..appearence(theme)
..appearance(theme)
}),
}
}

View file

@ -71,23 +71,22 @@ pub fn main() -> iced::Result {
path.push(&filename);
if let Ok(bytes) = fs::read_to_string(&path) {
if let Ok(entry) = DesktopEntry::decode(&path, &bytes) {
desktop = Some(Desktop {
name: entry
.name(None)
.map(|x| x.to_string())
.expect(&format!("Desktop file '{filename}' doesn't have `Name`")),
icon: entry.icon().map(|x| x.to_string()),
exec: entry
.exec()
.map(|x| x.to_string())
.expect(&format!("Desktop file '{filename}' doesn't have `Exec`")),
});
desktop =
Some(Desktop {
name: entry.name(None).map(|x| x.to_string()).unwrap_or_else(|| {
panic!("Desktop file '{filename}' doesn't have `Name`")
}),
icon: entry.icon().map(|x| x.to_string()),
exec: entry.exec().map(|x| x.to_string()).unwrap_or_else(|| {
panic!("Desktop file '{filename}' doesn't have `Exec`")
}),
});
break;
}
}
}
let desktop = desktop.expect(&format!(
"Failed to find valid desktop file '{filename}' in search paths"
));
let desktop = desktop.unwrap_or_else(|| {
panic!("Failed to find valid desktop file '{filename}' in search paths")
});
cosmic::applet::run::<Button>(true, desktop)
}