Skip to content

Commit

Permalink
If we have to use fake browser for donation then assume donated
Browse files Browse the repository at this point in the history
  • Loading branch information
parg committed Nov 16, 2023
1 parent dcc57e3 commit 209f447
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
7 changes: 7 additions & 0 deletions uis/src/com/biglybt/ui/swt/BrowserWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package com.biglybt.ui.swt;

import java.util.function.Consumer;

import org.eclipse.swt.browser.CloseWindowListener;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.browser.ProgressListener;
Expand Down Expand Up @@ -96,6 +98,11 @@
setUrl(
String url );

public abstract void
setFakeUrl(
String url,
Consumer<String> click_listener );

public abstract void
setText(
String text );
Expand Down
44 changes: 38 additions & 6 deletions uis/src/com/biglybt/ui/swt/BrowserWrapperFake.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
Expand Down Expand Up @@ -56,7 +57,9 @@
private Label link_label;
private Label description_label;

private String url;
private String url;
private Consumer<String> url_listener;

private String description;

private List<LocationListener> location_listeners = new ArrayList<>();
Expand Down Expand Up @@ -147,14 +150,25 @@ public void widgetSelected(SelectionEvent e) {
link_label.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
Utils.launch( url );
launch();
}
@Override
public void mouseUp(MouseEvent e) {

if ( e.button == 1 && e.stateMask != SWT.CONTROL){

Utils.launch( url );
launch();
}
}

private void
launch()
{
Utils.launch( url );

if ( url_listener != null ){

url_listener.accept( url );
}
}
});
Expand Down Expand Up @@ -260,13 +274,31 @@ public String getText() {
return( url );
}

@Override
public void
setFakeUrl(
String url,
Consumer<String> listener )
{
setUrl( url, listener );
}

@Override
public void
setUrl(
final String _url )
String url )
{
url = _url;

setUrl( url, null );
}

private void
setUrl(
final String _url,
Consumer<String> _listener )
{
url = _url;
url_listener = _listener;

Utils.execSWTThread(
new Runnable()
{
Expand Down
15 changes: 15 additions & 0 deletions uis/src/com/biglybt/ui/swt/BrowserWrapperSWT.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package com.biglybt.ui.swt;

import java.util.function.Consumer;

import org.eclipse.swt.browser.Browser;
//import org.eclipse.swt.chromium.Browser;

Expand All @@ -38,6 +40,8 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

import com.biglybt.core.util.Debug;

public class
BrowserWrapperSWT
extends BrowserWrapper
Expand Down Expand Up @@ -128,6 +132,17 @@
return( browser.getUrl());
}

@Override
public void
setFakeUrl(
String url,
Consumer<String> listener )
{
Debug.out( "Should be called on fake browser..." );

setUrl(url);
}

@Override
public void
setUrl(
Expand Down
6 changes: 4 additions & 2 deletions uis/src/com/biglybt/ui/swt/donations/DonationWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,13 @@ public void changed(LocationEvent event) {

if ( browser.isFake()){

browser.setUrl( Constants.URL_DONATION );
browser.setFakeUrl( Constants.URL_DONATION, (s)->{
neverAskAgain();
});

browser.setText( "Please follow the link to donate via an external browser" );

shell.setSize( 400, 500 );
shell.setSize( 800, 500 );

Utils.centreWindow(shell);

Expand Down

0 comments on commit 209f447

Please sign in to comment.