Experiment with user prompts
This commit is contained in:
parent
cb550af610
commit
c2d658be7b
|
@ -11,9 +11,9 @@ import java.io.FileNotFoundException;
|
|||
import java.io.Serializable;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
|
@ -115,7 +115,7 @@ public class License implements Serializable {
|
|||
}
|
||||
|
||||
if (Instant.now().isAfter(expires)) {
|
||||
throw new IllegalStateException("EXPIRED: " + toString());
|
||||
throw new IllegalStateException("EXPIRED since " + expires.atZone(ZoneId.systemDefault()).format(DateTimeFormatter.RFC_1123_DATE_TIME));
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@ -129,20 +129,4 @@ public class License implements Serializable {
|
|||
public static final SystemProperty<File> FILE = SystemProperty.of("net.filebot.license", File::new, ApplicationFolder.AppData.resolve("license.txt"));
|
||||
public static final MemoizedResource<License> INSTANCE = Resource.lazy(() -> new License(FILE.get()));
|
||||
|
||||
public static License configure(File file) throws Exception {
|
||||
// lock memoized resource while validating and setting a new license
|
||||
synchronized (INSTANCE) {
|
||||
// check if license file is valid and not expired
|
||||
License license = new License(file).check();
|
||||
|
||||
// write to default license file path
|
||||
Files.copy(file.toPath(), FILE.get().toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
// clear memoized instance and reload on next access
|
||||
INSTANCE.clear();
|
||||
|
||||
return license;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -165,15 +165,6 @@ public class Main {
|
|||
}
|
||||
}
|
||||
|
||||
private static void configureLicense(File f) {
|
||||
try {
|
||||
License license = License.configure(f);
|
||||
log.info(license + " has been activated.");
|
||||
} catch (Throwable e) {
|
||||
log.severe("License Error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void onStart(ArgumentBean args) throws Exception {
|
||||
// publish file arguments
|
||||
List<File> files = args.getFiles(false);
|
||||
|
|
|
@ -9,6 +9,8 @@ import java.io.FileInputStream;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Level;
|
||||
|
@ -146,6 +148,28 @@ public final class Settings {
|
|||
return LicenseModel.PGPSignedMessage;
|
||||
}
|
||||
|
||||
public static void configureLicense(File file) {
|
||||
try {
|
||||
// lock memoized resource while validating and setting a new license
|
||||
synchronized (License.INSTANCE) {
|
||||
// check if license file is valid and not expired
|
||||
License license = new License(file).check();
|
||||
|
||||
// confirmed valid license
|
||||
log.info(license + " has been activated.");
|
||||
|
||||
// write to default license file path
|
||||
Files.copy(file.toPath(), License.FILE.get().toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
// clear memoized instance and reload on next access
|
||||
License.INSTANCE.clear();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.severe("License Error: " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getAppStoreName() {
|
||||
if (isMacApp())
|
||||
return "Mac App Store";
|
||||
|
|
|
@ -11,6 +11,7 @@ import static net.filebot.util.ExceptionUtilities.*;
|
|||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.ui.SwingUI.*;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
|
@ -30,18 +31,22 @@ import java.util.logging.Level;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import net.filebot.HistorySpooler;
|
||||
import net.filebot.LicenseError;
|
||||
import net.filebot.MediaTypes;
|
||||
import net.filebot.NativeRenameAction;
|
||||
import net.filebot.ResourceManager;
|
||||
import net.filebot.StandardRenameAction;
|
||||
import net.filebot.UserFiles;
|
||||
import net.filebot.platform.mac.MacAppUtilities;
|
||||
import net.filebot.similarity.Match;
|
||||
import net.filebot.util.ui.ActionPopup;
|
||||
import net.filebot.util.ui.ProgressMonitor;
|
||||
import net.filebot.util.ui.ProgressMonitor.ProgressWorker;
|
||||
import net.filebot.util.ui.SwingEventBus;
|
||||
|
||||
class RenameAction extends AbstractAction {
|
||||
|
||||
|
@ -95,7 +100,8 @@ class RenameAction extends AbstractAction {
|
|||
ProgressMonitor.runTask(action.getDisplayName(), message, worker).get();
|
||||
}
|
||||
} catch (LicenseError e) {
|
||||
JOptionPane.showMessageDialog(window, e.getMessage(), "License Error", JOptionPane.WARNING_MESSAGE);
|
||||
JComponent source = (JComponent) evt.getSource();
|
||||
createLicensePopup(e.getMessage(), evt).show(source, -3, source.getHeight() + 4);
|
||||
return;
|
||||
} catch (CancellationException e) {
|
||||
debug.finest(e::toString);
|
||||
|
@ -226,6 +232,32 @@ class RenameAction extends AbstractAction {
|
|||
return emptyMap();
|
||||
}
|
||||
|
||||
private ActionPopup createLicensePopup(String message, ActionEvent parent) {
|
||||
ActionPopup actionPopup = new ActionPopup("License Required", ResourceManager.getIcon("file.lock"));
|
||||
|
||||
actionPopup.add(newAction("Select License", ResourceManager.getIcon("license.import"), e -> {
|
||||
withWaitCursor(parent.getSource(), () -> {
|
||||
List<File> files = UserFiles.FileChooser.AWT.showLoadDialogSelectFiles(false, false, null, MediaTypes.LICENSE_FILES, "Select License", parent);
|
||||
if (files.size() > 0) {
|
||||
configureLicense(files.get(0));
|
||||
SwingEventBus.getInstance().post(LICENSE);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
actionPopup.add(newAction("Purchase License", ResourceManager.getIcon("license.purchase"), e -> {
|
||||
openURI(getPurchaseURL());
|
||||
}));
|
||||
|
||||
actionPopup.addSeparator();
|
||||
|
||||
JLabel label = new JLabel(message, ResourceManager.getIcon("status.error"), JLabel.CENTER);
|
||||
label.setFont(label.getFont().deriveFont(9f).deriveFont(Font.BOLD));
|
||||
actionPopup.addDescription(label);
|
||||
|
||||
return actionPopup;
|
||||
}
|
||||
|
||||
protected static class StandardRenameWorker implements ProgressWorker<Map<File, File>> {
|
||||
|
||||
private Map<File, File> renameMap;
|
||||
|
|
|
@ -240,7 +240,7 @@ public class RenamePanel extends JComponent {
|
|||
|
||||
// settings popup and button
|
||||
ActionPopup settingsPopup = createSettingsPopup();
|
||||
final Action settingsPopupAction = new ShowPopupAction("Settings", ResourceManager.getIcon("action.settings"));
|
||||
Action settingsPopupAction = new ShowPopupAction("Settings", ResourceManager.getIcon("action.settings"));
|
||||
JButton settingsButton = createImageButton(settingsPopupAction);
|
||||
settingsButton.setComponentPopupMenu(settingsPopup);
|
||||
renameButton.setComponentPopupMenu(settingsPopup);
|
||||
|
|
|
@ -46,7 +46,7 @@ public class ActionPopup extends JPopupMenu {
|
|||
}
|
||||
|
||||
public void addDescription(JComponent component) {
|
||||
actionPanel.add(component, "gapx 4px, wrap 3px");
|
||||
actionPanel.add(component, "gapx 4px 4px, growx, wrap 3px");
|
||||
}
|
||||
|
||||
public void addAction(JComponent component) {
|
||||
|
|
Loading…
Reference in New Issue