updates to display when gui opens but before startup window

This commit is contained in:
Greg DiCristofaro 2023-10-19 13:54:46 -04:00
parent ea75fcd45b
commit e4d240e6f0
4 changed files with 60 additions and 37 deletions

View File

@ -1,6 +1,20 @@
/* /*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Autopsy Forensic Browser
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template *
* Copyright 2017-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.sleuthkit.autopsy.centralrepository.eventlisteners; package org.sleuthkit.autopsy.centralrepository.eventlisteners;
@ -10,7 +24,6 @@ import java.util.logging.Level;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.windows.OnShowing;
import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings; import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings;
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbChoice; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbChoice;
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbManager; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbManager;
@ -21,25 +34,28 @@ import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.ModuleSettings;
/** /**
* * Runs the default setup for central repository and notifies the user if a)
* @author gregd * running with GUI and b) first launch.
*/ */
@OnShowing public class CRDefaultSetupAction {
public class OnUIShowing implements Runnable {
private static final Logger logger = Logger.getLogger(OnUIShowing.class.getName());
@Override private static final Logger logger = Logger.getLogger(CRDefaultSetupAction.class.getName());
public void run() { private static final CRDefaultSetupAction INSTANCE = new CRDefaultSetupAction();
setupDefaultCentralRepository();
public static CRDefaultSetupAction getInstance() {
return INSTANCE;
}
private CRDefaultSetupAction() {
} }
/** /**
* Checks if the central repository has been set up and configured. If not, * Checks if the central repository has been set up and configured. If not,
* does the set up unconditionally. If the application is running with a * does the set up unconditionally.
* GUI, a notification will be displayed to the user if the mode is RELEASE *
* (in other words, developers are exempt from seeing the notification). * @return Returns true if first run and a default CR was setup.
*/ */
private void setupDefaultCentralRepository() { public boolean setupDefaultCentralRepository() {
Map<String, String> centralRepoSettings = ModuleSettings.getConfigSettings(CentralRepoSettings.getInstance().getModuleSettingsKey()); Map<String, String> centralRepoSettings = ModuleSettings.getConfigSettings(CentralRepoSettings.getInstance().getModuleSettingsKey());
String initializedStr = centralRepoSettings.get("initialized"); String initializedStr = centralRepoSettings.get("initialized");
@ -57,11 +73,7 @@ public class OnUIShowing implements Runnable {
} }
if (initialized) { if (initialized) {
return; // Nothing to do return false; // Nothing to do
}
if (CentralRepositoryNotificationDialog.shouldDisplay()) {
CentralRepositoryNotificationDialog.display();
} }
try { try {
@ -79,6 +91,7 @@ public class OnUIShowing implements Runnable {
} }
ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true");
return true;
} }
/** /**
@ -103,5 +116,4 @@ public class OnUIShowing implements Runnable {
} }
} }
} }

View File

@ -33,7 +33,7 @@ public class CentralRepositoryNotificationDialog {
* This dialog should display iff the mode is RELEASE and the * This dialog should display iff the mode is RELEASE and the
* application is running with a GUI. * application is running with a GUI.
*/ */
static boolean shouldDisplay() { public static boolean shouldDisplay() {
return //Version.getBuildType() == Version.Type.RELEASE return //Version.getBuildType() == Version.Type.RELEASE
//&& //&&
RuntimeProperties.runningWithGUI(); RuntimeProperties.runningWithGUI();
@ -51,7 +51,7 @@ public class CentralRepositoryNotificationDialog {
"CentralRepositoryNotificationDialog.bulletThree=Create personas that group accounts", "CentralRepositoryNotificationDialog.bulletThree=Create personas that group accounts",
"CentralRepositoryNotificationDialog.finalRemarks=To limit what is stored, use the Central Repository options panel." "CentralRepositoryNotificationDialog.finalRemarks=To limit what is stored, use the Central Repository options panel."
}) })
static void display() { public static void display() {
assert shouldDisplay(); assert shouldDisplay();
MessageNotifyUtil.Message.info( MessageNotifyUtil.Message.info(

View File

@ -20,21 +20,12 @@ package org.sleuthkit.autopsy.centralrepository.eventlisteners;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.openide.modules.ModuleInstall; import org.openide.modules.ModuleInstall;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbChoice;
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbManager;
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoException;
import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings; import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings;
import org.sleuthkit.autopsy.core.RuntimeProperties;
import org.sleuthkit.autopsy.core.UserPreferences;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.ModuleSettings;
import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.coreutils.PlatformUtil;

View File

@ -43,6 +43,8 @@ import org.openide.util.Exceptions;
import org.openide.util.Lookup; import org.openide.util.Lookup;
import org.openide.windows.WindowManager; import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.StartupWindowProvider; import org.sleuthkit.autopsy.casemodule.StartupWindowProvider;
import org.sleuthkit.autopsy.centralrepository.eventlisteners.CRDefaultSetupAction;
import org.sleuthkit.autopsy.centralrepository.eventlisteners.CentralRepositoryNotificationDialog;
import org.sleuthkit.autopsy.commandlineingest.CommandLineOptionProcessor; import org.sleuthkit.autopsy.commandlineingest.CommandLineOptionProcessor;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.ModuleSettings;
@ -89,6 +91,12 @@ public class Installer extends ModuleInstall {
final CommandLineOptionProcessor finalprocessor = processor; final CommandLineOptionProcessor finalprocessor = processor;
/**
* Runs central repo default setup. Triggered here to track if this is
* first time setup in order to show CR notification dialog prior to any
* startup window.
*/
final boolean crFirstTimeSetup = CRDefaultSetupAction.getInstance().setupDefaultCentralRepository();
// When the --nogui flag is supplied invokeWhenUIReady happens a lot sooner // When the --nogui flag is supplied invokeWhenUIReady happens a lot sooner
// than it would when running wiht the gui. Makes sense. That means that // than it would when running wiht the gui. Makes sense. That means that
@ -102,19 +110,31 @@ public class Installer extends ModuleInstall {
// be called. // be called.
WindowManager.getDefault().invokeWhenUIReady(() -> { WindowManager.getDefault().invokeWhenUIReady(() -> {
if(WindowManager.getDefault().getMainWindow().isVisible() || finalprocessor == null || finalprocessor.getState() == CommandLineOptionProcessor.ProcessState.COMPLETED) { if(WindowManager.getDefault().getMainWindow().isVisible() || finalprocessor == null || finalprocessor.getState() == CommandLineOptionProcessor.ProcessState.COMPLETED) {
StartupWindowProvider.getInstance().open(); showStartupWindows(crFirstTimeSetup);
} else { } else {
finalprocessor.addPropertyChangeListener(new PropertyChangeListener(){ finalprocessor.addPropertyChangeListener(new PropertyChangeListener(){
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if(evt.getPropertyName().equals(CommandLineOptionProcessor.PROCESSING_COMPLETED)) { if(evt.getPropertyName().equals(CommandLineOptionProcessor.PROCESSING_COMPLETED)) {
showStartupWindows(crFirstTimeSetup);
}
}
});
}
});
}
/**
* Show startup window(s) in sequence.
* @param crFirstTimeSetup If true, attempts to show the central repo notification dialog
*/
private void showStartupWindows(boolean crFirstTimeSetup) {
if (crFirstTimeSetup && CentralRepositoryNotificationDialog.shouldDisplay()) {
CentralRepositoryNotificationDialog.display();
}
StartupWindowProvider.getInstance().open(); StartupWindowProvider.getInstance().open();
} }
}
});
}
});
}
@Override @Override
public void uninstalled() { public void uninstalled() {