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

Commit fe75817

Browse files
committed
Linux better dialog open command handling & recorder starts only once
1 parent 393efde commit fe75817

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

core/Recorder.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
class Recorder {
33

4+
const PID_FILE = '/run/lock/TaskTimeTerminate';
5+
46
public Dialog $dialog;
57

68
public function __construct(bool $inTerminal = false) {
@@ -91,5 +93,31 @@ private function recordNew(JSONReader $r) : void {
9193
$r->setValue(['end'], -1 );
9294
}
9395
}
96+
97+
public static function runOnlyOnce() : void {
98+
if( Utilities::getOS() === Utilities::OS_LINUX ){
99+
$pid = getmypid();
100+
if( $pid !== false ){
101+
// check if other running
102+
if( is_file( self::PID_FILE ) ){
103+
$otherPid = file_get_contents(self::PID_FILE);
104+
if( is_numeric($otherPid) ){
105+
if( !posix_kill( intval($otherPid), SIGQUIT ) ){
106+
posix_kill( intval($otherPid), SIGKILL );
107+
}
108+
}
109+
}
110+
// set yourself running
111+
file_put_contents( self::PID_FILE, $pid, LOCK_EX );
112+
113+
// delete run file on exit
114+
register_shutdown_function( function ($pid) {
115+
if( is_file( self::PID_FILE ) && file_get_contents(self::PID_FILE) == $pid ){
116+
unlink(self::PID_FILE);
117+
}
118+
}, $pid);
119+
}
120+
}
121+
}
94122
}
95123
?>

core/Utilities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
class Utilities {
66

7-
const VERSION = 'v0.8.0 alpha';
7+
const VERSION = 'v0.8.1 alpha';
88

99
/**
1010
* OS Consts

core/platform/LinuxDialog.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ public function open() : void {
2424
'2> /dev/null'
2525
);
2626

27-
exec(implode(' ', $cmd), $stdout, $return);
27+
$handle = popen(implode(' ', $cmd), 'r');
28+
$stdout = fgets($handle);
29+
pclose($handle);
2830

29-
if( $return === 0 && !empty($stdout) ){
30-
$stdout = explode(' ', $stdout[0]);
31+
if( !empty($stdout) ){
32+
$stdout = explode(' ', trim($stdout));
3133

3234
if( count($stdout) !== 3 ){
3335
$this->open();

record.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<?php
33
require_once(__DIR__ . '/core/load.php');
44

5+
Recorder::runOnlyOnce(); // kills other recorder processes
56
$recorder = new Recorder();
67

78
while( true ){

0 commit comments

Comments
 (0)