您是否購買了昂貴的 Timeular 追蹤器,但又不想為他們的專有應用程式付費?這個項目適合你。使用 Timeular Reader,您可以將追蹤器連接到您最喜歡的時間追蹤應用程式。
首先使用--setup
標誌來執行命令,這將產生配置並讓您標記裝置的側面。
timeular-reader --setup
您不必設定所有側面,在您不想使用的側面按 q,配置將使用您設定的側面產生。
初始設定後,您可以修改config.toml
要控制輸出的詳細程度,您可以傳遞--verbose
或-v
,您可以添加多個-vvv
以使其更詳細。
還有--quiet
、 -q
模式來靜音所有輸出。
若要取得專案 ID 和工作區 ID,請在左側面板的「管理」下按一下「專案」。然後點擊您要使用的項目名稱。網址應如下圖所示https://track.toggl.com/{workspace_id}/projects/{project_id}/team
要產生 api 密鑰,請前往右上角的個人資料設定。向下捲動後,您將看到產生 API 金鑰的選項。
要取得您的工作區 ID,請在右上角點擊“您的工作區”,前往“管理”,然後轉到“設定”,您應該在 url 中包含工作區 ID。它應該看起來像這樣https://app.clockify.me/workspaces/{workspace_id}/settings
注意項目 ID 是可選的
若要在左側取得您的項目 ID,請按一下項目,然後按一下您的項目。該 url 將包含項目 id。應該看起來像這樣https://app.clockify.me/projects/{project_id}/edit
待辦事項
待辦事項
首先,您需要建立一個新的 mod 並在此處註冊它,我們稱之為example
。
您可以透過建立檔案src/handler/example.rs
並新增pub mod example;
進入上面連結的檔案。 example.rs
必須有一個名為async create_handler(setup: bool)
的公共函數,而函數必須傳回一個實作Handler
結構#[async_trait]
您的模組很可能需要一些配置。您可以實現主example.rs
檔案中的所有內容,但為了保持乾淨,我建議聲明新的 mod config
。配置模組將負責建立預設配置並將其儲存到主設定檔config.toml
中。
首先我們需要加入pub mod config;
到example.rs
並建立檔案src/handler/example/config.rs
。在config.rs
中,我們需要建立一個結構體來保存我們需要的所有配置數據,我們稱之為ExampleConfig
。
派生是必要的
# [ derive ( Serialize , Deserialize , Clone , Debug ) ]
pub struct ExampleConfig {
base_url : String ,
api_key : String ,
}
然後我們需要實作Default
和crate::config::Config
。 Default
實作可以使用不會發生太大變化的內容來建立結構,例如 API 基本 url。例如:
impl Default for ExampleConfig {
fn default ( ) -> Self {
ExampleConfig {
base_url : String :: from ( "https://api.example.com" ) ,
api_key : String :: new ( ) ,
}
}
}
crate::config::Config
實作可以為空,它只是繼承類型和生命週期,它可以如下所示:
impl < ' de > Config < ' de > for ExampleConfig { }
如果您想將配置保存在主設定檔中,則需要有一個唯一的金鑰來保存它。
為了方便起見,您可以實現獲取和更新配置(從文件/到文件)的方法。否則,您將必須呼叫crate::config::get_config
和crate::config::update_config
。這些函數可以如下所示:
const CONFIG_KEY : & str = "example" ;
pub fn create_config ( ) -> ExampleConfig {
crate :: config :: get_config :: < ExampleConfig > ( CONFIG_KEY )
}
pub fn update_config ( config : & ExampleConfig ) {
crate :: config :: update_config ( CONFIG_KEY , config ) ;
}
之後我們需要註冊新的處理程序。在src/handler.rs
中,您需要將我們的 mod Example
新增至Handlers
枚舉中並為其指派編號。
pub enum Handlers {
Toggl = 1,
Clockify = 2,
Traggo = 3,
Hackaru = 4,
+ Example = 5,
}
然後我們需要調整TryFrom<u8>
:
fn try_from(v: u8) -> Result<Self, Self::Error> {
match v {
x if x == Handlers::Toggl as u8 => Ok(Handlers::Toggl),
x if x == Handlers::Clockify as u8 => Ok(Handlers::Clockify),
x if x == Handlers::Traggo as u8 => Ok(Handlers::Traggo),
x if x == Handlers::Hackaru as u8 => Ok(Handlers::Hackaru),
+ x if x == Handlers::Example as u8 => Ok(Handlers::Example),
_ => Err(()),
}
}
TryFrom<&String>
中相同:
fn try_from(v: &String) -> Result<Self, Self::Error> {
match v.as_str() {
"toggl" => Ok(Handlers::Toggl),
"clockify" => Ok(Handlers::Clockify),
"traggo" => Ok(Handlers::Traggo),
"hackaru" => Ok(Handlers::Hackaru),
+ "example" => Ok(Handlers::Example),
_ => Err(()),
}
}
最後要做的是調整工廠方法,在get_handler
:
pub async fn get_handler(setup: bool, config: &TimeularConfig) -> Box<dyn Handler> {
match config.handler.as_str() {
"toggl" => Box::new(toggl::create_handler(setup).await),
"hackaru" => Box::new(hackaru::create_handler(setup).await),
"clockify" => Box::new(clockify::create_handler(setup).await),
"traggo" => Box::new(traggo::create_handler(setup).await),
+ "example" => Box::new(example::create_handler(setup).await),
_ => Box::new(example::create_handler(setup).await),
}
}
我已將範例追蹤器新增至儲存庫中,您可以在此基礎上建立您的模組。
只需運行
cargo build