Switch to new configuration file. Fix bug when finding window title.
This commit is contained in:
26
config.py
26
config.py
@@ -1,9 +1,10 @@
|
||||
import json
|
||||
import os
|
||||
from typing import List
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class BlockList(BaseModel):
|
||||
class Block(BaseModel):
|
||||
name: str = ''
|
||||
prefix: str = ''
|
||||
postfix: str = ''
|
||||
@@ -11,14 +12,21 @@ class BlockList(BaseModel):
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
directory: str
|
||||
blocks: List[Block]
|
||||
start_as_user: bool = True
|
||||
sleep_time: int = 1
|
||||
focusfriend_py: str = "focusfriend.py"
|
||||
window_names: str = "window_names.txt"
|
||||
|
||||
class Config:
|
||||
extra = 'forbid'
|
||||
|
||||
blocklists: List[BlockList]
|
||||
|
||||
|
||||
def load_config(config_file: str) -> Config:
|
||||
with open(config_file, 'r', encoding='utf8') as f:
|
||||
config_dict = json.load(f)
|
||||
return Config(**config_dict)
|
||||
|
||||
@classmethod
|
||||
def load_config(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)
|
||||
config = cls(**config_dict)
|
||||
config.directory = os.path.expanduser(config.directory)
|
||||
return config
|
||||
|
||||
Reference in New Issue
Block a user