52 lines
1.2 KiB
Rust
52 lines
1.2 KiB
Rust
use crate::process::ProcessId;
|
|
use crate::task::{TaskKind, TaskState};
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub struct TaskId(pub u32);
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Task {
|
|
pub id: TaskId,
|
|
pub process_id: ProcessId,
|
|
pub app_id: u32,
|
|
pub title: String,
|
|
pub kind: TaskKind,
|
|
pub state: TaskState,
|
|
}
|
|
|
|
impl Task {
|
|
pub fn new(
|
|
id: TaskId,
|
|
process_id: ProcessId,
|
|
app_id: u32,
|
|
title: impl Into<String>,
|
|
kind: TaskKind,
|
|
) -> Self {
|
|
Self { id, process_id, app_id, title: title.into(), kind, state: TaskState::Background }
|
|
}
|
|
|
|
pub fn mark_foreground(&mut self) {
|
|
self.state = TaskState::Foreground;
|
|
}
|
|
|
|
pub fn mark_background(&mut self) {
|
|
self.state = TaskState::Background;
|
|
}
|
|
|
|
pub fn mark_suspended(&mut self) {
|
|
self.state = TaskState::Suspended;
|
|
}
|
|
|
|
pub fn mark_closed(&mut self) {
|
|
self.state = TaskState::Closed;
|
|
}
|
|
|
|
pub fn mark_crashed(&mut self) {
|
|
self.state = TaskState::Crashed;
|
|
}
|
|
|
|
pub fn is_active(&self) -> bool {
|
|
matches!(self.state, TaskState::Foreground | TaskState::Background | TaskState::Suspended)
|
|
}
|
|
}
|