Skip to content

Commit

Permalink
Added analytics and minor design fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bostrot committed Nov 6, 2021
1 parent 79e0053 commit dda362f
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 63 deletions.
Binary file modified build/windows/runner/Release/data/app.so
Binary file not shown.
Binary file modified build/windows/runner/Release/data/flutter_assets/NOTICES.Z
Binary file not shown.
Binary file modified build/windows/runner/Release/desktop_window_plugin.dll
Binary file not shown.
Binary file modified build/windows/runner/Release/system_theme_plugin.dll
Binary file not shown.
Binary file modified build/windows/runner/Release/url_launcher_windows_plugin.dll
Binary file not shown.
Binary file modified build/windows/runner/Release/wsl2distromanager.exe
Binary file not shown.
8 changes: 8 additions & 0 deletions lib/analytics.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
library wsl2distromanager.analytics;

import 'package:plausible_analytics/plausible_analytics.dart';

String analyticsUrl = "https://analytics.bostrot.com";
const String analyticsName = "wslmanager.bostrot.com";

Plausible plausible = Plausible(analyticsUrl, analyticsName);
6 changes: 2 additions & 4 deletions lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class App {
}
}
} catch (e) {
print(e);
// ignored
}
return '';
}
Expand All @@ -54,11 +54,10 @@ class App {
if (response.data.length > 0) {
var jsonData = json.decode(response.data);
String motd = jsonData['motd'];
print(motd);
return motd;
}
} catch (e) {
print(e);
// ignored
}
return '';
}
Expand Down Expand Up @@ -106,7 +105,6 @@ class WSLApi {
if (location == '') {
location = 'C:\\WSL2-Distros\\';
}
print("$distribution, $location + $distribution + '.tar'");
String exportRes =
await export(distribution, location + distribution + '.tar');
String importRes = await import(
Expand Down
9 changes: 8 additions & 1 deletion lib/dialog.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'api.dart';
import 'analytics.dart';

dialog({
required BuildContext context,
Expand All @@ -12,8 +13,11 @@ dialog({
String submitText = '',
ButtonStyle submitStyle = const ButtonStyle(),
bool submitInput = true,
String cancelText = 'Cancel',
Function? onCancel,
}) {
final controller = TextEditingController();
plausible.event(page: title.split(' ')[0].toLowerCase());
showDialog(
context: context,
builder: (context) {
Expand Down Expand Up @@ -42,8 +46,11 @@ dialog({
onSubmit(controller.text);
}),
Button(
child: const Text('Cancel'),
child: Text(cancelText),
onPressed: () {
if (onCancel != null) {
onCancel();
}
Navigator.pop(context);
}),
],
Expand Down
79 changes: 33 additions & 46 deletions lib/distro_create_component.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'analytics.dart';
import 'api.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:file_picker/file_picker.dart';
Expand Down Expand Up @@ -31,54 +32,39 @@ Widget createComponent(WSLApi api, Function(String, {bool loading}) statusMsg) {
child: FutureBuilder<List<String>>(
future: api.getDownloadable(),
builder: (context, snapshot) {
List<String> list = [];
if (snapshot.hasData) {
List<String> list = snapshot.data ?? [];
return AutoSuggestBox<String>(
controller: autoSuggestBox,
items: list,
onSelected: (text) {
print(text);
},
textBoxBuilder: (context, controller, focusNode, key) {
return TextBox(
key: key,
controller: controller,
focusNode: focusNode,
suffix: Row(children: [
IconButton(
icon: const Icon(FluentIcons.close, size: 15.0),
onPressed: () {
controller.clear();
focusNode.unfocus();
},
),
IconButton(
icon: const Icon(FluentIcons.open_folder_horizontal,
size: 15.0),
onPressed: () async {
FilePickerResult? result =
await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['*'],
);
list = snapshot.data ?? [];
} else if (snapshot.hasError) {}
return AutoSuggestBox<String>(
controller: autoSuggestBox,
items: list,
textBoxBuilder: (context, controller, focusNode, key) {
return TextBox(
key: key,
controller: controller,
focusNode: focusNode,
suffix: IconButton(
icon: const Icon(FluentIcons.open_folder_horizontal,
size: 15.0),
onPressed: () async {
FilePickerResult? result =
await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['*'],
);

if (result != null) {
controller.text = result.files.single.path!;
} else {
// User canceled the picker
}
},
),
]),
placeholder: 'Distro',
);
},
);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
// By default, show a loading spinner.
return const Center(child: ProgressRing());
if (result != null) {
controller.text = result.files.single.path!;
} else {
// User canceled the picker
}
},
),
placeholder: 'Distro',
);
},
);
}),
)),
Expanded(
Expand All @@ -103,6 +89,7 @@ Widget createComponent(WSLApi api, Function(String, {bool loading}) statusMsg) {
),
Button(
onPressed: () async {
plausible.event(name: "wsl_create");
List<String> downloadable = await api.getDownloadable();

if (nameController.text != '') {
Expand Down
12 changes: 6 additions & 6 deletions lib/distro_list_component.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import 'package:flutter/gestures.dart';

import 'analytics.dart';
import 'api.dart';
import 'dialog.dart';
import 'package:fluent_ui/fluent_ui.dart';

class DistroList extends StatefulWidget {
DistroList(
{Key? key,
required WSLApi this.api,
required Function(String, {bool loading}) this.statusMsg})
const DistroList({Key? key, required this.api, required this.statusMsg})
: super(key: key);

final WSLApi api;
Expand Down Expand Up @@ -77,6 +73,7 @@ FutureBuilder<Instances> distroList(
child: IconButton(
icon: const Icon(FluentIcons.play),
onPressed: () {
plausible.event(name: "wsl_started");
api.start(item);
Future.delayed(const Duration(milliseconds: 500),
statusMsg('$item started.'));
Expand All @@ -89,6 +86,7 @@ FutureBuilder<Instances> distroList(
child: IconButton(
icon: const Icon(FluentIcons.stop),
onPressed: () {
plausible.event(name: "wsl_stopped");
api.stop(item);
statusMsg('$item stopped.');
},
Expand All @@ -103,6 +101,7 @@ FutureBuilder<Instances> distroList(
child: IconButton(
icon: const Icon(FluentIcons.open_folder_horizontal),
onPressed: () async {
plausible.event(name: "wsl_explorer");
api.startExplorer(item);
},
),
Expand All @@ -112,6 +111,7 @@ FutureBuilder<Instances> distroList(
child: IconButton(
icon: const Icon(FluentIcons.visual_studio_for_windows),
onPressed: () async {
plausible.event(name: "wsl_vscode");
api.startVSCode(item);
},
),
Expand Down
56 changes: 51 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import 'package:desktop_window/desktop_window.dart';
//import 'package:desktop_window/desktop_window.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:system_theme/system_theme.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'api.dart';
import 'dialog.dart';
import 'distro_list_component.dart';
import 'distro_create_component.dart';

import 'analytics.dart';

// TODO: Update on release
const String currentVersion = "v0.5.2+1";
const String windowsStoreUrl = "https://www.microsoft.com/store/"
"productId/9NWS9K95NMJB";

const String windowsStoreUrl =
'https://www.microsoft.com/store/productId/9NWS9K95NMJB';
late SharedPreferences prefs;

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SystemTheme.accentInstance.load();
runApp(const MyApp());
doWhenWindowReady(() {
final win = appWindow;
final initialSize = Size(650, 500);
const initialSize = Size(650, 500);
win.minSize = initialSize;
win.size = initialSize;
win.alignment = Alignment.center;
Expand All @@ -29,6 +34,15 @@ void main() async {
});
//DesktopWindow.setWindowSize(const Size(650, 500));
//DesktopWindow.setMinWindowSize(const Size(650, 500));

prefs = await SharedPreferences.getInstance();
bool? privacyMode = prefs.getBool('privacyMode');
if (privacyMode != null && privacyMode) {
plausible.enabled = false;
}

// Enable analytics
plausible.event();
}

ThemeData themeData = ThemeData();
Expand Down Expand Up @@ -130,7 +144,6 @@ class _MyHomePageState extends State<MyHomePage> {

// Check motd
app.checkMotd().then((String motd) {
print(motd);
statusMsg(motd, leadingIcon: false);
});
}
Expand Down Expand Up @@ -241,6 +254,7 @@ class _MyHomePageState extends State<MyHomePage> {
children: [
TextButton(
onPressed: () async {
plausible.event(name: "url_clicked");
await canLaunch('https://bostrot.com')
? await launch('https://bostrot.com')
: throw 'Could not launch URL';
Expand All @@ -250,6 +264,7 @@ class _MyHomePageState extends State<MyHomePage> {
const Text('|', style: TextStyle(fontSize: 12.0)),
TextButton(
onPressed: () async {
plausible.event(name: "git_clicked");
await canLaunch(
'https://github.com/bostrot/wsl2-distro-manager')
? await launch(
Expand All @@ -261,12 +276,43 @@ class _MyHomePageState extends State<MyHomePage> {
const Text('|', style: TextStyle(fontSize: 12.0)),
TextButton(
onPressed: () async {
plausible.event(name: "donate_clicked");
await canLaunch('http://paypal.me/bostrot')
? await launch('http://paypal.me/bostrot')
: throw 'Could not launch URL';
},
child:
const Text("Donate", style: TextStyle(fontSize: 12.0))),
const Text('|', style: TextStyle(fontSize: 12.0)),
TextButton(
onPressed: () async {
plausible.event(name: "analytics_clicked");
dialog(
context: context,
item: "Allow",
api: api,
statusMsg: statusMsg,
title: 'Usage Data',
body: 'Do you want to share anonymous usage data to '
'improve this app?',
submitText: 'Enable privacy mode',
submitInput: false,
submitStyle: const ButtonStyle(),
cancelText: 'Share usage data',
onCancel: () async {
plausible.event(name: "privacy_off");
await prefs.setBool('privacyMode', false);
plausible.enabled = true;
},
onSubmit: (inputText) async {
plausible.event(name: "privacy_on");
await prefs.setBool('privacyMode', true);
plausible.enabled = false;
statusMsg('Privacy mode enabled.');
});
},
child:
const Text("Privacy", style: TextStyle(fontSize: 12.0))),
],
)
],
Expand Down
Loading

0 comments on commit dda362f

Please sign in to comment.