Skip to content

Commit 333cd57

Browse files
authored
Labwc support, improved non-pi user support (#118)
* Added autostart support for Wayland with Labwc. * Fix problems starting service under any admin user other than `pi`.
1 parent d41ec26 commit 333cd57

12 files changed

Lines changed: 108 additions & 57 deletions

File tree

.idea/dictionaries/default_user.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.7.2
2+
3+
* Added autostart support for Wayland with Labwc.
4+
* Fix problems starting service under any admin user other than `pi`.
5+
16
## 3.7.1-do
27

38
* Better documentation on installation of the Adafruit GPS HAT.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ For reference, here’s a breakdown of the steps performed by a full installatio
396396
1. The commands `sudo update-rc.d weatherService defaults` and `sudo systemctl enable weatherService` are performed to establish and enable the service.
397397
1. An `autostart` file is created in `~/.config/lxsession/LXDE-pi/` (no `‑pi` on the end for Debian), or the existing `autostart` file is modified, to run the following script...
398398
1. The included file `autostart_extra.sh` is also copied to the above directory. This includes code to make sure Chromium doesn’t launch complaining it was shut down improperly, which could interfere with an otherwise smooth automatic start-up. The code then makes sure the clock server is running before launching your chosen web browser with the clock application.
399-
1. For Raspbian Bookworm or later, `~/.config/wayfire.ini` is also modified to run `autostart_extra.sh`.
399+
1. For Raspbian Bookworm or later, `~/.config/wayfire.ini` and `~/.config/labwc/autostart` are also modified to run `autostart_extra.sh`.
400400
1. The options `‑‑launch` or `‑‑reboot` are performed if specified.
401401

402402
### Screen Resolution

build.js

Lines changed: 14 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.ts

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ const cpuPath2 = '/sys/firmware/devicetree/base/model';
109109
const settingsPath = '/etc/default/weatherService';
110110
const rpiSetupStuff = path.join(__dirname, 'raspberry_pi_setup');
111111
const serviceSrc = rpiSetupStuff + '/weatherService';
112-
const serviceDst = '/etc/init.d/.';
113-
const serviceDstFull = '/etc/init.d/weatherService';
112+
const serviceDst = '/etc/init.d/weatherService';
114113
const fontSrc = rpiSetupStuff + '/fonts/';
115114
const fontDst = '/usr/local/share/fonts/';
116115
let chromium = 'chromium';
@@ -693,7 +692,7 @@ async function checkForGps(): Promise<void> {
693692
console.log(chalkUp(' [pb]• Install [w]ntpd[/w] and [w]ntpq[/w]'));
694693

695694
if (!hasPpsTools)
696-
console.log(chalkUp(' [pb]• Install [w]ppstest[/w]'));
695+
console.log(chalkUp(' [pb]• Install [w]pps-tools[/w]'));
697696
}
698697
else
699698
console.log('GPS time and location services found ' + chalk.green(CHECK_MARK));
@@ -1107,7 +1106,7 @@ async function doServerBuild(): Promise<void> {
11071106
if (doAcu || doDht) {
11081107
showStep();
11091108

1110-
const args = ['i', '-P', 'rpi-acu-rite-temperature@3', 'node-dht-sensor-rp5@0'];
1109+
const args = ['i', '-P', 'rpi-acu-rite-temperature@3', 'node-dht-sensor'];
11111110

11121111
if (isRaspberryPi5OrLater)
11131112
args.push('--use_libgpiod=true');
@@ -1145,8 +1144,11 @@ async function doServiceDeployment(): Promise<void> {
11451144

11461145
showStep();
11471146
write('Create or redeploy weatherService' + trailingSpace);
1148-
await monitorProcess(spawn('cp', [serviceSrc, serviceDst], { shell: true }), spin, ErrorMode.ANY_ERROR);
1149-
await monitorProcess(spawn('chmod', ['+x', serviceDstFull], { shell: true }), spin, ErrorMode.ANY_ERROR);
1147+
1148+
const serviceScript = fs.readFileSync(serviceSrc).toString().replace(/\/pi\//g, `/${user}/`);
1149+
1150+
fs.writeFileSync(serviceDst, serviceScript);
1151+
await monitorProcess(spawn('chmod', ['+x', serviceDst], { shell: true }), spin, ErrorMode.ANY_ERROR);
11501152

11511153
const settingsText =
11521154
`# If you edit AWC_PORT below, be sure to update\n# ${userHome}/${autostartDst}/autostart` +
@@ -1172,7 +1174,8 @@ async function doServiceDeployment(): Promise<void> {
11721174

11731175
autoScript = autoScript.replace('echo #launch-here', launchCmd)
11741176
.replace(/:8080\b/, ':' + settings.AWC_PORT)
1175-
.replace('the-browser', doFirefox ? 'firefox' : chromium);
1177+
.replace('the-browser', doFirefox ? 'firefox' : chromium)
1178+
.replace(/\/pi\//g, `/${user}/`);
11761179

11771180
fs.writeFileSync(path.join(autostartDir, autostartScriptFile), autoScript);
11781181

@@ -1182,6 +1185,7 @@ async function doServiceDeployment(): Promise<void> {
11821185
let update = false;
11831186
let found = false;
11841187

1188+
// Autostart setup for X11
11851189
try {
11861190
lines = asLines(fs.readFileSync(autostartPath).toString()).filter(line => !!line.trim());
11871191
}
@@ -1216,36 +1220,68 @@ async function doServiceDeployment(): Promise<void> {
12161220
if (update)
12171221
fs.writeFileSync(autostartPath, lines.join('\n') + '\n');
12181222

1219-
// Extra autostart setup for Wayfire
1220-
if (existsSync(wayfireIniPath)) {
1221-
try {
1223+
// Autostart setup for Wayland/Wayfire
1224+
try {
1225+
if (!existsSync(wayfireIniPath)) {
1226+
fs.mkdirSync(path.dirname(wayfireIniPath), { recursive: true });
1227+
lines = [];
1228+
}
1229+
else
12221230
lines = asLines(fs.readFileSync(wayfireIniPath).toString()).filter(line => !!line.trimEnd());
12231231

1224-
let autoIndex = lines.findIndex(l => l.startsWith('[autostart]'));
1225-
1226-
if (autoIndex < 0) {
1227-
lines.push('');
1228-
lines.push('[autostart]');
1229-
autoIndex = lines.length;
1230-
}
1231-
else
1232-
while (lines[++autoIndex] && !/^clock[12] = /.test(lines[autoIndex])) {}
1232+
let autoIndex = lines.findIndex(l => l.startsWith('[autostart]'));
12331233

1234-
// Prevent duplicate entries, remove old entries
1235-
lines = lines.filter((l, i) => i < autoIndex || !/^clock[12] = /.test(l));
1236-
lines.splice(autoIndex, 0, 'clock1 = ' + autostartEntry);
1237-
fs.writeFileSync(wayfireIniPath, lines.join('\n') + '\n');
1234+
if (autoIndex < 0) {
1235+
lines.push('');
1236+
lines.push('[autostart]');
1237+
autoIndex = lines.length;
12381238
}
1239-
catch (e) {
1240-
console.error(chalk.redBright('Error: failed to update .config/wayfire.ini to autostart AW-Clock'));
1241-
console.error(chalk.redBright(' ' + e.message));
1239+
else
1240+
while (lines[++autoIndex] && !/^((\s*\[)|(clock[12] = ))/.test(lines[autoIndex])) {}
1241+
1242+
// Prevent duplicate entries, remove old entries
1243+
lines = lines.filter((l, i) => i < autoIndex || !/^clock[12] = /.test(l));
1244+
lines.splice(autoIndex, 0, 'clock1 = ' + autostartEntry);
1245+
fs.writeFileSync(wayfireIniPath, lines.join('\n') + '\n');
1246+
}
1247+
catch (e) {
1248+
console.error(chalk.redBright('Error: failed to update .config/wayfire.ini to autostart AW-Clock'));
1249+
console.error(chalk.redBright(' ' + e.message));
1250+
}
1251+
1252+
// Autostart setup for Wayland/Labwc
1253+
const labwcAutostartPath = path.join(userHome, '.config/labwc/autostart');
1254+
1255+
try {
1256+
if (!existsSync(labwcAutostartPath)) {
1257+
fs.mkdirSync(path.dirname(labwcAutostartPath), { recursive: true });
1258+
lines = [];
12421259
}
1260+
else
1261+
lines = asLines(fs.readFileSync(labwcAutostartPath).toString()).filter(line => !!line.trimEnd());
1262+
1263+
const autoIndex = lines.findIndex(l => /\bautostart_extra.sh\b/.test(l));
1264+
1265+
if (autoIndex < 0)
1266+
lines.push(autostartEntry);
1267+
else
1268+
lines[autoIndex] = autostartEntry;
1269+
1270+
fs.writeFileSync(labwcAutostartPath, lines.join('\n') + '\n');
1271+
}
1272+
catch (e) {
1273+
console.error(chalk.redBright('Error: failed to update .config/labwc/autostart to autostart AW-Clock'));
1274+
console.error(chalk.redBright(' ' + e.message));
12431275
}
12441276

12451277
await monitorProcess(spawn('chown', 0, [sudoUser, autostartDir + '/autostart*'],
12461278
{ shell: true }), spin, ErrorMode.ANY_ERROR);
12471279
await monitorProcess(spawn('chmod', uid, ['+x', autostartDir + '/autostart*'],
12481280
{ shell: true }), spin, ErrorMode.ANY_ERROR);
1281+
await monitorProcess(spawn('chown', 0, [sudoUser, wayfireIniPath],
1282+
{ shell: true }), spin, ErrorMode.ANY_ERROR);
1283+
await monitorProcess(spawn('chown', 0, [sudoUser, labwcAutostartPath],
1284+
{ shell: true }), spin, ErrorMode.ANY_ERROR);
12491285

12501286
if (noStop)
12511287
console.log(backspace + trailingSpace + '\n\nReboot to complete set-up.');

build_node_check.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,23 @@ install_nvm() {
7373

7474
# Sync version changes with build.ts
7575
sadVersion=10
76-
minVersion=14
77-
maxVersion=18
78-
absMaxVersion=20
76+
minAptGetVersion=18
77+
minVersion=18
78+
maxVersion=20
79+
absMaxVersion=24
7980
free=$(free || echo "4194304")
8081
pattern='([0-9]+)'
8182
[[ $free =~ $pattern ]]
8283
free="${BASH_REMATCH[1]}"
8384

8485
# If less than 2G RAM, go with Node 12 instead
85-
if (( free < 1500000 ));then
86+
if (( free < 1500000 )); then
8687
minVersion=12
8788
maxVersion=12
8889
absMaxVersion=12
89-
elif (( free > 8000000 ));then
90-
minVersion=14
91-
maxVersion=22
90+
elif (( free > 8000000 )); then
91+
minVersion=20
92+
maxVersion=24
9293
absMaxVersion=999
9394
fi
9495

@@ -111,7 +112,7 @@ if [ "$version" -ne "$maxVersion" ] && [ -s "$NVM_DIR/nvm.sh" ]; then
111112
version="$(current_node_version)"
112113
fi
113114

114-
if (( version < minVersion )); then
115+
if ( (( version < minVersion )) && (( minVersion >= minAptGetVersion )) ); then
115116
echo "Installing Node.js. This could take several minutes..."
116117
sudo apt-get update
117118
curl -sL https://deb.nodesource.com/setup_"$minVersion".x | sudo bash -
@@ -143,7 +144,7 @@ if (( version < 0 )); then
143144
rm -rf "$NVM_DIR"
144145
fi
145146

146-
[ -d "$HOME/.nvm" ] rm -rf "$HOME/.nvm"
147+
[ -d "$HOME/.nvm" ] && rm -rf "$HOME/.nvm"
147148
export PATH="$originalPath"
148149
version="$(current_node_version)"
149150

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aw-clock",
3-
"version": "3.7.1",
3+
"version": "3.7.2",
44
"license": "MIT",
55
"author": "Kerry Shetline <kerry@shetline.com>",
66
"scripts": {

sass/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sass/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aw-clock-sass",
3-
"version": "3.7.1",
3+
"version": "3.7.2",
44
"description": "SASS builder for aw-clock",
55
"keywords": [
66
"sass"

0 commit comments

Comments
 (0)