Skip to content

Commit

Permalink
Autostart by default (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf authored and Berenz committed Jun 15, 2019
1 parent 1035883 commit a3a9066
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 198 deletions.
6 changes: 6 additions & 0 deletions ant/apple/apple-launcher.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ iconpath=$installpath/${apple.resources}/${apple.icon}
${apple.jvmver} > /dev/null 2>&1
fallback=$?

# If launched at startup, check override first
if [[ "$1" == "--autostart" ]] && [[ "$(cat "$installpath/.autostart")" == "0" ]]; then
echo "Skipping autostart"
exit 0
fi

# Fallback on Internet Plug-Ins version if needed
if [ $fallback -eq 0 ]; then
${apple.jvmcmd} java ${launch.opts} -Xdock:name="${project.name}" -Xdock:icon="$iconpath" -jar -Dapple.awt.UIElement="true" "$jarpath" -NSRequiresAquaSystemAppearance False
Expand Down
27 changes: 27 additions & 0 deletions ant/apple/apple-postinstall.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,33 @@ if [ $? -eq 0 ]; then
"${apple.installdir}/auth/firefox/${firefoxcert.name}" "install"
fi

# Install startup
site=$(echo "${vendor.website}"|rev|cut -d/ -f1|rev)
package=$(echo "$site" |rev |cut -d. -f1|rev).$(echo "$site" |rev |cut -d. -f2|rev).${project.filename}
cat > /Library/LaunchAgents/$package.plist << EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>$package</string>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key><false/>
<key>AfterInitialDemand</key><false/>
</dict>
<key>RunAtLoad</key><true/>
<key>ProgramArguments</key>
<array>
<string>${apple.installdir}/${apple.macos}/${project.name}</string>
<string>--autostart</string>
</array>
</dict>
</plist>
EOT

printf 1 > "${apple.installdir}/.autostart"
chmod 777 "${apple.installdir}/.autostart"

# Cleanup resources from previous versions
rm -rf "${apple.installdir}/demo/js/3rdparty"
rm "${apple.installdir}/demo/js/qz-websocket.js"
Expand Down
5 changes: 5 additions & 0 deletions ant/apple/apple-uninstall.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ else
echo -e "${bash.skipped}"
fi

# Remove startup entry
site=$(echo "${vendor.website}"|rev|cut -d/ -f1|rev)
package=$(echo "$site" |rev |cut -d. -f1|rev).$(echo "$site" |rev |cut -d. -f2|rev).${project.filename}
rm -f /Library/LaunchAgents/$package.plist

# Uninstall ${project.name} system certificates
"${apple.installdir}/auth/${apple.keygen.name}" "uninstall"

Expand Down
8 changes: 4 additions & 4 deletions ant/firefox/locator.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function get_osx_targetdir()
elif [[ "/$r" == "$HOME/Applications"* ]]; then
dir_out="/$r"
return_val=0
#If nothing else, remember it if we don't have anything else yet
#If nothing else, remember it if we don't have anything else yet
elif [ dir_out == "" ]; then
dir_out="/$r"
return_val=0
Expand All @@ -66,7 +66,7 @@ function get_targetdir()
lowerbin=$(echo "$with_bin" |tr '[:upper:]' '[:lower:]')
location=$(readlink -f "$(which $lowerdir 2> /dev/null)")
targetdir=$(dirname "$location")
if [ -f "$targetdir/$lowerbin" ] && file -b "$targetdir/$lowerbin" |grep -q ELF; then
if [[ "$targetdir" != "/usr/bin" ]] && [ -f "$targetdir/$lowerbin" ] && file -b "$targetdir/$lowerbin" |grep -q ELF; then
dir_out="$targetdir"
return 0
else
Expand Down Expand Up @@ -94,10 +94,10 @@ if [ "$#" == 0 ]; then
elif [ "$#" == 1 ]; then
with_dir=$1
with_bin=$1
else
else
with_dir=$1
with_bin=$2
fi
fi

if [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
Expand Down
18 changes: 18 additions & 0 deletions ant/linux/linux-installer.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,24 @@ rm -f "/lib/udev/rules.d/${linux.udev.name}" > /dev/null 2>&1
mv "$destdir/${linux.udev.name}" "/lib/udev/rules.d/${linux.udev.name}" > /dev/null 2>&1
udevadm control --reload-rules > /dev/null 2>&1

progress_dialog 93 "Cleaning up old versions..."

# Remove old startup entries
for i in /home/* ; do
if [ -n "${project.filename}" ]; then
rm "$i/.config/autostart/${project.filename}.desktop" > /dev/null 2>&1
fi
if [ -n "${project.name}" ]; then
rm "$i/.config/autostart/${project.name}.desktop" > /dev/null 2>&1
fi
done

progress_dialog 94 "Adding startup entry..."
cp "${shortcut}" "/etc/xdg/autostart/${project.filename}.desktop"

# Allow oridinary users to write
chmod 777 "/etc/xdg/autostart/${project.filename}.desktop"

cd "${destdir}"
progress_dialog 95 "Installation complete... Starting ${project.name}..."
which sudo > /dev/null 2>&1
Expand Down
6 changes: 6 additions & 0 deletions ant/linux/linux-keygen.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ if [ -n "$trustedcertpath" ]; then
exit 0
fi

# Check for keytool command
"${jks.keytool} -help" > /dev/null 2>&1
if [ $? -ne 0 ]; then
export PATH=$PATH:/usr/java/latest/bin/
fi

# Handle self-signed certificate
echo -e "\nCreating keystore for secure websockets..."
# Delete old files if exist
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion ant/windows/windows-cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ function getArg(index, defaultVal) {
*/
function trim(val) {
return val.replace(/^\s+/,'').replace(/\s+$/,'');
}
}
16 changes: 12 additions & 4 deletions ant/windows/windows-packager.nsi.in
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,22 @@ Section
${If} ${RunningX64}
${DisableX64FSRedirection}
${EndIf}

; Handle edge-case where jscript support is unregistered
nsExec::ExecToLog "regsvr32.exe /s $\"%systemroot%\system32\jscript.dll$\""

; Remove ${vendor.company} certificates
nsExec::ExecToLog "cscript.exe //NoLogo //E:jscript $\"$INSTDIR\auth\${windows.keygen.name}$\" $\"$INSTDIR$\" uninstall"

; Perform cleanup operations from previous install
nsExec::ExecToLog "cscript.exe //NoLogo //E:jscript $\"$INSTDIR\utils\${windows.cleanup.name}$\" $\"${project.name}$\""

keygen:
; Exports a self-signed certificate and properties file
DetailPrint "Generating a unique certificate for HTTPS support..."
nsExec::ExecToLog "cscript.exe //NoLogo //E:jscript $\"$INSTDIR\auth\${windows.keygen.name}$\" $\"$INSTDIR$\" install"
Pop $0

; Secure websockets is required, handle errors
${If} "$0" != "0"
${If} "$0" == "${windows.err.java}"
Expand All @@ -130,6 +133,10 @@ Section
${EndIf}

CreateShortCut "$SMPROGRAMS\${project.name}.lnk" "$INSTDIR\${project.filename}.exe" "" "$INSTDIR\${windows.icon}" 0
CreateShortCut "$SMSTARTUP\${project.name}.lnk" "$INSTDIR\${project.filename}.exe" "" "$INSTDIR\${windows.icon}" 0

; Grant R+W to Authenticated Users (S-1-5-11)
AccessControl::GrantOnFile "$SMSTARTUP\${project.name}.lnk" "(S-1-5-11)" "GenericRead + GenericWrite"

; Delete matching firewall rules
DetailPrint "Removing ${project.name} firewall rules..."
Expand Down Expand Up @@ -164,7 +171,7 @@ Section "Uninstall"
${If} ${RunningX64}
${DisableX64FSRedirection}
${EndIf}

; Remove ${vendor.company} certificates
nsExec::ExecToLog "cscript.exe //NoLogo //E:jscript $\"$INSTDIR\auth\${windows.keygen.name}$\" $\"$INSTDIR$\" uninstall"

Expand All @@ -174,7 +181,7 @@ Section "Uninstall"

; Remove startup entries
nsExec::ExecToLog "cscript.exe //NoLogo //E:jscript $\"$INSTDIR\utils\${windows.cleanup.name}$\" $\"${project.name}$\""

; Delete matching firewall rules
DetailPrint "Removing ${project.name} firewall rules..."
nsExec::ExecToLog "netsh.exe advfirewall firewall delete rule name= $\"${project.name}$\""
Expand All @@ -191,6 +198,7 @@ Section "Uninstall"

Delete "$DESKTOP\${project.name}.url"
Delete "$DESKTOP\${project.name}.lnk"
Delete "$SMSTARTUP\${project.name}.lnk"

; Sets the context of shell folders to current user
SetShellVarContext current
Expand Down
2 changes: 2 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@
</copy>
<copy file="${windows.jsonparser.in}" tofile="${windows.jsonparser.out}" />

<copy file="${windows.cleanup.in}" tofile="${windows.cleanup.out}" />

<exec executable="${nsisbin}" failonerror="true" >
<arg value="${windows.launcher.out}"/>
</exec>
Expand Down
39 changes: 6 additions & 33 deletions src/qz/deploy/DeployUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public boolean createShortcut(ToggleType toggleType) {
* @param toggleType Shortcut type, i.e. <code>ToggleType.STARTUP</code> or <code>ToggleType.DESKTOP</code>
* @return Whether or not the shortcut already exists
*/
public boolean hasShortcut(ToggleType toggleType) {
private boolean hasShortcut(ToggleType toggleType) {
boolean hasShortcut = false;
switch(toggleType) {
case STARTUP:
Expand Down Expand Up @@ -166,7 +166,7 @@ public boolean removeShortcut(ToggleType toggleType) {
* @return The calculated working path value, or an empty string if one
* could not be determined
*/
static String getParentDirectory(String filePath) {
private static String getParentDirectory(String filePath) {
// Working path should always default to the JARs parent folder
int lastSlash = filePath.lastIndexOf(File.separator);
return lastSlash < 0? "":filePath.substring(0, lastSlash);
Expand Down Expand Up @@ -202,25 +202,6 @@ public static DeployUtilities getSystemShortcutCreator() {
}
}

/**
* Creates all appropriate parent folders for the file path specified
*
* @param filePath The file in which to create parent directories for
* @return Whether or not the parent folder creation was successful
*/
static boolean createParentFolder(String filePath) {
String parentDirectory = getParentDirectory(filePath);
File f = new File(parentDirectory);
try {
f.mkdirs();
return f.exists();
}
catch(SecurityException e) {
log.error("Error while creating parent directories for: {}", filePath, e);
}
return false;
}

/**
* Returns whether or not a file exists
*
Expand Down Expand Up @@ -296,7 +277,8 @@ static boolean writeArrayToFile(String filePath, String[] array) {
* @param filePath The full file path to set the execute flag on
* @return <code>true</code> if successful, <code>false</code> otherwise
*/
static boolean setExecutable(String filePath) {
@SuppressWarnings("ResultOfMethodCallIgnored")
private static boolean setExecutable(String filePath) {
if (!SystemUtilities.isWindows()) {
try {
File f = new File(filePath);
Expand All @@ -315,7 +297,7 @@ static boolean setExecutable(String filePath) {
/**
* Gets the path to qz-tray.properties
*/
public static String detectPropertiesPath() {
private static String detectPropertiesPath() {
// Use supplied path from IDE or command line
// i.e -DsslPropertiesFile=C:\qz-tray.properties
String override = System.getProperty("sslPropertiesFile");
Expand Down Expand Up @@ -354,7 +336,7 @@ public static Properties loadTrayProperties() {
* @return A String value representing the absolute path to the currently running
* jar
*/
public static String detectJarPath() {
private static String detectJarPath() {
try {
String jarPath = new File(DeployUtilities.class.getProtectionDomain()
.getCodeSource().getLocation().getPath()).getCanonicalPath();
Expand All @@ -379,15 +361,6 @@ public String getJarPath() {
return jarPath;
}

/**
* Set the jar path for which we will create a shortcut for
*
* @param jarPath The full file path of the jar file
*/
public void setJarPath(String jarPath) {
this.jarPath = jarPath;
}

/**
* Small Enum for differentiating "desktop" and "startup"
*/
Expand Down
Loading

0 comments on commit a3a9066

Please sign in to comment.