Skip to content

Commit

Permalink
🧧Interface: 💨 Run Window Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Far-Se authored and Far-Se committed Jul 29, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 16de436 commit 62d4fbc
Showing 42 changed files with 1,219 additions and 262 deletions.
21 changes: 16 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
// ignore_for_file: unnecessary_import, prefer_const_constructors

import 'dart:async';
import 'dart:io';

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:tabamewin32/tabamewin32.dart';
import 'package:window_manager/window_manager.dart';

import 'models/globals.dart';
import 'models/utils.dart';
import 'models/settings.dart';
import 'models/win32/win32.dart';
import 'pages/interface.dart';
import 'pages/quickmenu.dart';

Future<void> main(List<String> arguments) async {
if (arguments.length == 1 && arguments[0].contains('-wizardly')) {
arguments = <String>['"${arguments[0].replaceAll(' -wizardly', '')}\\', '-wizardly'];
List<String> auxArgs = <String>[...arguments];
if (auxArgs.length == 1 && auxArgs[0].contains('-wizardly')) {
auxArgs = <String>['"${auxArgs[0].replaceAll(' -wizardly', '')}\\', '-wizardly'];
}
globalSettings.args = arguments;

// auxArgs.add("-strudel");
globalSettings.args = <String>[...auxArgs];
// WinUtils.msgBox(globalSettings.args.join(' '), "");
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();

@@ -52,7 +59,11 @@ Future<void> main(List<String> arguments) async {
});

await setWindowAsTransparent();

if (globalSettings.runAsAdministrator && !WinUtils.isAdministrator() && globalSettings.args.join(' ').contains('-strudel')) {
globalSettings.args.remove('-strudel');
WinUtils.run(Platform.resolvedExecutable, arguments: globalSettings.args.join(' '));
Timer(const Duration(seconds: 5), () => exit(0));
}
runApp(const Tabame());
}

46 changes: 44 additions & 2 deletions lib/models/classes/boxes.dart
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import 'package:flutter/foundation.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tabamewin32/tabamewin32.dart';
import '../../main.dart';
import '../utils.dart';
import '../settings.dart';
import 'saved_maps.dart';
import 'package:http/http.dart' as http;

