Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions screenprofiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,20 @@ def open_about_window(self):
dialog.exec_()

if __name__ == '__main__':
# Fork to background — parent exits, child continues as the tray app
pid = os.fork()
if pid > 0:
sys.exit(0)

# Child: detach from terminal and run the tray app
os.setsid()

# Redirect stdout/stderr so the detached process doesn't hold terminal fds
devnull = os.open(os.devnull, os.O_RDWR)
os.dup2(devnull, sys.stdout.fileno())
os.dup2(devnull, sys.stderr.fileno())
os.close(devnull)

app = QApplication(sys.argv)
window = MainWindow()
exit_code = app.exec_()
sys.exit(exit_code)
sys.exit(app.exec_())
13 changes: 8 additions & 5 deletions screenprofilercmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,14 @@ case $command in
# Change to script directory to ensure correct working directory
cd "$script_dir" || exit 1

# Launch the Python tray application in the background
# Redirect output to /dev/null to avoid cluttering terminal
nohup python3 "$script_dir/screenprofiler.py" >/dev/null 2>&1 &

print_success "Screen Profiler tray application launched"
# The Python script self-daemonizes: it forks, the parent exits
# with the appropriate exit code, and the child runs the tray app.
if python3 "$script_dir/screenprofiler.py"; then
print_success "Screen Profiler tray application launched"
else
print_error "Failed to launch tray application"
exit 1
fi
;;

# ------------------------------------------------------------------------
Expand Down