From 19878e119edf72d0650f249b0cb5b08e2fad7dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A3=B9=E9=9B=B6?= Date: Wed, 17 Apr 2024 08:05:09 +0800 Subject: [PATCH] add linux entry --- .github/workflows/build-linux.yml | 1 + lib/app/linux.dart | 126 ++++++++++++++++++++++++++++++ lib/main.dart | 5 ++ pubspec.yaml | 2 +- 4 files changed, 133 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 4cf770d..279b2ad 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -39,6 +39,7 @@ jobs: - name: install dependencies run: | sudo apt-get install clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev -y + chmod +x /home/runner/work/all_in_one/all_in_one/rust_builder/cargokit/run_build_tool.sh - name: Get dependencies run: flutter pub get diff --git a/lib/app/linux.dart b/lib/app/linux.dart index e69de29..980a41f 100644 --- a/lib/app/linux.dart +++ b/lib/app/linux.dart @@ -0,0 +1,126 @@ +import 'dart:io'; + +import 'package:all_in_one/app/common.dart'; +import 'package:all_in_one/routers/routers.dart'; +import 'package:all_in_one/schedule/cron_listener.dart'; +import 'package:all_in_one/software_monitor/notifier/monitor_item_notifier.dart'; +import 'package:all_in_one/common/logger.dart'; +import 'package:all_in_one/styles/app_style.dart'; +import 'package:flutter/material.dart'; +import 'package:icons_plus/icons_plus.dart'; +import 'package:window_manager/window_manager.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:all_in_one/src/rust/api/software_monitor_api.dart' as smapi; +import 'package:all_in_one/src/rust/api/sub_window_api.dart' as sw; +import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'; + +void runLinuxAPP() async { + WidgetsFlutterBinding.ensureInitialized(); + await windowManager.ensureInitialized(); + windowManager.setTitleBarStyle(TitleBarStyle.hidden); + windowManager.waitUntilReadyToShow(null, () async { + await windowManager.show(); + await windowManager.focus(); + await windowManager.setHasShadow(true); + }); + windowManager.setBackgroundColor(Colors.transparent); + + CronListener.start(); + + runApp(ProviderScope( + // observers: kDebugMode ? [SimpleObserver()] : [], + child: _Lauout( + child: MaterialApp( + scrollBehavior: AppScrollBehavior(), + theme: ThemeData( + colorSchemeSeed: AppStyle.appColor, + fontFamily: "NotoSns", + useMaterial3: true, + tabBarTheme: const TabBarTheme(dividerColor: Colors.transparent), + ), + debugShowCheckedModeBanner: false, + routes: Routers.routers, + navigatorKey: Routers.navigatorKey, + initialRoute: Routers.workboardScreen, + ), + ), + )); +} + +class _Lauout extends ConsumerStatefulWidget { + const _Lauout({required this.child}); + final Widget child; + + @override + ConsumerState<_Lauout> createState() => __LauoutState(); +} + +class __LauoutState extends ConsumerState<_Lauout> { + initStream() { + scheduleStream.listen((event) { + logger.info("events $event"); + sw.showTodos(data: []); + }); + + stream.listen((event) { + // print(event); + logger.info(event); + if (event is Int64List) { + ref + .read(monitorItemProvider.notifier) + .updateRunning(event.map((element) => element.toInt()).toList()); + } else { + ref.read(monitorItemProvider.notifier).updateRunning( + (event as (Int64List, String)) + .$1 + .map((element) => element.toInt()) + .toList(), + foreground: event.$2); + } + }); + } + + final scheduleStream = CronListener.controller.stream; + + final stream = Platform.isWindows + ? smapi.softwareWatchingWithForegroundMessageStream() + : smapi.softwareWatchingMessageStream(); + + @override + void initState() { + super.initState(); + initStream(); + } + + @override + Widget build(BuildContext context) { + return Directionality( + textDirection: TextDirection.ltr, + child: Scaffold( + backgroundColor: AppStyle.appColor, + appBar: PreferredSize( + preferredSize: const Size.fromHeight(30), + child: WindowCaption( + backgroundColor: AppStyle.appColor, + brightness: Brightness.dark, + title: Row( + children: [ + if (ref.watch(routersProvider) != Routers.workboardScreen) + InkWell( + onTap: () { + if (ref.watch(routersProvider) == Routers.entryScreen) { + ref.read(routersProvider.notifier).toMain(); + } else { + ref.read(routersProvider.notifier).toEntries(); + } + }, + child: const Icon(Bootstrap.arrow_left), + ) + ], + ), + ), + ), + body: widget.child, + )); + } +} diff --git a/lib/main.dart b/lib/main.dart index 434db27..4076cf5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:all_in_one/app/linux.dart'; import 'package:all_in_one/app/windows.dart'; import 'package:all_in_one/isar/database.dart'; import 'package:all_in_one/isar/software.dart'; @@ -52,4 +53,8 @@ Future main() async { if (Platform.isWindows) { runWindowsAPP(); } + + if (Platform.isLinux) { + runLinuxAPP(); + } } diff --git a/pubspec.yaml b/pubspec.yaml index 35ce655..04e4a5d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: all_in_one description: "A new Flutter project." publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 0.0.3+2 +version: 0.0.3+3 environment: sdk: '>=3.3.0 <4.0.0'