mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Add API for restarting IDE with elevation
This is used in Rider to allow debugging processes which require extra privileges
This commit is contained in:
committed by
Dmitry Jemerov
parent
c23a84f0a9
commit
c3b534b28c
+8
-4
@@ -744,6 +744,10 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
|
||||
}
|
||||
|
||||
public void exit(boolean force, boolean exitConfirmed, boolean restart, @NotNull String[] beforeRestart) {
|
||||
exit(force, exitConfirmed, restart, false, beforeRestart);
|
||||
}
|
||||
|
||||
public void exit(boolean force, boolean exitConfirmed, boolean restart, boolean elevate, @NotNull String[] beforeRestart) {
|
||||
if (!force) {
|
||||
if (myExitInProgress) return;
|
||||
if (!exitConfirmed && getDefaultModalityState() != ModalityState.NON_MODAL) return;
|
||||
@@ -751,14 +755,14 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
|
||||
|
||||
myExitInProgress = true;
|
||||
if (isDispatchThread()) {
|
||||
doExit(force, exitConfirmed, restart, beforeRestart);
|
||||
doExit(force, exitConfirmed, restart, elevate, beforeRestart);
|
||||
}
|
||||
else {
|
||||
invokeLater(() -> doExit(force, exitConfirmed, restart, beforeRestart), ModalityState.NON_MODAL);
|
||||
invokeLater(() -> doExit(force, exitConfirmed, restart, elevate, beforeRestart), ModalityState.NON_MODAL);
|
||||
}
|
||||
}
|
||||
|
||||
private void doExit(boolean force, boolean exitConfirmed, boolean restart, String[] beforeRestart) {
|
||||
private void doExit(boolean force, boolean exitConfirmed, boolean restart, boolean elevate, String[] beforeRestart) {
|
||||
try {
|
||||
if (!force && !confirmExitIfNeeded(exitConfirmed)) {
|
||||
return;
|
||||
@@ -786,7 +790,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
|
||||
int exitCode = 0;
|
||||
if (restart && Restarter.isSupported()) {
|
||||
try {
|
||||
Restarter.scheduleRestart(beforeRestart);
|
||||
Restarter.scheduleRestart(elevate, beforeRestart);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
LOG.error("Restart failed", t);
|
||||
|
||||
@@ -104,9 +104,13 @@ public class Restarter {
|
||||
}
|
||||
|
||||
public static void scheduleRestart(@NotNull String... beforeRestart) throws IOException {
|
||||
scheduleRestart(false, beforeRestart);
|
||||
}
|
||||
|
||||
public static void scheduleRestart(Boolean elevate, @NotNull String... beforeRestart) throws IOException {
|
||||
Logger.getInstance(Restarter.class).info("restart: " + Arrays.toString(beforeRestart));
|
||||
if (SystemInfo.isWindows) {
|
||||
restartOnWindows(beforeRestart);
|
||||
restartOnWindows(elevate, beforeRestart);
|
||||
}
|
||||
else if (SystemInfo.isMac) {
|
||||
restartOnMac(beforeRestart);
|
||||
@@ -119,7 +123,7 @@ public class Restarter {
|
||||
}
|
||||
}
|
||||
|
||||
private static void restartOnWindows(String... beforeRestart) throws IOException {
|
||||
private static void restartOnWindows(Boolean elevate, String... beforeRestart) throws IOException {
|
||||
Kernel32 kernel32 = Native.loadLibrary("kernel32", Kernel32.class);
|
||||
Shell32 shell32 = Native.loadLibrary("shell32", Shell32.class);
|
||||
|
||||
@@ -146,7 +150,13 @@ public class Restarter {
|
||||
args.add(String.valueOf(pid));
|
||||
args.add(String.valueOf(beforeRestart.length));
|
||||
Collections.addAll(args, beforeRestart);
|
||||
args.add(String.valueOf(argv.length));
|
||||
if (elevate) {
|
||||
args.add(String.valueOf(argv.length + 1));
|
||||
args.add(new File(PathManager.getBinPath(), "launcher.exe").getPath());
|
||||
}
|
||||
else {
|
||||
args.add(String.valueOf(argv.length));
|
||||
}
|
||||
Collections.addAll(args, argv);
|
||||
runRestarter(new File(PathManager.getBinPath(), "restarter.exe"), args);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user