Skip to content

Commit

Permalink
Fix starting background when system language != English (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
airsquared committed Aug 19, 2023
1 parent 01320a6 commit a49a132
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Gradle build
uses: gradle/gradle-build-action@v2
with:
arguments: build --no-daemon
arguments: build --no-daemon --scan
- uses: initdc/upload-artifact@feat/artifact-per-file
with:
artifact-per-file: true
Expand Down
1 change: 1 addition & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,10 @@ if (os.isLinux() && findProperty('installerType') == null) {
if (os.isWindows() && findProperty('installerType') == null) {
assemble.dependsOn windowsInstaller
}

if (hasProperty('buildScan')) {
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
}
33 changes: 13 additions & 20 deletions src/main/java/airsquared/blobsaver/app/Background.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Predicate;

class Background {

Expand Down Expand Up @@ -178,7 +177,6 @@ private static Path windowsBackgroundFile() {
} catch (IOException e) {
throw new UncheckedIOException(e);
}

}

public static void startBackground() {
Expand Down Expand Up @@ -208,18 +206,11 @@ public static void stopBackground() {

public static boolean isBackgroundEnabled() {
if (Platform.isMac()) {
return outputMatches(s -> s.contains(backgroundLabel), "/bin/launchctl", "list");
return exitCode("/bin/launchctl", "list", backgroundLabel) == 0;
} else if (Platform.isWindows()) {
return outputMatches(s -> s.contains("Ready") || s.contains("Running"), "schtasks", "/Query", "/TN", windowsTaskName);
return exitCode("schtasks", "/Query", "/TN", windowsTaskName) == 0;
} else {
try {
return new ProcessBuilder("systemctl", "is-enabled", "--user", "--quiet", "blobsaver.timer")
.start().waitFor() == 0;
} catch (IOException e) {
throw new UncheckedIOException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return exitCode("systemctl", "is-enabled", "--user", "--quiet", "blobsaver.timer") == 0;
}
}

Expand Down Expand Up @@ -258,20 +249,22 @@ private static void systemctl(String... args) {
execute("systemctl", args);
}

private static void execute(String program, String... args) {
ArrayList<String> arguments = new ArrayList<>(args.length + 1);
arguments.add(program);
Collections.addAll(arguments, args);
private static int exitCode(String... command) {
try {
Utils.executeProgram(arguments);
return new ProcessBuilder(command).start().waitFor();
} catch (IOException e) {
throw new UncheckedIOException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

private static boolean outputMatches(Predicate<String> predicate, String... args) {
try (var reader = new ProcessBuilder(args).redirectErrorStream(true).start().inputReader()) {
return reader.lines().anyMatch(predicate);
private static void execute(String program, String... args) {
ArrayList<String> arguments = new ArrayList<>(args.length + 1);
arguments.add(program);
Collections.addAll(arguments, args);
try {
Utils.executeProgram(arguments);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/airsquared/blobsaver/app/BackgroundTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 airsquared
*
* This file is part of blobsaver.
*
* blobsaver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* blobsaver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with blobsaver. If not, see <https://www.gnu.org/licenses/>.
*/

package airsquared.blobsaver.app;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

import static org.junit.jupiter.api.Assertions.*;

class BackgroundTest extends BlobsaverTest {

@Test
@EnabledIfEnvironmentVariable(named = "GITHUB_ACTIONS", matches = "true")
void background() {
Background.startBackground();
assertTrue(Background.isBackgroundEnabled());
Background.stopBackground();
assertFalse(Background.isBackgroundEnabled());
}
}
17 changes: 13 additions & 4 deletions src/test/java/airsquared/blobsaver/app/TSSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package airsquared.blobsaver.app;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

Expand All @@ -26,9 +27,17 @@
public class TSSTest extends BlobsaverTest {

@Test
public void call(@TempDir Path savePath) throws TSS.TSSException {
TSS tss = new TSS.Builder().setDevice("iPhone12,8").setEcid("1").setIncludeBetas(true)
.setSavePath(savePath.toString()).build();
tss.call(); // don't create another thread
public void normal(@TempDir Path savePath) throws TSS.TSSException {
TSS tss = new TSS.Builder().setDevice("iPhone12,8").setEcid("1").setSavePath(savePath.toString())
.build();
tss.call();
}

@Test
@Disabled
public void betas(@TempDir Path savePath) throws TSS.TSSException {
TSS tss = new TSS.Builder().setDevice("iPhone12,8").setEcid("1").setSavePath(savePath.toString())
.setIncludeBetas(true).build();
tss.call();
}
}

0 comments on commit a49a132

Please sign in to comment.