Skip to content

Commit

Permalink
wip: Upgrading project
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed May 18, 2024
1 parent 0e03e15 commit 633b832
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 135 deletions.
23 changes: 1 addition & 22 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
include: package:flutter_lints/flutter.yaml

linter:
rules:
## Error Rules
- always_use_package_imports
## Style rules
- directives_ordering
- eol_at_end_of_file
- file_names
- flutter_style_todos
- library_names
- library_prefixes
- prefer_is_empty
- prefer_is_not_empty
- prefer_is_not_operator
- prefer_null_aware_method_calls
- prefer_single_quotes
- sort_constructors_first
- sort_unnamed_constructors_first
## Pub rules
- sort_pub_dependencies
include: package:mostly_reasonable_lints/flutter.yaml
30 changes: 1 addition & 29 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
include: package:mostly_reasonable_lints/flutter.yaml
77 changes: 65 additions & 12 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import 'dart:io';

import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:launch_at_startup/launch_at_startup.dart';
import 'package:package_info_plus/package_info_plus.dart';

import './pages/home.dart';

void main() async {
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

if (!kIsWeb) {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
LaunchAtStartup.instance.setup(
launchAtStartup.setup(
appName: packageInfo.appName,
appPath: Platform.resolvedExecutable,
packageName: 'dev.leanflutter.examples.launchatstartupexample',
Expand All @@ -24,7 +22,7 @@ void main() async {
}

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
const MyApp({super.key});

@override
State<MyApp> createState() => _MyAppState();
Expand All @@ -34,15 +32,70 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: const Color(0xff416ff4),
canvasColor: Colors.white,
scaffoldBackgroundColor: const Color(0xffF7F9FB),
dividerColor: Colors.grey.withOpacity(0.3),
),
builder: BotToastInit(),
navigatorObservers: [BotToastNavigatorObserver()],
home: const HomePage(),
);
}
}

class HomePage extends StatefulWidget {
const HomePage({super.key});

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
bool _isEnabled = false;

@override
void initState() {
super.initState();
_init();
}

_init() async {
_isEnabled = await launchAtStartup.isEnabled();
setState(() {});
}

_handleEnable() async {
await launchAtStartup.enable();
await _init();
}

_handleDisable() async {
await launchAtStartup.disable();
await _init();
}

Widget _buildBody(BuildContext context) {
return ListView(
children: <Widget>[
ListTile(
title: const Text('enable'),
onTap: _handleEnable,
),
ListTile(
title: const Text('disable'),
onTap: _handleDisable,
),
ListTile(
title: const Text('isEnabled'),
trailing: Text('$_isEnabled'),
),
],
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: _buildBody(context),
);
}
}
2 changes: 1 addition & 1 deletion example/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:package_info_plus/package_info_plus.dart';
import 'package:preference_list/preference_list.dart';

class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
const HomePage({super.key});

@override
State<HomePage> createState() => _HomePageState();
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7

COCOAPODS: 1.15.2
COCOAPODS: 1.14.3

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -231,6 +223,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.11.0"
mostly_reasonable_lints:
dependency: "direct dev"
description:
name: mostly_reasonable_lints
sha256: c61cc6b211f54188eef15e0ad7c9b00e8c001478ac253a52036ef7391b532b7c
url: "https://pub.dev"
source: hosted
version: "0.1.1"
msix:
dependency: "direct dev"
description:
Expand All @@ -251,10 +251,10 @@ packages:
dependency: "direct main"
description:
name: package_info_plus
sha256: "2c582551839386fa7ddbc7770658be7c0f87f388a4bff72066478f597c34d17f"
sha256: b93d8b4d624b4ea19b0a5a208b2d6eff06004bc3ce74c06040b120eeadd00ce0
url: "https://pub.dev"
source: hosted
version: "7.0.0"
version: "8.0.0"
package_info_plus_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -400,10 +400,10 @@ packages:
dependency: transitive
description:
name: win32_registry
sha256: "41fd8a189940d8696b1b810efb9abcf60827b6cbfab90b0c43e8439e3a39d85a"
sha256: "10589e0d7f4e053f2c61023a31c9ce01146656a70b7b7f0828c0b46d7da2a9bb"
url: "https://pub.dev"
source: hosted
version: "1.1.2"
version: "1.1.3"
xml:
dependency: transitive
description:
Expand Down
11 changes: 6 additions & 5 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ description: Demonstrates how to use the launch_at_startup plugin.
publish_to: "none"

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=3.0.0 <4.0.0"

