Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autostart by default #107

Merged
merged 1 commit into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 "$jarpath"
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
2 changes: 1 addition & 1 deletion ant/firefox/locator.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function get_targetdir()
lowerbin=$(echo "$with_bin" |tr '[:upper:]' '[:lower:]')
location=$(readlink -f "$(which $lowerdir)")
targetdir=$(dirname "$location")
if [ -f "$targetdir/$lowerbin" ]; then
if [[ "$targetdir" != "/usr/bin" ]] && [ -f "$targetdir/$lowerbin" ]; then
dir_out="$targetdir"
return 0
else
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 @@ -192,6 +192,24 @@ progress_dialog 92 "Installing usb/udev rules..."
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

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 1>&2
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 @@ -145,6 +145,12 @@ if [ -n "$sslcertpath" ]; then
exit $status
fi

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

echo "Creating keystore for secure websockets..."
eval "$makekeystore" > /dev/null 2>&1
check_exists "$keystorepath"
Expand Down
Binary file not shown.
Binary file not shown.
48 changes: 48 additions & 0 deletions ant/windows/windows-cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/** Post-Install Cleanup **/

var app = getArg(0);

if (app) {
removeStartupEntries(app);
} else {
WScript.Echo("No app name provided. Exiting.");
WScript.Quit(1);
}

WScript.Quit(0);

/**
* Cycles through all users on system and removes matching startup entries.
*/
function removeStartupEntries(app) {
WScript.Echo('Removing startup entries for all users matching "' + app + '"');
var shell = new ActiveXObject("WScript.shell");
// get all users
var proc = shell.Exec('reg.exe query HKU');
var users = proc.StdOut.ReadAll().split(/[\r\n]+/);
for (var i = 0; i < users.length; i++) {
try {
var key = trim(users[i]) + "\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\" + app;
shell.RegDelete(key);
WScript.Echo(' - [success] Removed "' + app + '" startup in ' + users[i]);
} catch(ignore) {}
}
}

/*
* Gets then nth argument passed into this script
* Returns defaultVal if argument wasn't found
*/
function getArg(index, defaultVal) {
if (index >= WScript.Arguments.length || trim(WScript.Arguments(index)) == "") {
return defaultVal;
}
return WScript.Arguments(index);
}

/*
* Functional equivalent of foo.trim()
*/
function trim(val) {
return val.replace(/^\s+/,'').replace(/\s+$/,'');
}
10 changes: 9 additions & 1 deletion ant/windows/windows-packager.nsi.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ Section

; 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..."
Expand Down Expand Up @@ -123,6 +126,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 @@ -172,6 +179,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
3 changes: 3 additions & 0 deletions ant/windows/windows.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ windows.keygen.tool=certutil.exe
windows.nsis.addons=${basedir}/ant/windows/nsis
windows.packager.in=${basedir}/ant/windows/windows-packager.nsi.in
windows.packager.out=${build.dir}/windows-packager.nsi
windows.cleanup.name=windows-cleanup.js
windows.cleanup.in=${basedir}/ant/windows/${windows.cleanup.name}
windows.cleanup.out=${dist.dir}/utils/${windows.cleanup.name}
windows.launcher.in=${basedir}/ant/windows/windows-launcher.nsi.in
windows.launcher.out=${build.dir}/windows-launcher.nsi

Expand Down
2 changes: 2 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@
<filterchain><expandproperties/></filterchain>
</copy>

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

<exec executable="${nsisbin}" failonerror="true" >
<arg value="${windows.launcher.out}"/>
</exec>
Expand Down
40 changes: 6 additions & 34 deletions src/qz/deploy/DeployUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,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 @@ -165,7 +165,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 @@ -201,25 +201,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 @@ -295,7 +276,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 @@ -314,7 +296,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 All @@ -326,7 +308,6 @@ public static String detectPropertiesPath() {
String propFile = Constants.PROPS_FILE + ".properties";

// Use relative path based on qz-tray.jar, fix %20
// TODO: Find a better way to fix the unicode chars?
return fixWhitespaces(getParentDirectory(jarPath) + File.separator + propFile);
}

Expand Down Expand Up @@ -356,7 +337,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 {
return new File(DeployUtilities.class.getProtectionDomain()
.getCodeSource().getLocation().getPath()).getCanonicalPath();
Expand All @@ -379,15 +360,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