提交 40c616e2 编写于 作者: S Serge Rider

#2818 Auto-download fresh version on update check.

+ Early access link if no new version found.


Former-commit-id: 2b6b0fe8
上级 bc180c7a
......@@ -37,6 +37,7 @@
<property name="website" value="%productWebsite"/>
<property name="email" value="%productEmail"/>
<property name="versionUpdateURL" value="https://dbeaver.io/product/version.xml"/>
<property name="earlyAccessURL" value="https://dbeaver.io/files/ea"/>
<property name="windowImages" value="/icons/dbeaver16.png,/icons/dbeaver32.png,/icons/dbeaver48.png,/icons/dbeaver64.png,/icons/dbeaver256.png"/>
<property name="appName" value="DBeaver"/>
<property name="startupForegroundColor" value="000000"/>
......
......@@ -511,10 +511,11 @@ public class DBeaverApplication implements IApplication, DBPApplication {
return msgResult;
}
public void notifyVersionUpgrade(VersionDescriptor versionDescriptor, boolean showSkip) {
public void notifyVersionUpgrade(VersionDescriptor currentVersion, VersionDescriptor newVersion, boolean showSkip) {
VersionUpdateDialog dialog = new VersionUpdateDialog(
UIUtils.getActiveWorkbenchShell(),
versionDescriptor,
currentVersion,
newVersion,
showSkip);
dialog.open();
}
......
......@@ -30,7 +30,6 @@ import org.jkiss.dbeaver.registry.updater.VersionDescriptor;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.osgi.framework.Version;
import java.io.IOException;
import java.util.Calendar;
......@@ -107,18 +106,18 @@ public class DBeaverVersionChecker extends AbstractJob {
versionDescriptor.getProgramVersion().compareTo(GeneralUtils.getProductVersion()) > 0 &&
!VersionUpdateDialog.isSuppressed(versionDescriptor))
{
showUpdaterDialog(versionDescriptor);
showUpdaterDialog(versionDescriptor, versionDescriptor);
} else if (showAlways) {
showUpdaterDialog(null);
showUpdaterDialog(versionDescriptor, null);
}
return Status.OK_STATUS;
}
private void showUpdaterDialog(final VersionDescriptor versionDescriptor)
private void showUpdaterDialog(VersionDescriptor currentVersion, final VersionDescriptor newVersion)
{
UIUtils.asyncExec(() -> {
DBeaverApplication.getInstance().notifyVersionUpgrade(versionDescriptor, !showAlways);
DBeaverApplication.getInstance().notifyVersionUpgrade(currentVersion, newVersion, !showAlways);
});
}
}
......@@ -16,6 +16,8 @@
*/
package org.jkiss.dbeaver.core.application.update;
import org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.osgi.util.NLS;
......@@ -26,29 +28,47 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.application.internal.CoreApplicationActivator;
import org.jkiss.dbeaver.registry.updater.VersionDescriptor;
import org.jkiss.dbeaver.ui.ActionUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import org.jkiss.utils.CommonUtils;
public class VersionUpdateDialog extends Dialog {
private VersionDescriptor newVersion;
private static final int INFO_ID = 1000;
private static final int UPGRADE_ID = 1001;
private static final int CHECK_EA_ID = 1002;
private VersionDescriptor currentVersion;
@Nullable
private VersionDescriptor newVersion;
private Font boldFont;
private boolean showConfig;
private Button dontShowAgainCheck;
private final String earlyAccessURL;
public VersionUpdateDialog(Shell parentShell, VersionDescriptor newVersion, boolean showConfig)
public VersionUpdateDialog(Shell parentShell, VersionDescriptor currentVersion, @Nullable VersionDescriptor newVersion, boolean showConfig)
{
super(parentShell);
this.currentVersion = currentVersion;
this.newVersion = newVersion;
this.showConfig = showConfig;
earlyAccessURL = Platform.getProduct().getProperty("earlyAccessURL");
}
public VersionDescriptor getCurrentVersion() {
return currentVersion;
}
@Nullable
public VersionDescriptor getNewVersion() {
return newVersion;
}
......@@ -178,23 +198,25 @@ public class VersionUpdateDialog extends Dialog {
}
if (newVersion != null) {
/*
// Disable P2 update. Doesn't work and can't work properly in most cases.
boolean hasUpdate = Platform.getBundle(CheckForUpdateAction.P2_PLUGIN_ID) != null;
if (hasUpdate) {
createButton(
parent,
IDialogConstants.PROCEED_ID,
"Update",
true);
}
*/
createButton(
parent,
INFO_ID,
CoreMessages.dialog_version_update_button_more_info,
UPGRADE_ID,
"Upgrade ...",
true);
} else {
if (!CommonUtils.isEmpty(earlyAccessURL)) {
createButton(
parent,
CHECK_EA_ID,
"Early Access",
false);
}
}
createButton(
parent,
INFO_ID,
CoreMessages.dialog_version_update_button_more_info,
false);
createButton(
parent,
......@@ -206,12 +228,22 @@ public class VersionUpdateDialog extends Dialog {
@Override
protected void buttonPressed(int buttonId)
{
if (dontShowAgainCheck != null && dontShowAgainCheck.getSelection()) {
if (dontShowAgainCheck != null && dontShowAgainCheck.getSelection() && newVersion != null) {
CoreApplicationActivator.getDefault().getPreferenceStore().setValue("suppressUpdateCheck." + newVersion.getPlainVersion(), true);
}
if (buttonId == INFO_ID) {
if (newVersion != null) {
UIUtils.launchProgram(newVersion.getBaseURL());
} else if (currentVersion != null) {
UIUtils.launchProgram(currentVersion.getBaseURL());
}
} else if (buttonId == UPGRADE_ID) {
if (newVersion != null) {
UIUtils.launchProgram(makeDownloadURL(newVersion.getBaseURL()));
}
} else if (buttonId == CHECK_EA_ID) {
if (!CommonUtils.isEmpty(earlyAccessURL)) {
UIUtils.launchProgram(earlyAccessURL);
}
} else if (buttonId == IDialogConstants.PROCEED_ID) {
final IWorkbenchWindow window = UIUtils.getActiveWorkbenchWindow();
......@@ -225,6 +257,31 @@ public class VersionUpdateDialog extends Dialog {
close();
}
private String makeDownloadURL(String baseURL) {
while (baseURL.endsWith("/")) baseURL = baseURL.substring(0, baseURL.length() - 1);
String os = Platform.getOS();
switch (os) {
case "win32": os = "win"; break;
case "macosx": os = "mac"; break;
default: os = "linux"; break;
}
String arch = Platform.getOSArch();
String dist = null;
if (os.equals("linux")) {
// Determine package manager
try {
RuntimeUtils.executeProcess("/usr/bin/apt-get", "--version");
dist = "deb";
} catch (DBException e) {
dist = "rpm";
}
}
return baseURL + "?start" +
"&os=" + os +
"&arch=" + arch +
(dist == null ? "" : "&dist=" + dist);
}
public static boolean isSuppressed(VersionDescriptor version) {
CoreApplicationActivator activator = CoreApplicationActivator.getDefault();
return activator != null && activator.getPreferenceStore().getBoolean("suppressUpdateCheck." + version.getPlainVersion());
......
......@@ -281,7 +281,7 @@ dialog_tunnel_checkbox_use_handler = Use {0}
dialog_tunnel_title = Configure networks handlers and tunnels
dialog_version_update_available_new_version = New version of {0} is available.
dialog_version_update_button_more_info = Update ...
dialog_version_update_button_more_info = Details ...
dialog_version_update_current_version = Current version
dialog_version_update_n_a = N/A
dialog_version_update_new_version = New version
......
......@@ -16,12 +16,11 @@
*/
package org.jkiss.dbeaver.utils;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.connection.DBPNativeClientLocation;
import org.jkiss.dbeaver.model.runtime.AbstractJob;
......@@ -32,17 +31,17 @@ import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.StandardConstants;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* RuntimeUtils
......@@ -236,6 +235,28 @@ public class RuntimeUtils {
return monitoringTask.finished;
}
public static String executeProcess(String binPath, String ... args) throws DBException {
try {
String[] cmdBin = {binPath};
String[] cmd = args == null ? cmdBin : ArrayUtils.concatArrays(cmdBin, args);
Process p = Runtime.getRuntime().exec(cmd);
try {
try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
String line;
if ((line = input.readLine()) != null) {
return line;
}
}
return null;
} finally {
p.destroy();
}
}
catch (Exception ex) {
throw new DBException("Error executing process " + binPath, ex);
}
}
public static boolean isPlatformMacOS() {
return Platform.getOS().toLowerCase().contains("macos");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册