| @@ 11-63 (lines=53) @@ | ||
| 8 | use Godbout\Alfred\Time\Menus\Menu; |
|
| 9 | use Godbout\Alfred\Workflow\ScriptFilter; |
|
| 10 | ||
| 11 | class SetupState extends Menu |
|
| 12 | { |
|
| 13 | public static function scriptFilter() |
|
| 14 | { |
|
| 15 | self::saveState(); |
|
| 16 | ||
| 17 | ScriptFilter::add( |
|
| 18 | self::stateSaved(), |
|
| 19 | self::back() |
|
| 20 | ); |
|
| 21 | } |
|
| 22 | ||
| 23 | private static function saveState() |
|
| 24 | { |
|
| 25 | Workflow::disableAllServices(); |
|
| 26 | ||
| 27 | self::toEnable() ? Workflow::enableService('harvest') : Workflow::disableService('harvest'); |
|
| 28 | } |
|
| 29 | ||
| 30 | private static function stateSaved() |
|
| 31 | { |
|
| 32 | return Item::create() |
|
| 33 | ->title(self::stateTitle()) |
|
| 34 | ->subtitle(self::stateSubtitle()) |
|
| 35 | ->icon(Icon::create('resources/icons/harvest.png')) |
|
| 36 | ->arg('do') |
|
| 37 | ->variable('timer_action', 'exit'); |
|
| 38 | } |
|
| 39 | ||
| 40 | private static function stateTitle() |
|
| 41 | { |
|
| 42 | return 'Harvest ' . (self::toEnable() ? 'ENABLED!' : 'DISABLED!'); |
|
| 43 | } |
|
| 44 | ||
| 45 | protected static function stateSubtitle() |
|
| 46 | { |
|
| 47 | return (self::toEnable() ? 'Other services disabled. ': '') . 'You may press enter to quit the workflow'; |
|
| 48 | } |
|
| 49 | ||
| 50 | private static function back() |
|
| 51 | { |
|
| 52 | return Item::create() |
|
| 53 | ->title('Back') |
|
| 54 | ->subtitle('Go back to Harvest options') |
|
| 55 | ->arg('harvest_setup') |
|
| 56 | ->icon(Icon::create('resources/icons/harvest.png')); |
|
| 57 | } |
|
| 58 | ||
| 59 | protected static function toEnable() |
|
| 60 | { |
|
| 61 | return getenv('harvest_enabled') === 'true'; |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| @@ 11-63 (lines=53) @@ | ||
| 8 | use Godbout\Alfred\Time\Menus\Menu; |
|
| 9 | use Godbout\Alfred\Workflow\ScriptFilter; |
|
| 10 | ||
| 11 | class SetupState extends Menu |
|
| 12 | { |
|
| 13 | public static function scriptFilter() |
|
| 14 | { |
|
| 15 | self::saveState(); |
|
| 16 | ||
| 17 | ScriptFilter::add( |
|
| 18 | self::stateSaved(), |
|
| 19 | self::back() |
|
| 20 | ); |
|
| 21 | } |
|
| 22 | ||
| 23 | private static function saveState() |
|
| 24 | { |
|
| 25 | Workflow::disableAllServices(); |
|
| 26 | ||
| 27 | self::toEnable() ? Workflow::enableService('toggl') : Workflow::disableService('toggl'); |
|
| 28 | } |
|
| 29 | ||
| 30 | private static function stateSaved() |
|
| 31 | { |
|
| 32 | return Item::create() |
|
| 33 | ->title(self::stateTitle()) |
|
| 34 | ->subtitle(self::stateSubtitle()) |
|
| 35 | ->icon(Icon::create('resources/icons/toggl.png')) |
|
| 36 | ->arg('do') |
|
| 37 | ->variable('timer_action', 'exit'); |
|
| 38 | } |
|
| 39 | ||
| 40 | private static function stateTitle() |
|
| 41 | { |
|
| 42 | return 'Toggl ' . (self::toEnable() ? 'ENABLED!' : 'DISABLED!'); |
|
| 43 | } |
|
| 44 | ||
| 45 | protected static function stateSubtitle() |
|
| 46 | { |
|
| 47 | return (self::toEnable() ? 'Other services disabled. ' : '') . 'You may press enter to quit the workflow'; |
|
| 48 | } |
|
| 49 | ||
| 50 | private static function back() |
|
| 51 | { |
|
| 52 | return Item::create() |
|
| 53 | ->title('Back') |
|
| 54 | ->subtitle('Go back to Toggl options') |
|
| 55 | ->arg('toggl_setup') |
|
| 56 | ->icon(Icon::create('resources/icons/toggl.png')); |
|
| 57 | } |
|
| 58 | ||
| 59 | protected static function toEnable() |
|
| 60 | { |
|
| 61 | return getenv('toggl_enabled') === 'true'; |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||