Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop nits #1276

Merged
merged 6 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .run/macos.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="macos" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="-d macOS" />
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method v="2" />
</configuration>
</component>
7 changes: 7 additions & 0 deletions .run/windows.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="windows" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="-d windows" />
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method v="2" />
</configuration>
</component>
8 changes: 7 additions & 1 deletion desktop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,10 @@ func (app *App) OnStatsChange(fn func(stats.Stats)) {
func (app *App) afterStart(cl *flashlightClient.Client) {
ctx := context.Background()
go app.fetchOrCreateUser(ctx)
go app.proClient.DesktopPaymentMethods(ctx)
if app.settings.GetUserID() != 0 {
// fetch plan only if user is created
go app.proClient.DesktopPaymentMethods(ctx)
}
go app.fetchDeviceLinkingCode(ctx)

app.OnSettingChange(settings.SNSystemProxy, func(val interface{}) {
Expand Down Expand Up @@ -667,9 +670,12 @@ func (app *App) ProClient() proclient.ProClient {
}

// Client session methods
// this method get call when user is being created first time
func (app *App) FetchUserData() error {
go app.proClient.UserData(context.Background())
go app.proClient.FetchPaymentMethodsAndCache(context.Background())
//Update UI
app.sendConfigOptions()
return nil
}

Expand Down
18 changes: 7 additions & 11 deletions desktop/datacap/datacap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"strconv"
"strings"
"sync"
"time"

"github.com/getlantern/flashlight/v7/bandwidth"
"github.com/getlantern/flashlight/v7/common"
Expand All @@ -28,13 +27,6 @@ var (
log = golog.LoggerFor("lantern-desktop.datacap")

translationAppName = strings.ToUpper(common.DefaultAppName)

uncapped = &bandwidth.Quota{
MiBAllowed: 0,
MiBUsed: 0,
AsOf: time.Now(),
TTLSeconds: 0,
}
)

type dataCap struct {
Expand All @@ -49,10 +41,14 @@ func ServeDataCap(channel ws.UIChannel, iconURL func() string, clickURL func() s
q, _ := bandwidth.GetQuota()
if q == nil {
// On client first connecting, if we don't have a datacap, assume we're uncapped
q = uncapped
uncapped := map[string]interface{}{
"percent": 0,
"mibUsed": 0,
"mibAllowed": 0,
}
log.Debugf("Sending current bandwidth quota to new client: %v", q)
write(uncapped)
}
log.Debugf("Sending current bandwidth quota to new client: %v", q)
write(q)
}
bservice, err := channel.Register("bandwidth", helloFn)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ func reportIssue(email, issueType, description *C.char) *C.char {
return C.CString("true")
}

//export updatePaymentMethod
func updatePaymentMethod() *C.char {
_, err := a.ProClient().DesktopPaymentMethods(context.Background())
if err != nil {
return sendError(err)
}
a.SendConfig()
return C.CString("true")
}

//export checkUpdates
func checkUpdates() *C.char {
log.Debug("Checking for updates")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
github.com/getlantern/eventual v1.0.0
github.com/getlantern/eventual/v2 v2.0.2
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c
github.com/getlantern/flashlight/v7 v7.6.173
github.com/getlantern/flashlight/v7 v7.6.175
github.com/getlantern/fronted v0.0.0-20241218113928-4db253857875
github.com/getlantern/geolookup v0.0.0-20230327091034-aebe73c6eef4
github.com/getlantern/golog v0.0.0-20230503153817-8e72de7e0a65
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ github.com/getlantern/fdcount v0.0.0-20210503151800-5decd65b3731/go.mod h1:XZwE+
github.com/getlantern/filepersist v0.0.0-20160317154340-c5f0cd24e799/go.mod h1:8DGAx0LNUfXNnEH+fXI0s3OCBA/351kZCiz/8YSK3i8=
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c h1:mcz27xtAkb1OuOLBct/uFfL1p3XxAIcFct82GbT+UZM=
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c/go.mod h1:8DGAx0LNUfXNnEH+fXI0s3OCBA/351kZCiz/8YSK3i8=
github.com/getlantern/flashlight/v7 v7.6.173 h1:JvFMZlysbBcURai0JsuIrnlku6EUsbWuqcSn3aTbcYI=
github.com/getlantern/flashlight/v7 v7.6.173/go.mod h1:2HDjD6lx7W5hbTh3Vg572bHVFd9YZ4YODLl2b+d7JBw=
github.com/getlantern/flashlight/v7 v7.6.175 h1:Jmkf4n6gxiUWLEcmTqSZNoLp7Q+CdUAuZgROwkHXBFI=
github.com/getlantern/flashlight/v7 v7.6.175/go.mod h1:2HDjD6lx7W5hbTh3Vg572bHVFd9YZ4YODLl2b+d7JBw=
github.com/getlantern/framed v0.0.0-20190601192238-ceb6431eeede h1:yrU6Px3ZkvCsDLPryPGi6FN+2iqFPq+JeCb7EFoDBhw=
github.com/getlantern/framed v0.0.0-20190601192238-ceb6431eeede/go.mod h1:nhnoiS6DE6zfe+BaCMU4YI01UpsuiXnDqM5S8jxHuuI=
github.com/getlantern/fronted v0.0.0-20241218113928-4db253857875 h1:i87Jjwv5XdhTMWvkU3zZusp9A5NvSbX39x38UEuJ3cw=
Expand Down
5 changes: 0 additions & 5 deletions internalsdk/session_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,6 @@ func (m *SessionModel) initSessionModel(ctx context.Context, opts *SessionModelO
pathdb.Mutate(m.db, func(tx pathdb.TX) error {
return pathdb.Put(tx, pathIsFirstTime, true, "")
})

// err = m.userCreate(ctx)
// if err != nil {
// log.Error(err)
// }
go m.proClient.RetryCreateUser(ctx, m, 10*time.Minute)
} else {
// Get all user details
Expand Down
40 changes: 20 additions & 20 deletions lib/core/app/app_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,26 @@ class _AppWebViewState extends State<AppWebView> {
onReceivedError: (controller, request, error) =>
showErrorDialog("Failed to load", error.description),
initialSettings: InAppWebViewSettings(
isInspectable: kDebugMode,
javaScriptEnabled: true,
supportZoom: true,
domStorageEnabled: true,
allowFileAccess: true,
useWideViewPort: !isDesktop(),
loadWithOverviewMode: !isDesktop(),
clearCache: true,
mixedContentMode: MixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW,
builtInZoomControls: Platform.isAndroid,
displayZoomControls: false,
mediaPlaybackRequiresUserGesture: false,
allowsInlineMediaPlayback: false,
underPageBackgroundColor: Colors.white,
transparentBackground: true,
allowFileAccessFromFileURLs: true,
preferredContentMode: isMobile()
? UserPreferredContentMode.MOBILE
: UserPreferredContentMode.RECOMMENDED,
),
isInspectable: kDebugMode,
javaScriptEnabled: true,
supportZoom: true,
domStorageEnabled: true,
allowFileAccess: true,
useWideViewPort: false,
loadWithOverviewMode: true,
clearCache: true,
mixedContentMode: MixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW,
builtInZoomControls: Platform.isAndroid,
displayZoomControls: false,
mediaPlaybackRequiresUserGesture: false,
allowsInlineMediaPlayback: false,
underPageBackgroundColor: Colors.white,
transparentBackground: true,
allowFileAccessFromFileURLs: true,
//We want to use mobile mode for webview on desktop
// Since we are showign app on mobile size it will be better to use mobile mode
// showing recommended mode user has to scroll a lot
preferredContentMode: UserPreferredContentMode.MOBILE),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this

onProgressChanged: (controller, progress) =>
appLogger.i("Loading progress: $progress%"),
),
Expand Down
10 changes: 7 additions & 3 deletions lib/core/service/lantern_ffi_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:isolate';

import 'package:ffi/ffi.dart';
import 'package:lantern/core/utils/common.dart';
import 'package:lantern/core/utils/common_desktop.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Expand Down Expand Up @@ -342,6 +341,13 @@ class LanternFFI {
checkAuthAPIError(result);
return Future.value(result.toBool());
}

static FutureOr<bool> updatePaymentPlans(dynamic context) {
final result =
_lanternFFI.updatePaymentMethod().cast<Utf8>().toDartString();
checkAPIError(result, 'we_are_experiencing_technical_difficulties'.i18n);
return Future.value(result.toBool());
}
}

// checkAPIError throws a PlatformException if the API response contains an error
Expand Down Expand Up @@ -375,5 +381,3 @@ void checkAuthAPIError(result) {
return;
}
}

// final lanternFFI = LanternFFI;
5 changes: 2 additions & 3 deletions lib/features/checkout/checkout_legacy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import 'package:retry/retry.dart';
class CheckoutLegacy extends StatefulWidget {
final Plan plan;
final bool isPro;

const CheckoutLegacy({
required this.plan,
required this.isPro,
Key? key,
}) : super(key: key);
super.key,
});

@override
State<CheckoutLegacy> createState() => _CheckoutLegacyState();
Expand Down
6 changes: 5 additions & 1 deletion lib/features/home/session_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ class SessionModel extends Model {

Widget proUser(ValueWidgetBuilder<bool> builder) {
if (isMobile()) {
return subscribedSingleValueBuilder<bool>('prouser', builder: builder,defaultValue: false);
return subscribedSingleValueBuilder<bool>('prouser',
builder: builder, defaultValue: false);
}
return FfiValueBuilder<bool>('prouser', proUserNotifier, builder);
}
Expand Down Expand Up @@ -607,6 +608,9 @@ class SessionModel extends Model {
}

Future<void> updatePaymentPlans() async {
if (isDesktop()) {
return compute(LanternFFI.updatePaymentPlans, '');
}
return methodChannel.invokeMethod('updatePaymentPlans', '');
}

Expand Down
5 changes: 5 additions & 0 deletions lib/features/vpn/vpn_bandwidth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class VPNBandwidth extends StatelessWidget {
// received any bandwidth updates
return const SizedBox();
}
// If the user is uncap, don't show the data usage
if (bandwidth.mibAllowed == 0) {
return const SizedBox();
}

return Column(
children: [
Container(
Expand Down
10 changes: 10 additions & 0 deletions lib/generated_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,16 @@ class NativeLibrary {
ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>)>();

ffi.Pointer<ffi.Char> updatePaymentMethod() {
return _updatePaymentMethod();
}

late final _updatePaymentMethodPtr =
_lookup<ffi.NativeFunction<ffi.Pointer<ffi.Char> Function()>>(
'updatePaymentMethod');
late final _updatePaymentMethod =
_updatePaymentMethodPtr.asFunction<ffi.Pointer<ffi.Char> Function()>();

ffi.Pointer<ffi.Char> checkUpdates() {
return _checkUpdates();
}
Expand Down
1 change: 1 addition & 0 deletions liblantern_amd64.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ extern char* deviceLinkingCode();
extern char* paymentRedirect(char* planID, char* currency, char* provider, char* email, char* deviceName);
extern void exitApp();
extern char* reportIssue(char* email, char* issueType, char* description);
extern char* updatePaymentMethod();
extern char* checkUpdates();

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions liblantern_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ extern char* deviceLinkingCode();
extern char* paymentRedirect(char* planID, char* currency, char* provider, char* email, char* deviceName);
extern void exitApp();
extern char* reportIssue(char* email, char* issueType, char* description);
extern char* updatePaymentMethod();
extern char* checkUpdates();

#ifdef __cplusplus
Expand Down
Loading