Skip to content

Commit

Permalink
refactor!: make singletons explicit
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `BetrayalPlugin()` and `BetrayalLogConfig()` have been replaced with `.instance` respectively.
  • Loading branch information
benthillerkus committed Apr 17, 2022
1 parent 18fbd94 commit 772730e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/src/imperative.dart
Expand Up @@ -17,7 +17,7 @@ part of 'plugin.dart';
///
/// To nuke all existing icons, use [TrayIcon.clearAll]
class TrayIcon {
static final BetrayalPlugin _plugin = BetrayalPlugin();
static final BetrayalPlugin _plugin = BetrayalPlugin.instance;
static final Map<Id, TrayIcon> _allIcons = {};
static final Random _random = Random();

Expand Down
6 changes: 3 additions & 3 deletions lib/src/logging.dart
@@ -1,7 +1,7 @@
import 'dart:async';
import 'dart:developer';

import 'package:logging/logging.dart';
import 'dart:developer';

/// Manager for logging in the *betrayal* package.
///
Expand All @@ -11,7 +11,7 @@ import 'dart:developer';
/// to initialize everything.
class BetrayalLogConfig {
/// Retrieves the singleton instance.
factory BetrayalLogConfig() => _instance;
static BetrayalLogConfig get instance => _instance;

static final _instance = BetrayalLogConfig._internal();

Expand Down Expand Up @@ -90,7 +90,7 @@ class BetrayalLogConfig {
_logger.level = _level;

// Ensure that the following message is logged.
BetrayalLogConfig();
instance;

_logger.info("logging level changed to ${_level.name}");
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/plugin.dart
Expand Up @@ -43,7 +43,7 @@ class BetrayalPlugin {
static final BetrayalPlugin _instance = BetrayalPlugin._internal();

/// Retrieves the singleton instance.
factory BetrayalPlugin() => _instance;
static BetrayalPlugin get instance => _instance;

static const MethodChannel _channel = MethodChannel('betrayal');

Expand Down Expand Up @@ -97,7 +97,6 @@ class BetrayalPlugin {
/// Once it is invoked, it will try to clear up any icons registered
/// with the plugin.
BetrayalPlugin._internal() {
BetrayalLogConfig();
_logger.finer('initializing plugin...');
// This makes sure the plugin can be invoked
// before `runApp` is called in main
Expand Down

0 comments on commit 772730e

Please sign in to comment.