Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Fix #24 + optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbtech committed Sep 19, 2020
1 parent a1c3e60 commit 225d7c1
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 19 deletions.
6 changes: 3 additions & 3 deletions core/AutocompleteSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function openSocket(){
}
}
else {
echo "ERROR: Unable to bind socket to '" . $this->socketpath . "'!" . PHP_EOL;
CLIOutput::error( CLIOutput::ERROR_FATAL, "ERROR: Unable to bind socket to '" . $this->socketpath . "'!");
}

}
Expand Down Expand Up @@ -183,7 +183,7 @@ public static function createSocketThread(){
}
}
else {
echo "INFO: Automatic Socket starting disabled!" . PHP_EOL;
CLIOutput::error( CLIOutput::ERROR_INFO, "Automatic Socket starting disabled!");
}
}

Expand All @@ -192,7 +192,7 @@ public static function getWinSocketFile() : string {
return getenv('USERPROFILE') . '/AppData/Local/Temp/TaskTimeTerminateAutocomplete.sock';
}
else{
echo "ERROR: Used windows socket path function (AutocompleteSocket::getWinSocketFile) on non-windows OS!" . PHP_EOL;
CLIOutput::error( CLIOutput::ERROR_FATAL, "Used windows socket path function (AutocompleteSocket::getWinSocketFile) on non-windows OS!");
return "";
}
}
Expand Down
22 changes: 21 additions & 1 deletion core/CLIOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,30 @@ class CLIOutput {
const WHITE = "\e[0;37m";
const RESET = "\e[0;0m";

public static function colorString($s, $color) : string {
const ERROR_WARN = 1;
const ERROR_INFO = 2;
const ERROR_FATAL = 3;

public static function colorString(string $s, string $color) : string {
return $color . $s . self::RESET;
}

public static function error(int $type, string $msg) : void {
$p = "";
switch ($type){
case self::ERROR_WARN:
$p = self::colorString("WARN", self::YELLOW);
break;
case self::ERROR_INFO:
$p = self::colorString("INFO", self::BLUE);
break;
case self::ERROR_FATAL:
$p = self::colorString("ERROR", self::RED);
break;
}
echo $p . ': "' . $msg . '"' . PHP_EOL;
}

public function __construct() {
$this->hello();
}
Expand Down
4 changes: 2 additions & 2 deletions core/Recorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(bool $inTerminal = false) {
AutocompleteSocket::createSocketThread();
break;
case Utilities::OS_LINUX:
MacDialog::checkOSPackages();
LinuxDialog::checkOSPackages();
$this->dialog = new LinuxDialog();
break;
case Utilities::OS_WIN:
Expand Down Expand Up @@ -96,7 +96,7 @@ private function saveTaskTime(JSONReader $r) : void {
));
}
else{
echo "WARN: Last task is already stored -- therefore TTT ignores it." . PHP_EOL;
CLIOutput::error(CLIOutput::ERROR_WARN, "Last task is already stored -- therefore TTT ignores it.");
}
// also save to sync
StatsLoader::saveDayTasks( $data->getArray() );
Expand Down
16 changes: 10 additions & 6 deletions core/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ class Time {

private const DEFAULT_FORMAT = 'dhm|s';
private const ALLOWED_PARTS = array(
'd' => 24*60*60,
'h' => 60*60,
'm' => 60,
's' => 1
'y' => 365*24*60*60, // year
't' => 30*24*60*60, // month (one of twelve)
'w' => 7*24*60*60, // week
'd' => 24*60*60, // day
'a' => 6*60*60, // work-day (8 hours)
'h' => 60*60, // hour
'm' => 60, // minute
's' => 1 // second
);
private const DELIMITER = '|';
private const PAD_VALUE = 4;
Expand Down Expand Up @@ -35,8 +39,8 @@ public function __construct() {
str_replace('||', '', $this->timeformat) === $this->timeformat;

if(!$ok){
$this->timeformat = self::DEFAULT_FORMAT;
echo "ERROR: Invalid timeformat in config.json" . PHP_EOL;
$this->timeformat = self::DEFAULT_FORMAT;
CLIOutput::error( CLIOutput::ERROR_WARN, "Invalid timeformat in config.json" );
}

// calculate pad
Expand Down
2 changes: 1 addition & 1 deletion core/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
class Utilities {

const VERSION = 'v1.0.0 rc';
const VERSION = 'v1.0.0 rc2';

/**
* OS Consts
Expand Down
2 changes: 1 addition & 1 deletion core/platform/Dialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function createCommandLineArgs(string $dialogPath) : string {
'-cats',
'"'. implode(',', $this->categories) .'"',
'-lastcat',
'"'.$this->categories[$this->chCategory ?? 0] .'"'
'"'.$this->categories[$this->chCategory ?? array_key_first($this->categories)] .'"'
);
if( !empty($this->chName)){
array_push($cmd,
Expand Down
10 changes: 7 additions & 3 deletions core/platform/WindowsDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public static function checkOSPackages() : void {
$zip->extractTo(__DIR__ . '/php-gtk/');
$zip->close();

// activate Sockets in PHP-GD
file_put_contents( __DIR__ . '/php-gtk/PHP55-GTK2/php.ini', PHP_EOL . 'extension = "php_sockets.dll"' . PHP_EOL, FILE_APPEND);

unlink(__DIR__ . '/d.zip');

exec(self::PHP_GTK_TEST, $output);
Expand All @@ -50,6 +47,13 @@ public static function checkOSPackages() : void {
die( PHP_EOL . 'Error downloading PHP-GTK!!' . PHP_EOL . PHP_EOL);
}
}

// check if Sockets in PHP-GD active
$iniActivate = PHP_EOL . 'extension = "php_sockets.dll"' . PHP_EOL;
$ini = file_get_contents( __DIR__ . '/php-gtk/PHP55-GTK2/php.ini' );
if( strpos($ini, $iniActivate) === false ){
file_put_contents( __DIR__ . '/php-gtk/PHP55-GTK2/php.ini', $iniActivate, FILE_APPEND);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
$socket = new AutocompleteSocket(AutocompleteSocket::getWinSocketFile());
break;
default:
echo "ERROR: Unable to create Socket on this OS!" . PHP_EOL;
CLIOutput::error( CLIOutput::ERROR_FATAL, "Unable to create Socket on this OS!" );
break;
}
}
else{
echo "ERROR: Socket Library not loaded in this installation!" . PHP_EOL;
CLIOutput::error( CLIOutput::ERROR_WARN, "Socket Library not loaded in this php installation!" );
}
?>

0 comments on commit 225d7c1

Please sign in to comment.