Skip to content

Commit

Permalink
Merge pull request #7 from guchengxi1994/master
Browse files Browse the repository at this point in the history
add linux entry
  • Loading branch information
guchengxi1994 authored Apr 17, 2024
2 parents deb23fa + 19878e1 commit 2a92b72
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
126 changes: 126 additions & 0 deletions lib/app/linux.dart
Original file line number Diff line number Diff line change
@@ -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,
));
}
}
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -52,4 +53,8 @@ Future<void> main() async {
if (Platform.isWindows) {
runWindowsAPP();
}

if (Platform.isLinux) {
runLinuxAPP();
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 2a92b72

Please sign in to comment.