Commit acd0ab2f authored by Maarten Billemont's avatar Maarten Billemont

Merge branch 'master' into rewrite

parents 909393af 3927d4e8
Pipeline #37291817 failed with stage
in 20 minutes and 50 seconds
......@@ -51,13 +51,13 @@ const char *mpw_askpass(const char *prompt) {
int pipes[2];
if (pipe( pipes ) == ERR) {
wrn( "Couldn't pipe: %s", strerror( errno ) );
wrn( "Couldn't create pipes for askpass: %s", strerror( errno ) );
return NULL;
}
pid_t pid = fork();
if (pid == ERR) {
wrn( "Couldn't fork for askpass:\n %s: %s", askpass, strerror( errno ) );
wrn( "Couldn't fork for askpass: %s", askpass, strerror( errno ) );
return NULL;
}
......@@ -83,15 +83,16 @@ const char *mpw_askpass(const char *prompt) {
return NULL;
}
if (WIFEXITED( status ) && WEXITSTATUS( status ) == EXIT_SUCCESS && answer && strlen( answer )) {
// Remove trailing newline.
if (answer[strlen( answer ) - 1] == '\n')
mpw_replace_string( answer, mpw_strndup( answer, strlen( answer ) - 1 ) );
return answer;
if (!WIFEXITED( status ) || WEXITSTATUS( status ) != EXIT_SUCCESS || !answer || !strlen( answer )) {
// askpass failed.
mpw_free_string( &answer );
return NULL;
}
mpw_free_string( &answer );
return NULL;
// Remove trailing newline.
if (answer[strlen( answer ) - 1] == '\n')
mpw_replace_string( answer, mpw_strndup( answer, strlen( answer ) - 1 ) );
return answer;
}
static const char *_mpw_getline(const char *prompt, bool silent) {
......
......@@ -22,9 +22,6 @@ public final class Platform {
if (null != (tryPlatform = construct( "com.lyndir.masterpassword.gui.util.platform.JDK9Platform" )))
activePlatform = tryPlatform;
else if (null != (tryPlatform = construct( "com.lyndir.masterpassword.gui.util.platform.ApplePlatform" )))
activePlatform = tryPlatform;
else
activePlatform = new BasePlatform();
}
......
package com.lyndir.masterpassword.gui.util.platform;
import com.apple.eawt.*;
import com.apple.eio.FileManager;
import com.google.common.base.Preconditions;
import com.lyndir.lhunath.opal.system.logging.Logger;
import java.io.*;
import java.net.URI;
/**
* @author lhunath, 2018-07-29
*/
public class ApplePlatform implements IPlatform {
private static final Logger logger = Logger.get( ApplePlatform.class );
private static final Application application = Preconditions.checkNotNull(
Application.getApplication(), "Not an Apple Java application." );
private AppForegroundListener appForegroundHandler;
private AppReOpenedListener appReopenHandler;
@Override
public boolean installAppForegroundHandler(final Runnable handler) {
if (appForegroundHandler == null)
application.addAppEventListener( appForegroundHandler = new AppForegroundListener() {
@Override
public void appMovedToBackground(final AppEvent.AppForegroundEvent e) {
}
@Override
public void appRaisedToForeground(final AppEvent.AppForegroundEvent e) {
handler.run();
}
} );
return true;
}
@Override
public boolean removeAppForegroundHandler() {
if (appForegroundHandler == null)
return false;
application.removeAppEventListener( appForegroundHandler );
return true;
}
@Override
public boolean installAppReopenHandler(final Runnable handler) {
application.addAppEventListener( appReopenHandler = e -> handler.run() );
return true;
}
@Override
public boolean removeAppReopenHandler() {
if (appReopenHandler == null)
return false;
application.removeAppEventListener( appReopenHandler );
return true;
}
@Override
public boolean requestForeground() {
application.requestForeground( true );
return true;
}
@Override
public boolean show(final File file) {
try {
return FileManager.revealInFinder( file );
}
catch (final FileNotFoundException e) {
logger.err( e, "While showing: %s", file );
return false;
}
}
@Override
public boolean open(final URI url) {
try {
FileManager.openURL( url.toString() );
return true;
}
catch (final IOException e) {
logger.err( e, "While opening: %s", url );
return false;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment