Skip to content

Commit a49a132

Browse files
committed
Fix starting background when system language != English (#613)
1 parent 01320a6 commit a49a132

File tree

6 files changed

+71
-25
lines changed

6 files changed

+71
-25
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Gradle build
2424
uses: gradle/gradle-build-action@v2
2525
with:
26-
arguments: build --no-daemon
26+
arguments: build --no-daemon --scan
2727
- uses: initdc/upload-artifact@feat/artifact-per-file
2828
with:
2929
artifact-per-file: true

.idea/codeStyles/Project.xml

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

build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,10 @@ if (os.isLinux() && findProperty('installerType') == null) {
228228
if (os.isWindows() && findProperty('installerType') == null) {
229229
assemble.dependsOn windowsInstaller
230230
}
231+
232+
if (hasProperty('buildScan')) {
233+
buildScan {
234+
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
235+
termsOfServiceAgree = 'yes'
236+
}
237+
}

src/main/java/airsquared/blobsaver/app/Background.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.nio.file.Path;
2727
import java.util.ArrayList;
2828
import java.util.Collections;
29-
import java.util.function.Predicate;
3029

3130
class Background {
3231

@@ -178,7 +177,6 @@ private static Path windowsBackgroundFile() {
178177
} catch (IOException e) {
179178
throw new UncheckedIOException(e);
180179
}
181-
182180
}
183181

184182
public static void startBackground() {
@@ -208,18 +206,11 @@ public static void stopBackground() {
208206

209207
public static boolean isBackgroundEnabled() {
210208
if (Platform.isMac()) {
211-
return outputMatches(s -> s.contains(backgroundLabel), "/bin/launchctl", "list");
209+
return exitCode("/bin/launchctl", "list", backgroundLabel) == 0;
212210
} else if (Platform.isWindows()) {
213-
return outputMatches(s -> s.contains("Ready") || s.contains("Running"), "schtasks", "/Query", "/TN", windowsTaskName);
211+
return exitCode("schtasks", "/Query", "/TN", windowsTaskName) == 0;
214212
} else {
215-
try {
216-
return new ProcessBuilder("systemctl", "is-enabled", "--user", "--quiet", "blobsaver.timer")
217-
.start().waitFor() == 0;
218-
} catch (IOException e) {
219-
throw new UncheckedIOException(e);
220-
} catch (InterruptedException e) {
221-
throw new RuntimeException(e);
222-
}
213+
return exitCode("systemctl", "is-enabled", "--user", "--quiet", "blobsaver.timer") == 0;
223214
}
224215
}
225216

@@ -258,20 +249,22 @@ private static void systemctl(String... args) {
258249
execute("systemctl", args);
259250
}
260251

261-
private static void execute(String program, String... args) {
262-
ArrayList<String> arguments = new ArrayList<>(args.length + 1);
263-
arguments.add(program);
264-
Collections.addAll(arguments, args);
252+
private static int exitCode(String... command) {
265253
try {
266-
Utils.executeProgram(arguments);
254+
return new ProcessBuilder(command).start().waitFor();
267255
} catch (IOException e) {
268256
throw new UncheckedIOException(e);
257+
} catch (InterruptedException e) {
258+
throw new RuntimeException(e);
269259
}
270260
}
271261

272-
private static boolean outputMatches(Predicate<String> predicate, String... args) {
273-
try (var reader = new ProcessBuilder(args).redirectErrorStream(true).start().inputReader()) {
274-
return reader.lines().anyMatch(predicate);
262+
private static void execute(String program, String... args) {
263+
ArrayList<String> arguments = new ArrayList<>(args.length + 1);
264+
arguments.add(program);
265+
Collections.addAll(arguments, args);
266+
try {
267+
Utils.executeProgram(arguments);
275268
} catch (IOException e) {
276269
throw new UncheckedIOException(e);
277270
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2023 airsquared
3+
*
4+
* This file is part of blobsaver.
5+
*
6+
* blobsaver is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, version 3 of the License.
9+
*
10+
* blobsaver is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with blobsaver. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package airsquared.blobsaver.app;
20+
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
23+
24+
import static org.junit.jupiter.api.Assertions.*;
25+
26+
class BackgroundTest extends BlobsaverTest {
27+
28+
@Test
29+
@EnabledIfEnvironmentVariable(named = "GITHUB_ACTIONS", matches = "true")
30+
void background() {
31+
Background.startBackground();
32+
assertTrue(Background.isBackgroundEnabled());
33+
Background.stopBackground();
34+
assertFalse(Background.isBackgroundEnabled());
35+
}
36+
}

src/test/java/airsquared/blobsaver/app/TSSTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package airsquared.blobsaver.app;
2020

21+
import org.junit.jupiter.api.Disabled;
2122
import org.junit.jupiter.api.Test;
2223
import org.junit.jupiter.api.io.TempDir;
2324

@@ -26,9 +27,17 @@
2627
public class TSSTest extends BlobsaverTest {
2728

2829
@Test
29-
public void call(@TempDir Path savePath) throws TSS.TSSException {
30-
TSS tss = new TSS.Builder().setDevice("iPhone12,8").setEcid("1").setIncludeBetas(true)
31-
.setSavePath(savePath.toString()).build();
32-
tss.call(); // don't create another thread
30+
public void normal(@TempDir Path savePath) throws TSS.TSSException {
31+
TSS tss = new TSS.Builder().setDevice("iPhone12,8").setEcid("1").setSavePath(savePath.toString())
32+
.build();
33+
tss.call();
34+
}
35+
36+
@Test
37+
@Disabled
38+
public void betas(@TempDir Path savePath) throws TSS.TSSException {
39+
TSS tss = new TSS.Builder().setDevice("iPhone12,8").setEcid("1").setSavePath(savePath.toString())
40+
.setIncludeBetas(true).build();
41+
tss.call();
3342
}
3443
}

0 commit comments

Comments
 (0)