@@ -68,9 +68,9 @@ class Boxes {
globalSettings
..hideTaskbarOnStartup = pref.getBool("hideTaskbarOnStartup") ?? false
..taskBarAppsStyle = TaskBarAppsStyle.values[pref.getInt("taskBarAppsStyle") ?? 0]
..themeType = ThemeType.values[pref.getInt("themeType") ?? 0]
..themeScheduleMin = pref.getInt("themeScheduleMin") ?? 0
..themeScheduleMax = pref.getInt("themeScheduleMax") ?? 0
..themeType = ThemeType.values[pref.getInt("themeType") ?? 0] // * always after schedule
..language = pref.getString("language") ?? Platform.localeName.substring(0, 2)
..customLogo = pref.getString("customLogo") ?? ""
..customSpash = pref.getString("customSpash") ?? ""
@@ -86,6 +86,7 @@ class Boxes {
..usePowerShellAsToastNotification = pref.getBool("usePowerShellAsToastNotification") ?? false
..showSystemUsage = pref.getBool("showSystemUsage") ?? false;

// ? Theme
final String? lightTheme = pref.getString("lightTheme");
final String? darkTheme = pref.getString("darkTheme");
if (lightTheme == null || darkTheme == null) {
@@ -162,6 +163,47 @@ class Boxes {
return rewritesMap;
}

List<List<String>> _runShortcuts = <List<String>>[];
set runShortcuts(List<List<String>> items) {
_runShortcuts = items;
updateSettings("runShortcuts", jsonEncode(items));
}

List<List<String>> get runShortcuts {
if (_runShortcuts.isNotEmpty) return _runShortcuts;
final String prefString = pref.getString("runShortcuts") ?? "";
if (prefString.isEmpty) return _runShortcuts;
final List<dynamic> runShortcuts = jsonDecode(pref.getString("runShortcuts")!);
_runShortcuts.clear();
for (List<dynamic> x in runShortcuts) {
_runShortcuts.add(<String>[x[0], x[1]]);
}
return _runShortcuts;
}

List<List<String>> _runKeys = <List<String>>[];
set runKeys(List<List<String>> items) {
_runKeys = items;
updateSettings("runKeys", jsonEncode(items));
}

List<List<String>> get runKeys {
if (_runKeys.isNotEmpty) return _runKeys;
final String prefString = pref.getString("runKeys") ?? "";
if (prefString.isEmpty) {
return <List<String>>[
<String>["m", "{MEDIA_NEXT_TRACK}"],
<String>["p", "{MEDIA_PREVIOUS_TRACK}"]
];
}
final List<dynamic> runKeys = jsonDecode(pref.getString("runKeys")!);
_runKeys.clear();
for (List<dynamic> x in runKeys) {
_runKeys.add(<String>[x[0], x[1]]);
}
return _runKeys;
}

List<String> get topBarWidgets {
List<String> defaultWidgets = <String>[
"TaskManagerButton",
2 changes: 1 addition & 1 deletion lib/models/classes/saved_maps.dart
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import 'dart:convert';

import 'package:flutter/foundation.dart';

import '../utils.dart';
import '../settings.dart';

abstract class SavedMap {
const SavedMap();
195 changes: 135 additions & 60 deletions lib/models/utils.dart → lib/models/settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
// vscode-fold=2
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math';

@@ -16,63 +17,6 @@ import 'classes/saved_maps.dart';
import 'win32/mixed.dart';
import 'win32/win32.dart';

typedef Maa = MainAxisAlignment;
typedef Caa = CrossAxisAlignment;

extension IntegerExtension on int {
String formatTime() {
final int hour = (this ~/ 60);
final int minute = (this % 60);
return "${hour.toString().numberFormat()}:${minute.toString().numberFormat()}";
}

bool isBetween(num from, num to) {
return from < this && this < to;
}

bool isBetweenEqual(num from, num to) {
return from <= this && this <= to;
}
}

extension StringExtension on String {
String truncate(int max, {String suffix = ''}) => length < max ? this : replaceRange(max, null, suffix);
String toUpperCaseFirst() {
if (length < 2) return toUpperCase();
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
}

String toUperCaseAll() => toUpperCase();
String toUpperCaseEach() => split(" ").map((String str) => str.toUpperCaseFirst()).join(" ");
String numberFormat({int minNr = 10}) {
return (int.parse(this) / minNr).toDouble().toString().replaceAll('.', '');
}
}

int darkerColor(int color, {int darkenBy = 0x10, int floor = 0x0}) {
final int darkerHex = (max((color >> 16) - darkenBy, floor) << 16) + (max(((color & 0xff00) >> 8) - darkenBy, floor) << 8) + max(((color & 0xff) - darkenBy), floor);
return darkerHex;
}

class AdjustableScrollController extends ScrollController {
AdjustableScrollController([int extraScrollSpeed = 40]) {
super.addListener(() {
ScrollDirection scrollDirection = super.position.userScrollDirection;
if (scrollDirection != ScrollDirection.idle) {
double scrollEnd = super.offset + (scrollDirection == ScrollDirection.reverse ? extraScrollSpeed : -extraScrollSpeed);
scrollEnd = min(super.position.maxScrollExtent, max(super.position.minScrollExtent, scrollEnd));
jumpTo(scrollEnd);
}
});
}
}

enum TaskBarAppsStyle { onlyActiveMonitor, activeMonitorFirst, orderByActivity }

enum VolumeOSDStyle { normal, media, visible, thin }

enum ThemeType { system, light, dark, schedule }

class Settings {
List<String> args = <String>[];

@@ -94,7 +38,9 @@ class Settings {
VolumeOSDStyle volumeOSDStyle = VolumeOSDStyle.normal;
TaskBarAppsStyle taskBarAppsStyle = TaskBarAppsStyle.activeMonitorFirst;

List<String> weather = <String>['10 C', "berlin, Germany", "m", "%c+%t"]; //u for US
List<String> weather = <String>['10 C', "berlin, Germany", "m", "%c+%t"];

RunCommands run = RunCommands(); //u for US
set weatherTemperature(String temp) => weather[0] = temp;
String get weatherTemperature => weather[0];
set weatherCity(String temp) => weather[1] = temp;
@@ -107,7 +53,13 @@ class Settings {
int themeScheduleMin = 8 * 60;
int themeScheduleMax = 20 * 60;
ThemeColors get theme => themeColors;
ThemeType themeType = ThemeType.system;
ThemeType _themeType = ThemeType.system;
ThemeType get themeType => _themeType;
set themeType(ThemeType t) {
_themeType = t;
setScheduleThemeChange();
}

ThemeColors lightTheme = ThemeColors(background: 0xffD5E0FB, textColor: 0xff3A404A, accentColor: 0xff446EE9, gradientAlpha: 200, quickMenuBoldFont: true);
ThemeColors darkTheme = ThemeColors(background: 0xFF3B414D, accentColor: 0xDCFFDCAA, gradientAlpha: 240, textColor: 0xFFFAF9F8, quickMenuBoldFont: true);
ThemeColors get themeColors => themeTypeMode == ThemeType.dark ? darkTheme : lightTheme;
@@ -127,6 +79,73 @@ class Settings {
}

String get logo => themeTypeMode == ThemeType.dark ? "resources/logo_light.png" : "resources/logo_dark.png";
Timer? themeScheduleChangeTimer;
void setScheduleThemeChange() {
themeScheduleChangeTimer?.cancel();
if (themeType != ThemeType.schedule) return;
final int now = (DateTime.now().hour * 60) + DateTime.now().minute;
if (now.isBetween(themeScheduleMin, themeScheduleMax)) {
themeScheduleChangeTimer = Timer(Duration(minutes: themeScheduleMax - now), () {});
} else {
themeScheduleChangeTimer = Timer(Duration(minutes: 24 - now + themeScheduleMin), () {});
}
}
}

class RunCommands {
String calculator = r"c ;^[0-9]+ ?[+\-*\\%]";
String color = r"col ;^(#|0x|rgb)";
String currency = r"cur ;\$;\d+ \w{3,4} to \w{3,4}";
String shortcut = r"s ;";
String regex = r"rgx ;^/";
String lorem = r"lorem ;->";
String encoders = r"enc ;^([\!|\@]|\[[$@])";
String setvar = r"v ;^\$";
String json = r"json";
String timer = r"t ;~";
String keys = r"k ;`";
String timezones = r"t";

List<String> get list => <String>[calculator, color, currency, shortcut, regex, lorem, encoders, setvar, json, timezones];
Future<void> save() async {
await Boxes.updateSettings("runCommands", jsonEncode(toMap()));
return;
}

Future<void> fetch() async {
final Map<String, String> output = jsonDecode(Boxes.pref.getString("runCommands2") ?? "[]");
if (output.isEmpty) return;
calculator = output["calculator"] ?? r"c ;^[0-9]+ ?[+\-*\\%]";
color = output["color"] ?? r"col ;^(#|0x|rgb)";
currency = output["currency"] ?? r"cur ;\$;\d+ \w{3,4} to \w{3,4}";
shortcut = output["shortcut"] ?? r"s ;";
regex = output["regex"] ?? r"rgx ;^/";
lorem = output["lorem"] ?? r"lorem ;->";
encoders = output["encoders"] ?? r"enc ;^([\!|\@]|\[[$@])";
setvar = output["setvar"] ?? r"v ;^\$";
json = output["json"] ?? r"json";
timer = output["timer"] ?? r"t ;~";
keys = output["keys"] ?? r"k ;`";
timezones = output["timezones"] ?? r"t";
}
// String

Map<String, dynamic> toMap() {
return <String, dynamic>{
"calculator": calculator,
"color": color,
"currency": currency,
"shortcut": shortcut,
"regex": regex,
"lorem": lorem,
"encoders": encoders,
"setvar": setvar,
"json": json,
"timer": timer,
"keys": keys,
"timezones": timezones,
};
}
}

Settings globalSettings = Settings();
@@ -141,6 +160,9 @@ Future<void> registerAll() async {
Timer.periodic(const Duration(seconds: 10), (Timer timer) => Monitor.fetchMonitor());
//register
await Boxes.registerBoxes();
//Schedule Theme
globalSettings.setScheduleThemeChange();
//Toast
Future<void>.delayed(const Duration(seconds: 2), () async {
if (!WinUtils.windowsNotificationRegistered) {
await localNotifier.setup(appName: 'Tabame', shortcutPolicy: ShortcutPolicy.requireCreate);
@@ -149,6 +171,59 @@ Future<void> registerAll() async {
});
}

typedef Maa = MainAxisAlignment;
typedef Caa = CrossAxisAlignment;

extension IntegerExtension on int {
String formatTime() {
final int hour = (this ~/ 60);
final int minute = (this % 60);
return "${hour.toString().numberFormat()}:${minute.toString().numberFormat()}";
}

bool isBetween(num from, num to) {
return from < this && this < to;
}

bool isBetweenEqual(num from, num to) {
return from <= this && this <= to;
}
}

extension StringExtension on String {
String truncate(int max, {String suffix = ''}) => length < max ? this : replaceRange(max, null, suffix);
String toUpperCaseFirst() {
if (length < 2) return toUpperCase();
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
}

// vscode-fold=dart
String toUperCaseAll() => toUpperCase();
String toUpperCaseEach() => split(" ").map((String str) => str.toUpperCaseFirst()).join(" ");
String numberFormat({int minNr = 10}) {
return (int.parse(this) / minNr).toDouble().toString().replaceAll('.', '');
}
}

int darkerColor(int color, {int darkenBy = 0x10, int floor = 0x0}) {
final int darkerHex = (max((color >> 16) - darkenBy, floor) << 16) + (max(((color & 0xff00) >> 8) - darkenBy, floor) << 8) + max(((color & 0xff) - darkenBy), floor);
return darkerHex;
}

class AdjustableScrollController extends ScrollController {
AdjustableScrollController([int extraScrollSpeed = 40]) {
super.addListener(() {
ScrollDirection scrollDirection = super.position.userScrollDirection;
if (scrollDirection != ScrollDirection.idle) {
double scrollEnd = super.offset + (scrollDirection == ScrollDirection.reverse ? extraScrollSpeed : -extraScrollSpeed);
scrollEnd = min(super.position.maxScrollExtent, max(super.position.minScrollExtent, scrollEnd));
jumpTo(scrollEnd);
}
});
}
}

enum TaskBarAppsStyle { onlyActiveMonitor, activeMonitorFirst, orderByActivity }

enum VolumeOSDStyle { normal, media, visible, thin }

enum ThemeType { system, light, dark, schedule }
6 changes: 5 additions & 1 deletion lib/models/win32/win32.dart
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ import 'package:tabamewin32/tabamewin32.dart';

import '../globals.dart';
import '../keys.dart';
import '../utils.dart';
import '../settings.dart';
import 'imports.dart';
import 'mixed.dart';
import 'registry.dart';
@@ -791,6 +791,10 @@ class WinUtils {
free(ppsi);
free(ppfi);
}

static msgBox(String text, String title) {
MessageBox(0, TEXT(text), TEXT(title), 0);
}
}

class WizardlyContextMenu {
Loading
Oops, something went wrong.

0 comments on commit 62d4fbc

Please sign in to comment.