This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / pi / patch-permission-sound.py
1.0 kB 35 lines
1#!/usr/bin/env python3 2"""Patch pi-hooks permission extension to play peon sounds via pw-play on Linux.""" 3import re 4import sys 5 6ts_file = sys.argv[1] 7pw_play = sys.argv[2] 8 9src = open(ts_file).read() 10 11# Use a lambda for replacement to avoid re.sub interpreting backslash sequences 12replacement = r"""function playPermissionSound(): void { 13 const isMac = process.platform === "darwin"; 14 if (isMac) { 15 exec('afplay /System/Library/Sounds/Funk.aiff 2>/dev/null', (err) => { 16 if (err) process.stdout.write("\x07"); 17 }); 18 } else { 19 const n = Math.floor(Math.random() * 4) + 1; 20 exec(`""" + pw_play + r""" "$HOME/src/sounds/games/Warcraft III/Units/Orc/Peon/PeonWhat${n}.wav"`, () => {}); 21 } 22}""" 23 24result = re.sub( 25 r'function playPermissionSound\(\): void \{.*?\n\}', 26 lambda m: replacement, 27 src, 28 flags=re.DOTALL, 29) 30 31if result == src: 32 print("ERROR: playPermissionSound function not found in", ts_file, file=sys.stderr) 33 sys.exit(1) 34 35open(ts_file, 'w').write(result)