Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e39bef1
commit 439909a
Showing
11 changed files
with
273 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export 'src/imperative.dart'; | ||
export 'src/win_icon.dart'; | ||
export 'src/image.dart'; | ||
export 'src/plugin.dart'; | ||
export 'src/logging.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:logging/logging.dart'; | ||
import 'dart:developer'; | ||
|
||
/// Manager for logging in the *betrayal* package. | ||
/// | ||
/// All of the functions and fields are static. | ||
/// However, since static stuff is lazy in Dart, | ||
/// [BetrayalPlugin] creates a singleton instance | ||
/// to initialize everything. | ||
class BetrayalLogConfig { | ||
/// Retrieves the singleton instance. | ||
factory BetrayalLogConfig() => _instance; | ||
|
||
static final _instance = BetrayalLogConfig._internal(); | ||
|
||
static final Logger _logger = Logger("betrayal"); | ||
|
||
BetrayalLogConfig._internal() { | ||
onRecord = (LogRecord record) { | ||
log(record.message, | ||
level: record.level.value, | ||
name: record.loggerName, | ||
sequenceNumber: record.sequenceNumber, | ||
time: record.time, | ||
error: record.error, | ||
stackTrace: record.stackTrace, | ||
zone: record.zone); | ||
}; | ||
_logger.info("ready to log!"); | ||
} | ||
|
||
static Level _level = Logger.root.level; | ||
|
||
/// Allows individual loggers to have their own level. | ||
/// | ||
/// In this case, you could use it to make *betrayal* shut up, for example. | ||
/// ```dart | ||
/// BetrayalLogConfig.allowIndividualLevels(); | ||
/// BetrayalLogConfig().setLevel(Level.OFF); | ||
/// ``` | ||
/// | ||
/// This function is implemented as | ||
/// ``` | ||
/// static void allowIndividualLevels() => hierarchicalLoggingEnabled = true; | ||
/// ``` | ||
/// so unfortunately, it's changing a global variable from the `logging` package. | ||
static void allowIndividualLevels() => hierarchicalLoggingEnabled = true; | ||
|
||
/// Use this to change the logging level `betrayal` scope. | ||
/// | ||
/// This is only possible, if `hierarchicalLoggingEnabled == true`. | ||
/// | ||
/// If the global isn't in scope, | ||
/// you can call [BetrayalLogConfig.allowIndividualLevels] instead. | ||
/// | ||
/// Valid input types are [Level], [String] and [num]. | ||
/// | ||
/// | String | num | | ||
/// |-------|----| | ||
/// | `ALL` | 0 | | ||
/// | `FINEST` | 300 | | ||
/// | `FINER` | 400 | | ||
/// | `FINE` | 500 | | ||
/// | `CONFIG` | 700 | | ||
/// | `INFO` | 800 | | ||
/// | `WARNING` | 900 | | ||
/// | `SEVERE` | 1000 | | ||
/// | `SHOUT` | 1200 | | ||
/// | `OFF` | 2000 | | ||
static set level(dynamic level) { | ||
if (level is Level) { | ||
_level = level; | ||
} else if (level is String) { | ||
level = level.toUpperCase(); | ||
_level = Level.LEVELS.firstWhere( | ||
(element) => element.name == level, | ||
orElse: () => | ||
throw ArgumentError.value(level, "level", "not a valid Level!"), | ||
); | ||
} else if (level is num) { | ||
// This works assuming that the order will not be changed | ||
// from lowest value (ALL) to highest (OFF) in the future. | ||
_level = Level.LEVELS.lastWhere((element) => element.value <= level); | ||
} else { | ||
throw ArgumentError( | ||
"level must be a Level, String or num, not ${level.runtimeType}!"); | ||
} | ||
_logger.level = _level; | ||
_logger.info("logging level changed to ${_level.name}"); | ||
} | ||
|
||
/// The current logging level for the `betrayal` scope. | ||
static Level get level => _level; | ||
|
||
// ignore: prefer_function_declarations_over_variables | ||
static late void Function(LogRecord record) _onRecord; | ||
|
||
static StreamSubscription<LogRecord>? _subscription; | ||
|
||
/// Handles log records. | ||
/// | ||
/// Per default they will be send to `developer.log`, | ||
/// which is the default logging facility in Dart. | ||
static set onRecord(void Function(LogRecord record) onRecord) { | ||
_onRecord = onRecord; | ||
_subscription?.cancel(); | ||
_subscription = _logger.onRecord.listen(_onRecord); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import 'package:flutter/widgets.dart'; | ||
|
||
/// Represents constants in WinUser.h | ||
enum WinEvent { | ||
/// `0x200`, equivalent to `EVENT_SYSTEM_MOVESIZESTART` | ||
mouseMove, | ||
|
||
/// `0x201`, equivalent to `onTapDown` | ||
leftButtonDown, | ||
|
||
/// `0x202`, equivalent to `onTapUp` | ||
leftButtonUp, | ||
|
||
/// `0x203`, equivalent to `onDoubleTap` | ||
leftButtonDoubleClick, | ||
|
||
/// `0x204`, equivalent to `onSecondaryTapDown` | ||
rightButtonDown, | ||
|
||
/// `0x205`, equivalent to `onSecondaryTapUp` | ||
rightButtonUp, | ||
|
||
/// `0x206` | ||
rightButtonDoubleClick, | ||
|
||
/// `0x207`, equivalent to `onTertiaryTapDown` | ||
middleButtonDown, | ||
|
||
/// `0x207`, equivalent to `onTertiaryTapUp` | ||
middleButtonUp, | ||
|
||
/// `0x207` | ||
middleButtonDoubleClick, | ||
} | ||
|
||
/// Returns the [WinEvent] for the given [code]. | ||
@protected | ||
WinEvent fromCode(int code) { | ||
switch (code) { | ||
case 0x200: | ||
return WinEvent.mouseMove; | ||
case 0x201: | ||
return WinEvent.leftButtonDown; | ||
case 0x202: | ||
return WinEvent.leftButtonUp; | ||
case 0x203: | ||
return WinEvent.leftButtonDoubleClick; | ||
case 0x204: | ||
return WinEvent.rightButtonDown; | ||
case 0x205: | ||
return WinEvent.rightButtonUp; | ||
case 0x206: | ||
return WinEvent.rightButtonDoubleClick; | ||
case 0x207: | ||
return WinEvent.middleButtonDown; | ||
case 0x208: | ||
return WinEvent.middleButtonUp; | ||
case 0x209: | ||
return WinEvent.middleButtonDoubleClick; | ||
} | ||
throw ArgumentError.value(code, "code", "Unknown code"); | ||
} | ||
|
||
/// This extension allows adding members to the [WinEvent] enum. | ||
/// | ||
/// In Dart 2.17 and later, this will be possible doable | ||
/// without an extension. | ||
extension EventCodes on WinEvent { | ||
/// The internal constant used by Windows. | ||
int get code { | ||
switch (this) { | ||
case WinEvent.mouseMove: | ||
return 0x200; | ||
case WinEvent.leftButtonDown: | ||
return 0x201; | ||
case WinEvent.leftButtonUp: | ||
return 0x202; | ||
case WinEvent.leftButtonDoubleClick: | ||
return 0x203; | ||
case WinEvent.rightButtonDown: | ||
return 0x204; | ||
case WinEvent.rightButtonUp: | ||
return 0x205; | ||
case WinEvent.rightButtonDoubleClick: | ||
return 0x206; | ||
case WinEvent.middleButtonDown: | ||
return 0x207; | ||
case WinEvent.middleButtonUp: | ||
return 0x208; | ||
case WinEvent.middleButtonDoubleClick: | ||
return 0x209; | ||
} | ||
} | ||
} |
Oops, something went wrong.