dependencies:
bot_toast: ^4.0.1
cupertino_icons: ^1.0.2
flutter:
sdk: flutter
launch_at_startup:
path: ../
cupertino_icons: ^1.0.2
bot_toast: ^4.0.1
package_info_plus: ^7.0.0
package_info_plus: ^8.0.0
preference_list: ^0.0.1

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^3.0.2
mostly_reasonable_lints: ^0.1.1
msix: ^3.16.7

flutter:
Expand All @@ -29,3 +29,4 @@ msix_config:
publisher_display_name: LeanFlutter
identity_name: dev.leanflutter.examples.launchatstartupexample
msix_version: 1.0.0.0

15 changes: 9 additions & 6 deletions lib/src/app_auto_launcher_impl_linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import 'package:launch_at_startup/src/app_auto_launcher.dart';

class AppAutoLauncherImplLinux extends AppAutoLauncher {
AppAutoLauncherImplLinux({
required String appName,
required String appPath,
List<String> args = const [],
}) : super(appName: appName, appPath: appPath, args: args);
required super.appName,
required super.appPath,
super.args,
});

File get _desktopFile => File(
'${Platform.environment['HOME']}/.config/autostart/$appName.desktop');
File get _desktopFile {
return File(
'${Platform.environment['HOME']}/.config/autostart/$appName.desktop',
);
}

@override
Future<bool> isEnabled() async {
Expand Down
15 changes: 9 additions & 6 deletions lib/src/app_auto_launcher_impl_macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import 'package:launch_at_startup/src/app_auto_launcher.dart';

class AppAutoLauncherImplMacOS extends AppAutoLauncher {
AppAutoLauncherImplMacOS({
required String appName,
required String appPath,
List<String> args = const [],
}) : super(appName: appName, appPath: appPath, args: args);
required super.appName,
required super.appPath,
super.args,
});

static const platform = MethodChannel('launch_at_startup');

Expand All @@ -18,7 +18,8 @@ class AppAutoLauncherImplMacOS extends AppAutoLauncher {
await platform.invokeMethod<bool>('launchAtStartupIsEnabled');
if (isEnabled == null) {
throw Exception(
'WARNING: AppAutoLauncherImplMacOS.isEnabled null response! platform.invokeMethod<bool>("launchAtStartupIsEnabled") returned a null response when checking if app is set to launch at startup.');
'WARNING: AppAutoLauncherImplMacOS.isEnabled null response! platform.invokeMethod<bool>("launchAtStartupIsEnabled") returned a null response when checking if app is set to launch at startup.',
);
} else {
return isEnabled;
}
Expand All @@ -37,7 +38,9 @@ class AppAutoLauncherImplMacOS extends AppAutoLauncher {
Future<bool> disable() async {
if (await isEnabled()) {
await platform.invokeMethod(
'launchAtStartupSetEnabled', {'setEnabledValue': false});
'launchAtStartupSetEnabled',
{'setEnabledValue': false},
);
}
return true;
}
Expand Down
24 changes: 13 additions & 11 deletions lib/src/app_auto_launcher_impl_windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ bool isRunningInMsix(String packageName) {

class AppAutoLauncherImplWindows extends AppAutoLauncher {
AppAutoLauncherImplWindows({
required String appName,
required super.appName,
required String appPath,
List<String> args = const [],
}) : super(appName: appName, appPath: appPath, args: args) {
}) : super(appPath: appPath, args: args) {
_registryValue = args.isEmpty ? appPath : '$appPath ${args.join(' ')}';
}

Expand Down Expand Up @@ -47,11 +47,13 @@ class AppAutoLauncherImplWindows extends AppAutoLauncher {

@override
Future<bool> enable() async {
_regKey.createValue(RegistryValue(
appName,
RegistryValueType.string,
_registryValue,
));
_regKey.createValue(
RegistryValue(
appName,
RegistryValueType.string,
_registryValue,
),
);

final bytes = Uint8List(_startupApprovedRegKeyBytesLength);
// "2" as a first byte in this register means that the autostart is enabled
Expand Down Expand Up @@ -98,11 +100,11 @@ class AppAutoLauncherImplWindows extends AppAutoLauncher {

class AppAutoLauncherImplWindowsMsix extends AppAutoLauncher {
AppAutoLauncherImplWindowsMsix({
required String appName,
required String appPath,
required super.appName,
required super.appPath,
required this.packageName,
List<String> args = const [],
}) : super(appName: appName, appPath: appPath, args: args);
super.args,
});

final String packageName;

Expand Down
Loading

0 comments on commit 633b832

Please sign in to comment.