Skip to content

Commit

Permalink
MacOS UI and Support Add
Browse files Browse the repository at this point in the history
  • Loading branch information
vednig committed Oct 31, 2024
1 parent 962d5e1 commit c2be437
Show file tree
Hide file tree
Showing 16 changed files with 385 additions and 81 deletions.
Binary file added Frontend/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion Frontend/searchlight_gui/.fvmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"flutter": "3.1.0",
"flutter": "3.7.0",
"flavors": {}
}
1 change: 1 addition & 0 deletions Frontend/searchlight_gui/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions Frontend/searchlight_gui/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
41 changes: 41 additions & 0 deletions Frontend/searchlight_gui/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
198 changes: 131 additions & 67 deletions Frontend/searchlight_gui/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,42 @@ import 'package:fluent_ui/fluent_ui.dart' as fluent_ui;
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_acrylic/flutter_acrylic.dart';
import 'package:hotkey_manager/hotkey_manager.dart';
// import 'package:hotkey_manager/hotkey_manager.dart';
import 'package:window_manager/window_manager.dart';
import 'package:path_provider/path_provider.dart';
import 'package:macos_ui/macos_ui.dart' as macos_ui;

// import 'package:flutter_window_close/flutter_window_close.dart' as fwc;

//import 'bg.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await hotKeyManager.unregisterAll();
HotKey _hotKey = HotKey(
KeyCode.keyZ,
modifiers: [KeyModifier.alt],

//-------- Set hotkey scope (default is HotKeyScope.system)--------
scope: HotKeyScope.inapp, //------- Set as inapp-wide hotkey-------
);
await hotKeyManager.register(
_hotKey,
keyDownHandler: (hotKey) {
//--------<>-------------
//Enable when in Production
//--------<>--------------
if (appWindow.isVisible) {
exit(0);
} else {
appWindow.show();
}
},
// await hotKeyManager.unregisterAll();
// HotKey _hotKey = HotKey(
// KeyCode.keyZ,
// modifiers: [KeyModifier.alt],

// //-------- Set hotkey scope (default is HotKeyScope.system)--------
// scope: HotKeyScope.inapp, //------- Set as inapp-wide hotkey-------
// );
// await hotKeyManager.register(
// _hotKey,
// keyDownHandler: (hotKey) {
// //--------<>-------------
// //Enable when in Production
// //--------<>--------------
// if (appWindow.isVisible) {
// exit(0);
// } else {
// appWindow.show();
// }
// },
//----- Only works on macOS --------
//keyUpHandler: (hotKey){
//print('onKeyUp+${hotKey.toJson()}');
//} ,
//----------------------------------
);
// );

