diff --git a/addonInter/build.gradle b/addonInter/build.gradle index ae6b74c..e63b5aa 100644 --- a/addonInter/build.gradle +++ b/addonInter/build.gradle @@ -20,6 +20,10 @@ configurations { canBeConsumed = true canBeResolved = false } + install { + canBeConsumed = true + canBeResolved = false + } } // In this section you declare where to find the dependencies of your project @@ -57,4 +61,5 @@ artifacts { nativeBuild(installDist.destinationDir) { builtBy installDist } + install(distTar) } \ No newline at end of file diff --git a/browser/browserConf/distribution/policies.json b/browser/browserConf/distribution/policies.json index cc28f49..2a095e9 100644 --- a/browser/browserConf/distribution/policies.json +++ b/browser/browserConf/distribution/policies.json @@ -15,9 +15,6 @@ "Fingerprinting": true }, "DontCheckDefaultBrowser": true, - "ExtensionSettings": { - ${preinstalled} - }, "Permissions": { "Camera": { "BlockNewRequests": true diff --git a/browser/build.gradle b/browser/build.gradle index 4220c76..81ef203 100644 --- a/browser/build.gradle +++ b/browser/build.gradle @@ -16,6 +16,10 @@ configurations { canBeConsumed = false canBeResolved = true } + install { + canBeConsumed = true + canBeResolved = false + } } // In this section you declare where to find the dependencies of your project @@ -45,9 +49,6 @@ repositories { } } -def firefox_module = "devedition" -def firefox_revision = "92.0b7" - abstract class InstallBrowserTask extends DefaultTask { @OutputFile final abstract DirectoryProperty installation = project.objects.directoryProperty() @@ -248,6 +249,31 @@ task installAddons(type: Copy) { } } +task zipPolicies(type: Tar) { + archiveFileName = "conf.tar" + destinationDirectory = file("$buildDir") + from(configurations.addon.files) { + into "distribution/extensions" + } + from files("browserConf") + filesMatching('**/policies.json'){ + def pre = "" + for (File addon: configurations.addon.resolve()) + { + if (pre.length() > 0) + { + pre += ",\n" + } + pre += "\"" + addon.name.substring(0, addon.name.lastIndexOf('.')) + "\": {\n" + pre += "\"installation_mode\": \"forced_install\"," + pre += "\"install_url\": \"" + addon.toURI().toString() + "\"" + pre += "}" + } + println "Expanding ${pre}" + expand(preinstalled: pre) + } +} + tasks.named('clean') { dependsOn uninstallFirefoxWindows } @@ -255,3 +281,7 @@ println configurations.getNames() compileJava.dependsOn installAddons compileJava.dependsOn movePolicies + +artifacts { + install(zipPolicies) +} \ No newline at end of file diff --git a/browser/gradle.properties b/browser/gradle.properties new file mode 100644 index 0000000..e6073bc --- /dev/null +++ b/browser/gradle.properties @@ -0,0 +1,2 @@ +firefox_module = devedition +firefox_revision = 92.0b7 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 8935686..c1c5f26 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import java.util.stream.Collectors + /* * Copyright (c) 2021 William Hubbard. All Rights Reserved. */ @@ -9,4 +11,56 @@ * For more details take a look at the Java Quickstart chapter in the Gradle * user guide available at https://docs.gradle.org/4.4.1/userguide/tutorial_java_projects.html */ -ext.defaultPackage = "edu.regis.universeplayer" \ No newline at end of file +ext.defaultPackage = "edu.regis.universeplayer" + +configurations { + browserData { + canBeConsumed = false + canBeResolved = true + } + appData { + canBeConsumed = false + canBeResolved = true + } +} + +dependencies { + browserData project(path: ":browser", configuration: 'install') + appData project(path: ":interface", configuration: "install") + appData project(path: ":addonInter", configuration: "install") +} + +task mergeApps(type: Tar) { + dependsOn configurations.appData + for (File file : configurations.appData.files) { + from(tarTree(file)) { + exclude "*" + include "*/bin/**" + include "*/lib/**" + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + eachFile { fcd -> + fcd.relativePath = new RelativePath(true, fcd.relativePath.segments.drop(1)) + } + includeEmptyDirs = false + } + } + archiveFileName = "${project.name}.tar" + destinationDirectory = file("$buildDir") + doFirst { + println "$buildDir" + } +} + +task buildscriptNix(type: Copy) { + dependsOn configurations.browserData + dependsOn mergeApps + from "$project.rootDir/src/install.sh" + into "$buildDir" + expand(project(":browser").properties) + doLast { + file("${buildDir}/install.sh").append "__BROWSERCONF__\n".bytes + file("${buildDir}/install.sh").append configurations.browserData.resolve().stream().findFirst().map(file -> file.bytes).get() + file("${buildDir}/install.sh").append "\n__APPDATA__\n".bytes + file("${buildDir}/install.sh").append mergeApps.archiveFile.get().asFile.bytes + } +} \ No newline at end of file diff --git a/interface/build.gradle b/interface/build.gradle index ea3cca4..2768582 100644 --- a/interface/build.gradle +++ b/interface/build.gradle @@ -15,6 +15,13 @@ repositories { } } +configurations { + install { + canBeConsumed = true + canBeResolved = false + } +} + // In this section you declare the dependencies for your production and test code dependencies { // The production code uses the SLF4J logging API at compile time @@ -46,3 +53,7 @@ targetCompatibility = JavaVersion.VERSION_16 // Define the main class for the application mainClassName = defaultPackage + '.PlayerEnvironment' //mainClassName = defaultPackage + '.localPlayer.Player' + +artifacts { + install(distTar) +} \ No newline at end of file diff --git a/interface/src/main/java/edu/regis/universeplayer/PlayerEnvironment.java b/interface/src/main/java/edu/regis/universeplayer/PlayerEnvironment.java index 6b08289..c0b7058 100644 --- a/interface/src/main/java/edu/regis/universeplayer/PlayerEnvironment.java +++ b/interface/src/main/java/edu/regis/universeplayer/PlayerEnvironment.java @@ -203,7 +203,10 @@ public class PlayerEnvironment */ runArguments(ops, params, System.out); - Runtime.getRuntime().addShutdownHook(new Thread(connector::stop)); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + connector.stop(); + PlayerManager.getPlayers().shutdownPlayers(); + })); } /** diff --git a/interface/src/main/java/edu/regis/universeplayer/gui/Interface.java b/interface/src/main/java/edu/regis/universeplayer/gui/Interface.java index ac606fc..1cf5f65 100644 --- a/interface/src/main/java/edu/regis/universeplayer/gui/Interface.java +++ b/interface/src/main/java/edu/regis/universeplayer/gui/Interface.java @@ -619,12 +619,13 @@ public class Interface extends JFrame implements SongDisplayListener, ComponentL @Override public void windowClosing(WindowEvent windowEvent) { - PlayerManager.getPlayers().shutdownPlayers(); + logger.info("Window closing"); } @Override public void windowClosed(WindowEvent windowEvent) { + logger.info("Window closed"); } @Override diff --git a/src/install.sh b/src/install.sh new file mode 100644 index 0000000..275d280 --- /dev/null +++ b/src/install.sh @@ -0,0 +1,98 @@ +#!/bin/sh +installDir="/usr/share/universal" +if [ -d "\$installDir" ] +then + rm -r "\$installDir" +fi +mkdir "\$installDir" +if [ \$? -ne 0 ] +then + installDir="\$HOME/.local/share/universal" + if [ -d "\$installDir" ] + then + rm -r "\$installDir" + fi + mkdir "\$installDir" + if [ \$? -ne 0 ] + then + echo "Could not create install directory. Try running with sudo" 1>&2 + exit 1 + fi +fi + +mkdir "\$installDir/firefox" +if [ \$? -ne 0 ] +then + echo "Could not create browser directory" 1>&2 + exit 1 +fi +# Install Firefox +if [ ! -f "/tmp/firefox.tar.bz2" ] +then + firefoxDownload="https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/linux-x86_64/en-US/firefox-${firefox_revision}.tar.bz2" + echo "Downloading Firefox" + if [ `command -v wget` ] + then + wget -O "/tmp/firefox.tar.bz2" "\$firefoxDownload" + elif [ `command -v curl` ] + then + curl -o "/tmp/firefox.tar.bz2" "\$firefoxDownload" + fi + if [ \$? -ne 0 ] + then + echo "Could not download Firefox from \$firefoxDownload" 1>&2 + exit 2 + fi +fi + +cd "\$installDir" +echo "Installing Firefox" +tar -xj -f "/tmp/firefox.tar.bz2" +if [ \$? -ne 0 ] +then + echo "Could not extract firefox" 1>&2 + exit 3 +fi +chmod +X "\$installDir/firefox/firefox" +rm "/tmp/firefox.tar.bz2" +if [ \$? -ne 0 ] +then + echo "WARNING: Could not clean up firefox!" 1>&2 +fi + +cd "\$OLDPWD" +cd "\$installDir/firefox" +# Install browser configurations +echo "Extracting browser configuration" +echo "Loading browser configuration" +confIndex=`awk '/^__BROWSERCONF__/ {print NR + 1; exit 0;}' \$0` +appIndex=`awk '/^__APPDATA__/ {print NR + 1; exit 0;}' \$0` +confLength=`expr \$appIndex - 1 - \$confIndex` +tail -n+\$confIndex \$0 | head -n-\$confLength | tar -x + +mkdir -p "\$HOME/.mozilla/native-messaging-hosts" +echo "Installing native app" +cat >"\$HOME/.mozilla/native-messaging-hosts/universalmusic.json" << ENDNATIVE +{ + "name": "universalmusic", + "description": "A link between the Universal Music Player and the web browser.", + "path": "\$installDir/bin/addonInter", + "type": "stdio", + "allowed_extensions": ["universalmusic@regis.edu"] +} +ENDNATIVE +cd "\$OLDPWD" + +# Install the actual application +cd "\$installDir" +echo "Copying application data" +echo "Extracting application data" +tail -n+\$appIndex \$0 | tar -x +chmod +X "\$installDir/bin/interface" +chmod +X "\$installDir/bin/addonInter" + +cd "\$OLDPWD" +ln -fs "\$installDir/bin/interface" "\$installDir/../../bin/universalplayer" +echo "Done!" +exit 0 +