Skip to content

Commit

Permalink
Support osx idle on screensaver, screenlock
Browse files Browse the repository at this point in the history
Add fah-screen-agent
Support idle/not idle notifications
Add tools.scons
  • Loading branch information
kbernhagen committed Jan 16, 2024
1 parent ed4d2d0 commit db28c33
Show file tree
Hide file tree
Showing 11 changed files with 624 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*.app

# Build byproducts
/bin
/build
/package.txt
/package-description.txt
Expand Down
20 changes: 13 additions & 7 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ if env['PLATFORM'] == 'win32' or int(env.get('cross_mingw', 0)):
duplicate = 0)
Default(hide_console)

tools = SConscript('src/tools.scons', variant_dir = 'build', duplicate = 0)
Default(tools)
Depends(tools, client)
# Clean
Clean(client, ['build', 'config.log'])
Clean(client, ['bin', 'build', 'config.log'])

# Dist
docs = ['README.md', 'CHANGELOG.md', 'LICENSE']
distfiles = docs + [client, 'images/fahlogo.png']
distfiles = docs + client + tools + ['images/fahlogo.png']
if env['PLATFORM'] == 'posix':
distfiles.append('install/lin/fah-client.service')
if hide_console is not None: distfiles.append(hide_console)
Expand Down Expand Up @@ -122,14 +125,18 @@ if 'package' in COMMAND_LINE_TARGETS:
# Specify components for the osx distribution pkg
client_home = '.'
client_root = client_home + '/build/pkg/root'
pkg_files = [[str(client[0]), 'usr/local/bin/', 0o755],
['build/install/osx/fahclient.url',
pkg_files = [['build/install/osx/fahclient.url',
'Applications/Folding@home/fahclient.url', 0o644],
['build/install/osx/uninstall.url',
'Applications/Folding@home/uninstall.url', 0o644],
['build/install/osx/launchd.plist',
'Library/LaunchDaemons/' +
'org.foldingathome.fahclient.plist', 0o644]]
'org.foldingathome.fahclient.plist', 0o644],
['build/install/osx/fah-screen-agent.plist','Library/LaunchAgents/' +
'org.foldingathome.fah-screen-agent.plist', 0o644]]
for tool in client + tools:
pkg_files += [[str(tool), 'usr/local/bin/', 0o755]]

pkg_components = [
{
# name is component pkg file name and name shown in installer
Expand All @@ -145,7 +152,7 @@ if 'package' in COMMAND_LINE_TARGETS:
# default build/pkg/root, as per cbang config pkg module
'root' : client_root,
# relative to root
'sign_tools' : ['usr/local/bin/fah-client'],
'sign_tools' : ['usr/local/bin/*'],
'must_close_apps': [
'org.foldingathome.fahviewer',
'org.foldingathome.fahcontrol',
Expand Down Expand Up @@ -220,7 +227,6 @@ if 'package' in COMMAND_LINE_TARGETS:
pkg_background = 'fah-opacity-50.png',
pkg_customize = 'always',
pkg_target = pkg_target,
pkg_arch = env.get('package_arch', 'x86_64'),
pkg_components = pkg_components,
)

Expand Down
25 changes: 25 additions & 0 deletions install/osx/fah-screen-agent.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>org.foldingathome.fah-screen-agent</string>
<key>LimitLoadToSessionType</key>
<string>Aqua</string>
<key>LowPriorityIO</key>
<true/>
<key>Program</key>
<string>/usr/local/bin/fah-screen-agent</string>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>/dev/null</string>
<key>Umask</key>
<integer>18</integer>
</dict>
</plist>
14 changes: 13 additions & 1 deletion install/osx/scripts/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,28 @@ chmod -R u+rwX,go-w "$RUN_DIR"
chown -R nobody:nobody "$RUN_DIR"

PLIST=/Library/LaunchDaemons/org.foldingathome.fahclient.plist
AGENT_PLIST="/Library/LaunchAgents/org.foldingathome.fah-screen-agent.plist"

"$SCRIPTS"/organize-credits.sh &

# Start service
chmod 0644 "$PLIST"
chmod 0644 "$PLIST" "$AGENT_PLIST"
launchctl load -w "$PLIST"

# start, in case RunAtLoad is false
launchctl start org.foldingathome.fahclient || true

# restart any running agents in other sessions
# note that this does not reload their launchd jobs
killall -HUP fah-screen-agent || true

# start agent in user's gui session
conuser=$(/usr/bin/stat -f "%Su" /dev/console) || conuser="root"
conuid=$(/usr/bin/id -u "$conuser") || conuid=0
if [[ $conuid != 0 ]]; then
launchctl bootstrap gui/$conuid "$AGENT_PLIST" || true
fi

# Don't launch GUI if CLI install
[ "$COMMAND_LINE_INSTALL" == "1" ] && exit 0

Expand Down
10 changes: 10 additions & 0 deletions install/osx/scripts/preinstall
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SCRIPTS="$(dirname "$0")"
OLD_LAUNCHD="/Library/LaunchDaemons/FAHClient.plist"
OLD_LAUNCHD2="/Library/LaunchDaemons/edu.stanford.folding.fahclient.plist"
NEW_LAUNCHD="/Library/LaunchDaemons/org.foldingathome.fahclient.plist"
AGENT_PLIST="/Library/LaunchAgents/org.foldingathome.fah-screen-agent.plist"

if [ -f "$NEW_LAUNCHD" ]; then
launchctl unload -w "$NEW_LAUNCHD" || true
Expand All @@ -23,6 +24,15 @@ if [ -f "$OLD_LAUNCHD" ]; then
rm -f "$OLD_LAUNCHD" || true
fi

if [ -f "$AGENT_PLIST" ]; then
# stop agent running in console user's session and unload job
conuser=$(/usr/bin/stat -f "%Su" /dev/console) || conuser="root"
conuid=$(/usr/bin/id -u "$conuser") || conuid=0
if [[ $conuid != 0 ]]; then
launchctl bootout gui/$conuid "$AGENT_PLIST" || true
fi
fi

# Assuming upgrade, remove old stuff
F1="/Applications/FAHClient.url"
F2="/Applications/Folding@home/Web Control.url"
Expand Down
Loading

0 comments on commit db28c33

Please sign in to comment.