Skip to content

Commit f071c34

Browse files
committed
ml plugin support
1 parent e4a120f commit f071c34

File tree

2,965 files changed

+584803
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,965 files changed

+584803
-4
lines changed

β€Žlib/main.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:flutter/material.dart' hide MenuItem;
66
import 'package:flutter/services.dart';
77
import 'package:hotkey_manager/hotkey_manager.dart';
88
import 'package:system_tray/system_tray.dart';
9-
import 'package:window_manager/window_manager.dart'; // TODO: remove
9+
import 'package:window_manager/window_manager.dart'; // TODO: remove and use local window service
1010
import 'package:flutter_svg/flutter_svg.dart';
1111
import 'package:get_storage/get_storage.dart';
1212
import 'package:process_run/shell.dart';
@@ -22,6 +22,8 @@ double deviceScale = 1;
2222
double windowWidth = 1000;
2323
double windowHeight = 450;
2424

25+
PluginsServer pluginsServer = PluginsServer();
26+
2527
void main() async {
2628
WidgetsFlutterBinding.ensureInitialized();
2729

@@ -85,6 +87,7 @@ void main() async {
8587
await hotKeyManager.register(
8688
openHotKey,
8789
keyDownHandler: (hotKey) {
90+
pluginsServer.onOpenSpotter();
8891
windowService.show();
8992
print('onKeyDown+${hotKey.toJson()}');
9093
},
@@ -168,8 +171,6 @@ class _SpotterState extends State<Spotter> {
168171

169172
List<Option> activatedOptions = [];
170173

171-
PluginsServer pluginsServer = PluginsServer();
172-
173174
bool loading = false;
174175

175176
List<String> plugins = [
@@ -545,6 +546,11 @@ class _SpotterState extends State<Spotter> {
545546
initServer();
546547

547548
pluginsServer.start();
549+
550+
pluginsServer.mlSuggestionsRegistry.changes.listen((_) {
551+
List<String> mlSuggestions = pluginsServer.mlSuggestionsRegistry.toList();
552+
print("-------------------------------- object");
553+
});
548554
}
549555

550556
void onNextOptions(List<Option> options) {
@@ -634,6 +640,10 @@ class _SpotterState extends State<Spotter> {
634640
loading = true;
635641
});
636642

643+
final mlGlobalActionPath =
644+
[...activatedOptions, option].map((e) => e.name).join('#####');
645+
pluginsServer.mlSendGlobalActionPath(mlGlobalActionPath);
646+
637647
if (option.actionId != null) {
638648
PluginRequest? request = await pluginsServer.execAction(
639649
option.actionId as String,

β€Žlib/plugin_service.dart

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class PluginsServer {
118118
ObservableList<PluginRequest> requestsRegistry =
119119
ObservableList<PluginRequest>.from([]);
120120

121+
ObservableList<String> mlSuggestionsRegistry =
122+
ObservableList<String>.from([]);
123+
121124
start() async {
122125
HttpServer server = await HttpServer.bind('0.0.0.0', 4040);
123126
server.transform(WebSocketTransformer()).listen(_handleConnection);
@@ -154,7 +157,7 @@ class PluginsServer {
154157
return false;
155158
}
156159

157-
// TODO: return lingle item
160+
// TODO: return single item
158161
List<ReleaseAsset>? assets =
159162
await apiService.getLatestReleaseAssets(plugin);
160163

@@ -250,6 +253,29 @@ class PluginsServer {
250253
return request;
251254
}
252255

256+
mlAddSuggestionToList(String globalActionPath) {
257+
mlSuggestionsRegistry.add(globalActionPath);
258+
Iterable<String> nextMlSuggestionsRegistry = [
259+
...mlSuggestionsRegistry.take(2),
260+
globalActionPath
261+
];
262+
mlSuggestionsRegistry.clear();
263+
mlSuggestionsRegistry.addAll(nextMlSuggestionsRegistry);
264+
}
265+
266+
mlSendGlobalActionPath(String globalActionPath) async {
267+
for (var connection in pluginConnections) {
268+
connection.socket.add(
269+
'{"id": "", "type": "mlOnGlobalActionPath", "mlGlobalActionPath": "$globalActionPath"}');
270+
}
271+
}
272+
273+
onOpenSpotter() async {
274+
for (var connection in pluginConnections) {
275+
connection.socket.add('{"type": "onOpenSpotter"}');
276+
}
277+
}
278+
253279
_handleConnection(WebSocket socket) {
254280
String connectionId = DateTime.now().millisecondsSinceEpoch.toString();
255281
pluginConnections.add(PluginConnection(id: connectionId, socket: socket));
@@ -259,6 +285,12 @@ class PluginsServer {
259285

260286
socket.listen((event) {
261287
final json = jsonDecode(event);
288+
289+
if (json['mlGlobalActionPath'] != null) {
290+
mlAddSuggestionToList(json['mlGlobalActionPath']);
291+
return;
292+
}
293+
262294
json['connectionId'] = connectionId;
263295
PluginRequest request = PluginRequest.fromJson(json);
264296
// TODO: clean up after closing

β€Žlib/window_service.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import 'dart:async';
2+
import 'dart:io';
23

34
import 'package:flutter/services.dart';
5+
import 'package:window_manager/window_manager.dart';
46

57
class WindowService {
68
static const platform = MethodChannel('org.spotter-app');
79

810
Future<void> show() async {
911
try {
12+
if (Platform.isLinux) {
13+
await windowManager.show();
14+
// await windowManager.focus();
15+
return;
16+
}
1017
await platform.invokeMethod('showWindow');
1118
} catch (e) {
1219
return;
@@ -15,6 +22,10 @@ class WindowService {
1522

1623
Future<void> hide() async {
1724
try {
25+
if (Platform.isLinux) {
26+
await windowManager.hide();
27+
return;
28+
}
1829
await platform.invokeMethod('hideWindow');
1930
} catch (e) {
2031
return;

β€Žlinux/flutter/generated_plugin_registrant.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "generated_plugin_registrant.h"
88

99
#include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
10+
#include <dotup_flutter_active_window/dotup_flutter_active_window_plugin.h>
1011
#include <hotkey_manager/hotkey_manager_plugin.h>
1112
#include <screen_retriever/screen_retriever_plugin.h>
1213
#include <system_tray/system_tray_plugin.h>
@@ -16,6 +17,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
1617
g_autoptr(FlPluginRegistrar) bitsdojo_window_linux_registrar =
1718
fl_plugin_registry_get_registrar_for_plugin(registry, "BitsdojoWindowPlugin");
1819
bitsdojo_window_plugin_register_with_registrar(bitsdojo_window_linux_registrar);
20+
g_autoptr(FlPluginRegistrar) dotup_flutter_active_window_registrar =
21+
fl_plugin_registry_get_registrar_for_plugin(registry, "DotupFlutterActiveWindowPlugin");
22+
dotup_flutter_active_window_plugin_register_with_registrar(dotup_flutter_active_window_registrar);
1923
g_autoptr(FlPluginRegistrar) hotkey_manager_registrar =
2024
fl_plugin_registry_get_registrar_for_plugin(registry, "HotkeyManagerPlugin");
2125
hotkey_manager_plugin_register_with_registrar(hotkey_manager_registrar);

β€Žlinux/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
list(APPEND FLUTTER_PLUGIN_LIST
66
bitsdojo_window_linux
7+
dotup_flutter_active_window
78
hotkey_manager
89
screen_retriever
910
system_tray

β€Žmacos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import FlutterMacOS
66
import Foundation
77

88
import bitsdojo_window_macos
9+
import dotup_flutter_active_window
910
import hotkey_manager
1011
import package_info_plus
1112
import path_provider_macos
@@ -15,6 +16,7 @@ import window_manager
1516

1617
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
1718
BitsdojoWindowPlugin.register(with: registry.registrar(forPlugin: "BitsdojoWindowPlugin"))
19+
DotupFlutterActiveWindowPlugin.register(with: registry.registrar(forPlugin: "DotupFlutterActiveWindowPlugin"))
1820
HotkeyManagerPlugin.register(with: registry.registrar(forPlugin: "HotkeyManagerPlugin"))
1921
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
2022
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))

β€Žnode_modules/.bin/acorn

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žnode_modules/.bin/color-support

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žnode_modules/.bin/mkdirp

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žnode_modules/.bin/node-gyp

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žnode_modules/.bin/node-which

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žnode_modules/.bin/nopt

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žnode_modules/.bin/prebuild-install

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žnode_modules/.bin/rc

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žnode_modules/.bin/rimraf

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žnode_modules/.bin/semver

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)