Repurpose FocusFriend to get AntiDrift off the ground.

This commit is contained in:
2022-06-21 21:29:31 -04:00
parent 1d40434bf0
commit 0eed43c915
5 changed files with 293 additions and 183 deletions

View File

@@ -1,33 +1,36 @@
import json
import os
import yaml
from pathlib import Path
from typing import List
from pydantic import BaseModel
class Block(BaseModel):
name: str = ''
prefix: str = ''
postfix: str = ''
items: List[str]
name: str
keywords: List[str]
def load(filename: str) -> List[Block]:
result = [Block(path=filename, **block) for block in block_list]
return result
class Config(BaseModel):
directory: str
blocks: List[Block]
start_as_user: bool = True
sleep_time: int = 1
aw_focus_cmd: str = "aw-focus"
window_names: str = "window_names.txt"
enforce_aw_commit: bool = True
blackblocks: List[Block]
whiteblocks: List[Block]
check_delay: int = 1
minimize_delay: int = 5
blackblocks_only: bool = True
class Config:
extra = 'forbid'
@classmethod
def load_config(cls, config_file: str) -> Config:
def load(cls, config_file: str) -> Config:
config_file = os.path.expanduser(config_file)
with open(config_file, 'r', encoding='utf8') as f:
config_dict = json.load(f)
with open(config_file, "r") as f:
config_dict = yaml.safe_load(f)
config = cls(**config_dict)
config.directory = os.path.expanduser(config.directory)
return config