await Window.initialize();
if (Platform.isWindows) {
Expand All @@ -64,16 +67,32 @@ void main() async {
await windowManager.setTitleBarStyle(TitleBarStyle.hidden);
await windowManager.setAsFrameless();
await windowManager.maximize();


// windowManager.waitUntilReadyToShow(windowOptions, () async {
// await windowManager.show();
// await windowManager.focus();
// });
// });
// windowManager.waitUntilReadyToShow().then((_) async{
// await windowManager.setAsFrameless();
// });

}
if(Platform.isMacOS){
print('Build Type: MacOS');
// final Directory tempDir = await getTemporaryDirectory();

// final Directory appDocumentsDir = await getApplicationDocumentsDirectory();

final Directory? downloadsDir = await getDownloadsDirectory();
var normalTempDir = Directory('./Downloads');

// List<String>? contents = downloadsDir?.listSync(recursive: false).map((e) => e.toString()).toList();
// if(contents!=null){
// contents.forEach((element) {
// print(element);
// });
// }
}
runApp(const MyApp());
// focus
Expand Down Expand Up @@ -104,9 +123,10 @@ class MyApp extends StatelessWidget {
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
accentColor: fluent_ui.Colors.blue,
// accentColor: fluent_ui.Colors.blue,
//works with ScaffoldPage
scaffoldBackgroundColor: fluent_ui.Colors.transparent),
// scaffoldBackgroundColor: fluent_ui.Colors.black
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
Expand All @@ -131,16 +151,33 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
var systemTempDir =
Directory((Platform.environment['HOME'] ?? Platform.environment['USERPROFILE']).toString() + '/Downloads');
Directory? systemTempDir = Directory('.');
// get contents =>
// systemTempDir.listSync(recursive: false).map((e) => e.toString()).toList();
final FocusNode _focusNode = FocusNode();
// Directory? downloadsDir;
// Directory((Platform.environment['HOME'] ?? Platform.environment['USERPROFILE']).toString() + '/Downloads');

Future<void> _fetchData() async {

Directory? downloadsDir = await getDownloadsDirectory();
systemTempDir = Directory('/Users/vednig/Downloads');
// List<String>? contents = downloadsDir?.listSync(recursive: true).map((e) => e.toString()).toList();
// if(contents!=null){
// contents.forEach((element) {
// print(element);
// });
// }
}

// List<String>? contents = downloadsDir?.listSync(recursive: false).map((e) => e.toString()).toList();
get contents => systemTempDir?.listSync(recursive: false).map((e) => macos_ui.SearchResultItem(e.toString())).toList();

get contents =>
systemTempDir.listSync(recursive: true).map((e) => e.toString()).toList();
final FocusNode _focusNode = FocusNode();

@override
void initState() {
super.initState();
_fetchData();
WidgetsBinding.instance.addPostFrameCallback(
(_) => FocusScope.of(context).requestFocus(_focusNode));

Expand All @@ -162,7 +199,7 @@ class _MyHomePageState extends State<MyHomePage> {

return Scaffold(
//------------- Base Layout Of App --------------
backgroundColor: fluent_ui.Colors.transparent,
backgroundColor:fluent_ui.Colors.black,

//<Previous Code >bottomNavigationBar: ,
body: fluent_ui.Column(
Expand All @@ -172,46 +209,73 @@ class _MyHomePageState extends State<MyHomePage> {
flex: 0,
child: fluent_ui.Center(
child: fluent_ui.Container(
decoration: BoxDecoration(
color: fluent_ui.Colors.black,
borderRadius: BorderRadius.circular(4.0),
),

//<For Coulmn/Row as super> mainAxisAlignment: fluent_ui.MainAxisAlignment.center,
child: fluent_ui.Center(
child: fluent_ui.FractionallySizedBox(
widthFactor: 0.30,

child:
//<For Coulmn/Row as super> mainAxisAlignment: fluent_ui.MainAxisAlignment.center,
child: fluent_ui.AutoSuggestBox(
leadingIcon: fluent_ui.Icon(
fluent_ui.FluentIcons.search),
macos_ui.MacosTheme(
// themeMode: ThemeMode.system, // or ThemeMode.light, ThemeMode.dark
data:macos_ui.MacosThemeData.light(),

child:macos_ui.MacosSearchField(

placeholder: 'Search',
items: contents,
onChanged: (text, reason) async {
var re = RegExp(
r"File: '(([A-Z]:)?[\.]?[\\{1,2}/]?.*[\\{1,2}/])*(.+)\.(.+)'");

if (re.hasMatch('$text')) {
String txt = text
.replaceFirst('File: ', '')
.replaceAll("'", "");
print(txt);
if (Platform.isLinux) {
appWindow.hide();
await Process.run("xdg-open", [
txt,
]);
exit(0);;

} else if (Platform.isWindows) {
appWindow.hide();
await Process.run(txt, [],
runInShell: true);
}
} else {
print('No Match');
}
},
onSelected: (breed) {
// print(breed);
results: contents,
// onChanged: (text, reason) async {
// print(reason);
// var re = RegExp(
// r"File: '(([A-Z]:)?[\.]?[\\{1,2}/]?.*[\\{1,2}/])*(.+)\.(.+)'");
// // appWindow.hide();
// print("Opening $text");
// await Process.run("open", [
// "$text",
// ]);
// if (re.hasMatch('$text')) {
// String txt = text
// .replaceFirst('File: ', '')
// .replaceAll("'", "");
// print(txt);
// if (Platform.isLinux) {
// appWindow.hide();
// await Process.run("xdg-open", [
// txt,
// ]);
// exit(0);;

// } else if (Platform.isWindows) {
// appWindow.hide();
// await Process.run(txt, [],
// runInShell: true);
// }

// } else {
// print('No Match');
// }


// },
// onSelected: (String selection) {
// debugPrint('$selection selected');
// },
onResultSelected: (resultItem) {
debugPrint(resultItem.searchKey);
},
)))))),


)

)
)

)
)
),
]),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import flutter_acrylic
import flutter_platform_alert
import flutter_window_close
import hotkey_manager
import macos_ui
import path_provider_foundation
import screen_retriever
import window_manager

Expand All @@ -19,6 +21,8 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterPlatformAlertPlugin.register(with: registry.registrar(forPlugin: "FlutterPlatformAlertPlugin"))
FlutterWindowClosePlugin.register(with: registry.registrar(forPlugin: "FlutterWindowClosePlugin"))
HotkeyManagerPlugin.register(with: registry.registrar(forPlugin: "HotkeyManagerPlugin"))
MacOSUiPlugin.register(with: registry.registrar(forPlugin: "MacOSUiPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
40 changes: 40 additions & 0 deletions Frontend/searchlight_gui/macos/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
platform :osx, '10.14'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_macos_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_macos_build_settings(target)
end
end
Loading

0 comments on commit c2be437

Please sign in to comment.