diff --git a/CHANGELOG.md b/CHANGELOG.md index 8454cc7..2be3e06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.2] + ### Added * Add `Duration` struct to ease usage of delays and other methods using string duration formats * Add Default impl for `Duration` @@ -27,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Moved `ComRuntime` to `planif::com` module ## [0.2.1] + ### Updated * Update documentation, add deny missing_docs diff --git a/Cargo.toml b/Cargo.toml index 961c3a0..a803e75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT" repository = "https://github.com/mattrobineau/planif" version = "1.0.0" edition = "2021" -keywords = ["scheduled", "task", "windows"] +keywords = ["scheduled", "task", "windows", "schedule", "scheduler"] categories = ["os::windows-apis"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/examples/boot_task.rs b/examples/boot_task.rs index d012467..a50b6b5 100644 --- a/examples/boot_task.rs +++ b/examples/boot_task.rs @@ -1,16 +1,16 @@ -use planif::enums::TaskCreationFlags; -use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; +// use planif::enums::TaskCreationFlags; +// use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; -fn main() -> Result<(), Box> { - let com = ComRuntime::new()?; - let sb = ScheduleBuilder::new(&com).unwrap(); - sb.create_boot() - .author("Matt")? - .description("Test Time Trigger")? - .trigger("test_time_trigger", true)? - .action(Action::new("test_time_action", "notepad.exe", "", ""))? - .start_boundary("2022-04-28T02:14:08.660633427+00:00")? - .build()? - .register("TimeTaskName", TaskCreationFlags::CreateOrUpdate as i32)?; - Ok(()) -} +// fn main() -> Result<(), Box> { +// let com = ComRuntime::new()?; +// let sb = ScheduleBuilder::new(&com).unwrap(); +// sb.create_boot() +// .author("Matt")? +// .description("Test Time Trigger")? +// .trigger("test_time_trigger", true)? +// .action(Action::new("test_time_action", "notepad.exe", "", ""))? +// .start_boundary("2022-04-28T02:14:08.660633427+00:00")? +// .build()? +// .register("TimeTaskName", TaskCreationFlags::CreateOrUpdate as i32)?; +// Ok(()) +// } diff --git a/examples/daily_task.rs b/examples/daily_task.rs index 4e0bafa..95e739d 100644 --- a/examples/daily_task.rs +++ b/examples/daily_task.rs @@ -1,20 +1,20 @@ -use chrono::prelude::*; -use planif::enums::TaskCreationFlags; -use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; +// use chrono::prelude::*; +// use planif::enums::TaskCreationFlags; +// use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; -fn main() -> Result<(), Box> { - let com = ComRuntime::new()?; +// fn main() -> Result<(), Box> { +// let com = ComRuntime::new()?; - let sb = ScheduleBuilder::new(&com).unwrap(); - sb.create_daily() - .author("Matt")? - .description("Test Trigger")? - .trigger("test_trigger", true)? - .days_interval(1)? - .action(Action::new("test", "notepad.exe", "", ""))? - .start_boundary(&Local::now().to_rfc3339())? - .build()? - .register("TaskName", TaskCreationFlags::CreateOrUpdate as i32)?; +// let sb = ScheduleBuilder::new(&com).unwrap(); +// sb.create_daily() +// .author("Matt")? +// .description("Test Trigger")? +// .trigger("test_trigger", true)? +// .days_interval(1)? +// .action(Action::new("test", "notepad.exe", "", ""))? +// .start_boundary(&Local::now().to_rfc3339())? +// .build()? +// .register("TaskName", TaskCreationFlags::CreateOrUpdate as i32)?; - Ok(()) -} +// Ok(()) +// } diff --git a/examples/folder_task.rs b/examples/folder_task.rs index ea9cc96..8d39e22 100644 --- a/examples/folder_task.rs +++ b/examples/folder_task.rs @@ -1,24 +1,24 @@ -use chrono::{Duration, Local}; -use planif::enums::TaskCreationFlags; -use planif::schedule_builder::{Action, ScheduleBuilder}; +// use chrono::{Duration, Local}; +// use planif::enums::TaskCreationFlags; +// use planif::schedule_builder::{Action, ScheduleBuilder}; -fn main() -> Result<(), Box> { - let sb = ScheduleBuilder::new().unwrap(); +// fn main() -> Result<(), Box> { +// let sb = ScheduleBuilder::new().unwrap(); - sb.create_time() - .author("Matt")? - .description("Test Time Trigger in folder")? - .in_folder("Test folder")? - .trigger("test_time_folder_trigger", true)? - .action(Action::new("test_time_action", "notepad.exe", "", ""))? - .start_boundary( - &Local::now() - .checked_add_signed(Duration::seconds(5)) - .unwrap() - .to_rfc3339(), - )? - .build()? - .register("Time Folder Task", TaskCreationFlags::CreateOrUpdate as i32)?; +// sb.create_time() +// .author("Matt")? +// .description("Test Time Trigger in folder")? +// .in_folder("Test folder")? +// .trigger("test_time_folder_trigger", true)? +// .action(Action::new("test_time_action", "notepad.exe", "", ""))? +// .start_boundary( +// &Local::now() +// .checked_add_signed(Duration::seconds(5)) +// .unwrap() +// .to_rfc3339(), +// )? +// .build()? +// .register("Time Folder Task", TaskCreationFlags::CreateOrUpdate as i32)?; - Ok(()) -} +// Ok(()) +// } diff --git a/examples/logon_task.rs b/examples/logon_task.rs index f85967e..af0fe6c 100644 --- a/examples/logon_task.rs +++ b/examples/logon_task.rs @@ -1,17 +1,17 @@ -use planif::enums::TaskCreationFlags; -use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; +// use planif::enums::TaskCreationFlags; +// use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; -fn main() -> Result<(), Box> { - let com = ComRuntime::new()?; - let sb = ScheduleBuilder::new(&com).unwrap(); - sb.create_logon() - .author("Matt")? - .description("Test Time Trigger")? - .trigger("test_time_trigger", true)? - .action(Action::new("test_time_action", "notepad.exe", "", ""))? - .start_boundary("2022-04-28T02:14:08.660633427+00:00")? - .user_id("")? - .build()? - .register("TimeTaskName", TaskCreationFlags::CreateOrUpdate as i32)?; - Ok(()) -} +// fn main() -> Result<(), Box> { +// let com = ComRuntime::new()?; +// let sb = ScheduleBuilder::new(&com).unwrap(); +// sb.create_logon() +// .author("Matt")? +// .description("Test Time Trigger")? +// .trigger("test_time_trigger", true)? +// .action(Action::new("test_time_action", "notepad.exe", "", ""))? +// .start_boundary("2022-04-28T02:14:08.660633427+00:00")? +// .user_id("")? +// .build()? +// .register("TimeTaskName", TaskCreationFlags::CreateOrUpdate as i32)?; +// Ok(()) +// } diff --git a/examples/monthly_dow_task.rs b/examples/monthly_dow_task.rs index 77d55c1..793e580 100644 --- a/examples/monthly_dow_task.rs +++ b/examples/monthly_dow_task.rs @@ -1,24 +1,24 @@ -use chrono::prelude::*; -use planif::enums::{DayOfWeek, Month, TaskCreationFlags, WeekOfMonth}; -use planif::schedule_builder::{Action, ComRuntime, MonthlyDOW, ScheduleBuilder}; +// use chrono::prelude::*; +// use planif::enums::{DayOfWeek, Month, TaskCreationFlags, WeekOfMonth}; +// use planif::schedule_builder::{Action, ComRuntime, MonthlyDOW, ScheduleBuilder}; -fn main() -> Result<(), Box> { - let com = ComRuntime::new()?; - let builder: ScheduleBuilder = ScheduleBuilder::new(&com)? - .create_monthly_dow() - .author("Matt")? - .description("Test Trigger")? - .trigger("MyTrigger", true)? - .action(Action::new("test", "notepad.exe", "", ""))? - .months_of_year(vec![Month::January])? - .days_of_week(vec![DayOfWeek::Monday])? - .weeks_of_month(vec![WeekOfMonth::First])? - .start_boundary(&Local::now().to_rfc3339())?; +// fn main() -> Result<(), Box> { +// let com = ComRuntime::new()?; +// let builder: ScheduleBuilder = ScheduleBuilder::new(&com)? +// .create_monthly_dow() +// .author("Matt")? +// .description("Test Trigger")? +// .trigger("MyTrigger", true)? +// .action(Action::new("test", "notepad.exe", "", ""))? +// .months_of_year(vec![Month::January])? +// .days_of_week(vec![DayOfWeek::Monday])? +// .weeks_of_month(vec![WeekOfMonth::First])? +// .start_boundary(&Local::now().to_rfc3339())?; - builder.build()?.register( - "MonthlyDOWTaskName", - TaskCreationFlags::CreateOrUpdate as i32, - )?; +// builder.build()?.register( +// "MonthlyDOWTaskName", +// TaskCreationFlags::CreateOrUpdate as i32, +// )?; - Ok(()) -} +// Ok(()) +// } diff --git a/examples/monthly_task.rs b/examples/monthly_task.rs index cf8a26b..9d521b0 100644 --- a/examples/monthly_task.rs +++ b/examples/monthly_task.rs @@ -1,22 +1,22 @@ -use chrono::prelude::*; -use planif::enums::{DayOfMonth, Month, TaskCreationFlags}; -use planif::schedule_builder::{Action, ComRuntime, Monthly, ScheduleBuilder}; +// use chrono::prelude::*; +// use planif::enums::{DayOfMonth, Month, TaskCreationFlags}; +// use planif::schedule_builder::{Action, ComRuntime, Monthly, ScheduleBuilder}; -fn main() -> Result<(), Box> { - let com = ComRuntime::new()?; - let builder: ScheduleBuilder = ScheduleBuilder::new(&com)? - .create_monthly() - .author("Matt")? - .description("Test Trigger")? - .trigger("MyTrigger", true)? - .action(Action::new("test", "notepad.exe", "", ""))? - .days_of_month(vec![DayOfMonth::Day(1), DayOfMonth::Day(15)])? - .months_of_year(vec![Month::December])? - .start_boundary(&Local::now().to_rfc3339())?; +// fn main() -> Result<(), Box> { +// let com = ComRuntime::new()?; +// let builder: ScheduleBuilder = ScheduleBuilder::new(&com)? +// .create_monthly() +// .author("Matt")? +// .description("Test Trigger")? +// .trigger("MyTrigger", true)? +// .action(Action::new("test", "notepad.exe", "", ""))? +// .days_of_month(vec![DayOfMonth::Day(1), DayOfMonth::Day(15)])? +// .months_of_year(vec![Month::December])? +// .start_boundary(&Local::now().to_rfc3339())?; - builder - .build()? - .register("MonthlyTaskName", TaskCreationFlags::CreateOrUpdate as i32)?; +// builder +// .build()? +// .register("MonthlyTaskName", TaskCreationFlags::CreateOrUpdate as i32)?; - Ok(()) -} +// Ok(()) +// } diff --git a/examples/multiple_tasks.rs b/examples/multiple_tasks.rs index fee6fce..11ace76 100644 --- a/examples/multiple_tasks.rs +++ b/examples/multiple_tasks.rs @@ -1,34 +1,34 @@ -use chrono::prelude::*; -use planif::enums::TaskCreationFlags; -use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; +// use chrono::prelude::*; +// use planif::enums::TaskCreationFlags; +// use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; -fn main() -> Result<(), Box> { - let com = ComRuntime::new()?; +// fn main() -> Result<(), Box> { +// let com = ComRuntime::new()?; - if true { - let sb = ScheduleBuilder::new(&com).unwrap(); - sb.create_daily() - .author("Matt")? - .description("Test Trigger 1")? - .trigger("test_trigger_1", true)? - .days_interval(1)? - .action(Action::new("test", "notepad.exe", "", ""))? - .start_boundary(&Local::now().to_rfc3339())? - .build()? - .register("TaskName1", TaskCreationFlags::CreateOrUpdate as i32)?; - } +// if true { +// let sb = ScheduleBuilder::new(&com).unwrap(); +// sb.create_daily() +// .author("Matt")? +// .description("Test Trigger 1")? +// .trigger("test_trigger_1", true)? +// .days_interval(1)? +// .action(Action::new("test", "notepad.exe", "", ""))? +// .start_boundary(&Local::now().to_rfc3339())? +// .build()? +// .register("TaskName1", TaskCreationFlags::CreateOrUpdate as i32)?; +// } - if true { - let sb2 = ScheduleBuilder::new(&com).unwrap(); - sb2.create_daily() - .author("Matt")? - .description("Test Trigger 2")? - .trigger("test_trigger_2", true)? - .days_interval(1)? - .action(Action::new("test", "notepad.exe", "", ""))? - .start_boundary(&Local::now().to_rfc3339())? - .build()? - .register("TaskName2", TaskCreationFlags::CreateOrUpdate as i32)?; - } - Ok(()) -} +// if true { +// let sb2 = ScheduleBuilder::new(&com).unwrap(); +// sb2.create_daily() +// .author("Matt")? +// .description("Test Trigger 2")? +// .trigger("test_trigger_2", true)? +// .days_interval(1)? +// .action(Action::new("test", "notepad.exe", "", ""))? +// .start_boundary(&Local::now().to_rfc3339())? +// .build()? +// .register("TaskName2", TaskCreationFlags::CreateOrUpdate as i32)?; +// } +// Ok(()) +// } diff --git a/examples/various_settings_task.rs b/examples/various_settings_task.rs index 0961426..65dcf5c 100644 --- a/examples/various_settings_task.rs +++ b/examples/various_settings_task.rs @@ -1,28 +1,24 @@ -use chrono::prelude::*; -use planif::enums::TaskCreationFlags; -<<<<<<< HEAD -use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; -======= -use planif::schedule_builder::{Action, ScheduleBuilder}; ->>>>>>> origin/main -use planif::settings::Settings; +// use chrono::prelude::*; +// use planif::enums::TaskCreationFlags; +// use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; +// use planif::settings::Settings; -fn main() -> Result<(), Box> { - let com = ComRuntime::new()?; - let sb = ScheduleBuilder::new(&com).unwrap(); - let mut settings = Settings::new(); - settings.run_only_if_idle = Some(true); +// fn main() -> Result<(), Box> { +// let com = ComRuntime::new()?; +// let sb = ScheduleBuilder::new(&com).unwrap(); +// let mut settings = Settings::new(); +// settings.run_only_if_idle = Some(true); - sb.create_daily() - .author("Matt")? - .description("Test Trigger")? - .settings(settings)? - .trigger("test_trigger", true)? - .days_interval(1)? - .action(Action::new("test", "notepad.exe", "", ""))? - .start_boundary(&Local::now().to_rfc3339())? - .build()? - .register("TaskName", TaskCreationFlags::CreateOrUpdate as i32)?; +// sb.create_daily() +// .author("Matt")? +// .description("Test Trigger")? +// .settings(settings)? +// .trigger("test_trigger", true)? +// .days_interval(1)? +// .action(Action::new("test", "notepad.exe", "", ""))? +// .start_boundary(&Local::now().to_rfc3339())? +// .build()? +// .register("TaskName", TaskCreationFlags::CreateOrUpdate as i32)?; - Ok(()) -} +// Ok(()) +// } diff --git a/examples/weekly_task.rs b/examples/weekly_task.rs index 83de740..06f8af9 100644 --- a/examples/weekly_task.rs +++ b/examples/weekly_task.rs @@ -1,19 +1,19 @@ -use chrono::prelude::*; -use planif::enums::{ DayOfWeek, TaskCreationFlags }; -use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; +// use chrono::prelude::*; +// use planif::enums::{ DayOfWeek, TaskCreationFlags }; +// use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder}; -fn main() -> Result<(), Box> { - let com = ComRuntime::new()?; - let sb = ScheduleBuilder::new(&com).unwrap(); - sb.create_weekly() - .author("Matt")? - .description("Test Weekly Trigger")? - .trigger("test_weekly_trigger", true)? - .action(Action::new("test", "notepad.exe", "", ""))? - .start_boundary(&Local::now().to_rfc3339())? - .days_of_week(vec![DayOfWeek::Sunday, DayOfWeek::Thursday])? - .weeks_interval(3)? - .build()? - .register("WeeklyTaskName", TaskCreationFlags::CreateOrUpdate as i32)?; - Ok(()) -} +// fn main() -> Result<(), Box> { +// let com = ComRuntime::new()?; +// let sb = ScheduleBuilder::new(&com).unwrap(); +// sb.create_weekly() +// .author("Matt")? +// .description("Test Weekly Trigger")? +// .trigger("test_weekly_trigger", true)? +// .action(Action::new("test", "notepad.exe", "", ""))? +// .start_boundary(&Local::now().to_rfc3339())? +// .days_of_week(vec![DayOfWeek::Sunday, DayOfWeek::Thursday])? +// .weeks_interval(3)? +// .build()? +// .register("WeeklyTaskName", TaskCreationFlags::CreateOrUpdate as i32)?; +// Ok(()) +// } diff --git a/src/lib.rs b/src/lib.rs index 3227c5a..3d40578 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,20 +48,22 @@ pub mod schedule; pub mod schedule_builder; /// Various settings available while building [Schedules](schedule::Schedule). pub mod settings; +/// The base struct used to manage all the others. +pub mod task_scheduler; /// Com pub mod com; #[cfg(test)] mod tests { + use chrono::{Duration, Local}; + + use crate::{task_scheduler::{TaskScheduler}, enums::TaskCreationFlags, schedule_builder::Action}; #[test] fn it_works() -> Result<(), Box> { - use crate::enums::TaskCreationFlags; - use crate::schedule_builder::{Action, ScheduleBuilder}; - use chrono::prelude::*; - use chrono::Duration; - - ScheduleBuilder::new()? + let ts = TaskScheduler::new(); + ts + .create_schedule() .create_time() .author("Test dummy")? .description("Test Time Trigger")? @@ -77,6 +79,13 @@ mod tests { .build()? .register("TimeTaskName", TaskCreationFlags::CreateOrUpdate as i32)?; + println!("{}", ts.get_schedule("\\Test folder\\TimeTaskName").path()); + + // ts.get_schedules_from_folder("Mozilla") + // .unwrap() + // .into_iter() + // .for_each(|x| println!("{}", x.path())); + Ok(()) } } diff --git a/src/schedule.rs b/src/schedule.rs index 2175158..2124fcb 100644 --- a/src/schedule.rs +++ b/src/schedule.rs @@ -1,29 +1,37 @@ use windows::core::BSTR; use windows::Win32::System::TaskScheduler::{ - IActionCollection, IRegistrationInfo, ITaskDefinition, ITaskFolder, ITaskService, + IActionCollection, IRegistrationInfo, ITaskDefinition, ITaskFolder, ITaskSettings, ITrigger, ITriggerCollection, TASK_LOGON_INTERACTIVE_TOKEN, }; use windows::Win32::System::Com::VARIANT; use crate::com::ComRuntime; +/// Marker type for base [`Schedule`] +pub struct Unregistered {} + +/// Marker type for registered [`Schedule`] +pub struct Registered {} + #[derive(Debug, PartialEq)] /// A schedule is created by a [schedule builder](crate::schedule_builder). Once created, the /// Schedule can be registered with the Windows Task Scheduler. -pub struct Schedule { +pub struct Schedule { + pub(crate) kind: std::marker::PhantomData, pub(crate) task_folder: ITaskFolder, pub(crate) actions: IActionCollection, pub(crate) force_start_boundary: bool, - pub(crate) registration_info: IRegistrationInfo, + pub(crate) registration_info: IRegistrationInfo, // maybe just this? since taskdef can come form it pub(crate) settings: ITaskSettings, - pub(crate) task_definition: ITaskDefinition, - pub(crate) task_service: ITaskService, + pub(crate) task_definition: ITaskDefinition, + // pub(crate) task_service: ITaskService, pub(crate) trigger: Option, pub(crate) triggers: ITriggerCollection, + pub(crate) com_runtime: ComRuntime, //repetition: IRepetitionPattern, } -impl Schedule { +impl Schedule { /// Registers the schedule. Flags can be set by using the [TaskCreationFlags](crate::enums::TaskCreationFlags) enum. pub fn register(self, task_name: &str, flags: i32) -> Result<(), Box> { unsafe { @@ -38,7 +46,7 @@ impl Schedule { VARIANT::default(), )?; } - + Ok(()) } } @@ -76,3 +84,18 @@ impl TaskScheduler { self.com.clone() } } + +impl Schedule { + /// more test + pub fn path(&self) -> String { + unsafe { + self.task_folder.Path().unwrap().to_string() + } + } + + pub fn delete(self) { + unsafe { + self.task_folder.DeleteTask(self.) + } + } +} \ No newline at end of file diff --git a/src/schedule_builder.rs b/src/schedule_builder.rs index 3be3936..4a222a5 100644 --- a/src/schedule_builder.rs +++ b/src/schedule_builder.rs @@ -1,10 +1,14 @@ use crate::{ enums::{DayOfMonth, DayOfWeek, Month, WeekOfMonth}, error::{InvalidOperationError, RequiredPropertyError}, - schedule::Schedule, - settings::{Duration, PrincipalSettings, Settings}, + schedule::{Schedule, Unregistered}, + settings::{Duration, PrincipalSettings, Settings}, task_scheduler::ComRuntime, com::ComRuntime, }; + +use windows::core::ComInterface; +use windows::core::BSTR; +use windows::Win32::Foundation::VARIANT_BOOL; use windows::Win32::System::Com::{ CoCreateInstance, CLSCTX_ALL, VARIANT, }; @@ -14,8 +18,7 @@ use windows::Win32::System::TaskScheduler::{ IAction, IActionCollection, IBootTrigger, IDailyTrigger, IEventTrigger, IExecAction, IIdleTrigger, ILogonTrigger, IMonthlyDOWTrigger, IMonthlyTrigger, INetworkSettings, IPrincipal, IRegistrationInfo, IRegistrationTrigger, IRepetitionPattern, ITaskDefinition, ITaskFolder, - ITaskService, ITaskSettings, ITimeTrigger, ITrigger, ITriggerCollection, IWeeklyTrigger, - TaskScheduler, TASK_ACTION_EXEC, TASK_LOGON_TYPE, TASK_RUNLEVEL_TYPE, TASK_TRIGGER_BOOT, + ITaskService, ITaskSettings, ITimeTrigger, ITrigger, ITriggerCollection, IWeeklyTrigger, TASK_ACTION_EXEC, TASK_LOGON_TYPE, TASK_RUNLEVEL_TYPE, TASK_TRIGGER_BOOT, TASK_TRIGGER_DAILY, TASK_TRIGGER_EVENT, TASK_TRIGGER_IDLE, TASK_TRIGGER_LOGON, TASK_TRIGGER_MONTHLY, TASK_TRIGGER_MONTHLYDOW, TASK_TRIGGER_REGISTRATION, TASK_TRIGGER_TIME, TASK_TRIGGER_WEEKLY, @@ -51,7 +54,8 @@ pub struct Weekly {} pub struct ScheduleBuilder { pub(crate) frequency: std::marker::PhantomData, pub(crate) schedule: Schedule, - com: ComRuntime, + com_runtime: ComRuntime, + task_service: ITaskService } impl ScheduleBuilder { @@ -64,17 +68,20 @@ impl ScheduleBuilder { /// let com = ComRuntime::new()?; /// let builder: ScheduleBuilder = ScheduleBuilder::new(&com).unwrap(); /// ``` - pub fn new(com: &ComRuntime) -> Result> { + pub fn new(com_runtime: &ComRuntime, task_service: &ITaskService) -> Result> { unsafe { - let sb_com = com.clone(); + let sb_com_rt = com_runtime.clone(); + let sb_ts = task_service.clone(); + + let sch_com_rt = com_runtime.clone(); - let task_service: ITaskService = CoCreateInstance(&TaskScheduler, None, CLSCTX_ALL)?; - task_service.Connect( - VARIANT::default(), - VARIANT::default(), - VARIANT::default(), - VARIANT::default(), - )?; + // let task_service: ITaskService = CoCreateInstance(&TaskScheduler, None, CLSCTX_ALL)?; + // task_service.Connect( + // VARIANT::default(), + // VARIANT::default(), + // VARIANT::default(), + // VARIANT::default(), + // )?; let task_folder: ITaskFolder = task_service.GetFolder(&BSTR::from("\\"))?; let task_definition: ITaskDefinition = task_service.NewTask(0)?; @@ -84,18 +91,21 @@ impl ScheduleBuilder { let settings: ITaskSettings = task_definition.Settings()?; Ok(Self { - com: sb_com, + com_runtime: sb_com_rt, frequency: std::marker::PhantomData::, + task_service: sb_ts, schedule: Schedule { + kind: std::marker::PhantomData::, task_folder, actions, force_start_boundary: false, registration_info, settings, - task_service, + // task_service, task_definition, trigger: None, triggers, + com_runtime: sch_com_rt }, }) } @@ -114,9 +124,10 @@ impl ScheduleBuilder { /// ``` pub fn create_boot(self) -> ScheduleBuilder { ScheduleBuilder:: { - com: self.com, + com_runtime: self.com_runtime, frequency: std::marker::PhantomData::, schedule: self.schedule, + task_service: self.task_service } } @@ -134,9 +145,10 @@ impl ScheduleBuilder { pub fn create_daily(mut self) -> ScheduleBuilder { self.schedule.force_start_boundary = true; ScheduleBuilder:: { - com: self.com, + com_runtime: self.com_runtime, frequency: std::marker::PhantomData::, schedule: self.schedule, + task_service: self.task_service } } @@ -154,9 +166,10 @@ impl ScheduleBuilder { pub fn create_event(mut self) -> ScheduleBuilder { self.schedule.force_start_boundary = true; ScheduleBuilder:: { - com: self.com, + com_runtime: self.com_runtime, frequency: std::marker::PhantomData::, schedule: self.schedule, + task_service: self.task_service } } @@ -173,9 +186,10 @@ impl ScheduleBuilder { /// ``` pub fn create_idle(self) -> ScheduleBuilder { ScheduleBuilder:: { - com: self.com, + com_runtime: self.com_runtime, frequency: std::marker::PhantomData::, schedule: self.schedule, + task_service: self.task_service } } @@ -192,9 +206,10 @@ impl ScheduleBuilder { /// ``` pub fn create_logon(self) -> ScheduleBuilder { ScheduleBuilder:: { - com: self.com, + com_runtime: self.com_runtime, frequency: std::marker::PhantomData::, schedule: self.schedule, + task_service: self.task_service } } @@ -210,9 +225,10 @@ impl ScheduleBuilder { /// ``` pub fn create_monthly(self) -> ScheduleBuilder { ScheduleBuilder:: { - com: self.com, + com_runtime: self.com_runtime, frequency: std::marker::PhantomData::, schedule: self.schedule, + task_service: self.task_service } } @@ -229,9 +245,10 @@ impl ScheduleBuilder { pub fn create_monthly_dow(mut self) -> ScheduleBuilder { self.schedule.force_start_boundary = true; ScheduleBuilder:: { - com: self.com, + com_runtime: self.com_runtime, frequency: std::marker::PhantomData::, schedule: self.schedule, + task_service: self.task_service } } @@ -247,9 +264,10 @@ impl ScheduleBuilder { /// ``` pub fn create_registration(self) -> ScheduleBuilder { ScheduleBuilder:: { - com: self.com, + com_runtime: self.com_runtime, frequency: std::marker::PhantomData::, schedule: self.schedule, + task_service: self.task_service } } @@ -267,9 +285,10 @@ impl ScheduleBuilder { pub fn create_time(mut self) -> ScheduleBuilder