Skip to content

Commit

Permalink
feat: add url scheme support, fix interaction bugs in cmd palette
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatNerdSquared committed Jan 3, 2025
1 parent 814fee7 commit 4a97c0c
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 2 deletions.
11 changes: 11 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,16 @@
<true/>
<key>UIFileSharingEnabled</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>peregrine_url</string>
<key>CFBundleURLSchemes</key>
<array>
<string>peregrine</string>
</array>
</dict>
</array>
</dict>
</plist>
5 changes: 5 additions & 0 deletions lib/context_menus.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:super_context_menu/super_context_menu.dart' as scm;

import 'export_utils.dart';
Expand Down Expand Up @@ -69,6 +70,10 @@ scm.Menu buildEntryCardContextMenu({
title: 'Add as ancestor',
callback: () => addAncestorCallback(entryId),
),
scm.MenuAction(
title: 'Copy Entry URL',
callback: () => Clipboard.setData(ClipboardData(text: 'peregrine://peregrine/entry/$entryId')),
),
scm.MenuAction(
title: isEncrypted ? 'Decrypt Entry' : 'Encrypt Entry',
callback: () => !isEncrypted ? toggleEncryptCallback() : null,
Expand Down
21 changes: 20 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:app_links/app_links.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:path_provider/path_provider.dart';
Expand Down Expand Up @@ -76,10 +77,13 @@ final currentAncestorsProvider =
StateNotifierProvider<CurrentAncestors, List<String>>(
(_) => CurrentAncestors(),
);
final currentJumpIdProvider = StateProvider<String>((ref) => '');

FocusNode entryBoxFocusNode = FocusNode();
FocusNode searchBoxFocusNode = FocusNode();

final appLinks = AppLinks();

void main() async {
WidgetsFlutterBinding.ensureInitialized();
platformAppSupportDir = (await getApplicationDocumentsDirectory()).path;
Expand Down Expand Up @@ -107,8 +111,23 @@ class MyApp extends ConsumerWidget {
class PeregrineHomeView extends ConsumerWidget {
const PeregrineHomeView({super.key});

void _handleUrl(uri, ref) {
final uriParts = uri.pathSegments;
if (uriParts[0] != 'entry') return;

final entries = ref.read(filteredListProvider).keys.toList();
final entryIndex = entries.indexOf(uriParts[1]);
if (entryIndex == -1) {
ref.read(entryFilterProvider.notifier).setAllEntriesFilter();
}
ref
.read(currentJumpIdProvider.notifier)
.update((String state) => (uriParts[1]).toString());
}

@override
Widget build(BuildContext context, WidgetRef ref) {
appLinks.uriLinkStream.listen((uri) => _handleUrl(uri, ref));
final view = PretMainView(
leftSidebar: Sidebar(
searchBoxFocusNode: searchBoxFocusNode,
Expand All @@ -127,7 +146,7 @@ class PeregrineHomeView extends ConsumerWidget {
return Scaffold(
backgroundColor: const Color(0xffb69d7c),
body: PretCmdPaletteScope(
searchItems: ref.read(tagsProvider).keys.toList(),
searchItems: ref.watch(tagsProvider).keys.toList(),
child: DesktopFrame(
entryBoxFocusNode: entryBoxFocusNode,
searchBoxFocusNode: searchBoxFocusNode,
Expand Down
14 changes: 14 additions & 0 deletions lib/widgets/entry_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class EntryListView extends ConsumerStatefulWidget {

class EntryListViewState extends ConsumerState<EntryListView> {
final _scrollController = ScrollController();
final _listController = ListController();

void scrollToBottom() => _scrollController.jumpTo(
_scrollController.position.maxScrollExtent,
Expand All @@ -35,6 +36,18 @@ class EntryListViewState extends ConsumerState<EntryListView> {
@override
Widget build(BuildContext context) {
var entries = ref.watch(filteredListProvider).keys.toList();
final currentJumpId = ref.watch(currentJumpIdProvider);

Future(() {
if (currentJumpId != '') {
ref.read(currentJumpIdProvider.notifier).update((state) => '');
_listController.jumpToItem(
index: entries.indexOf(currentJumpId),
scrollController: _scrollController,
alignment: 0.5);
}
});

final listView = buildEntryList(entries);
return Scaffold(
floatingActionButton: Container(
Expand Down Expand Up @@ -111,6 +124,7 @@ class EntryListViewState extends ConsumerState<EntryListView> {
padding: EdgeInsets.all(PretConfig.defaultElementSpacing * 1.5),
),
SuperSliverList.builder(
listController: _listController,
itemCount: entries.length,
itemBuilder: (context, index) =>
PeregrineEntryCard(entryId: entries[index]))
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/pret_command_palette.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class PretCmdPaletteScopeState extends ConsumerState<PretCmdPaletteScope> {

void togglePalette() => setState(() {
_isPaletteShown = !_isPaletteShown;
_controller.clear();
filteredItems = widget.searchItems;
selectedIndex = 0;
_isPaletteShown ? paletteFocusNode.requestFocus() : null;
});
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "generated_plugin_registrant.h"

#include <contextual_menu/contextual_menu_plugin.h>
#include <gtk/gtk_plugin.h>
#include <irondash_engine_context/irondash_engine_context_plugin.h>
#include <super_native_extensions/super_native_extensions_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
Expand All @@ -15,6 +16,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) contextual_menu_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ContextualMenuPlugin");
contextual_menu_plugin_register_with_registrar(contextual_menu_registrar);
g_autoptr(FlPluginRegistrar) gtk_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "GtkPlugin");
gtk_plugin_register_with_registrar(gtk_registrar);
g_autoptr(FlPluginRegistrar) irondash_engine_context_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "IrondashEngineContextPlugin");
irondash_engine_context_plugin_register_with_registrar(irondash_engine_context_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
contextual_menu
gtk
irondash_engine_context
super_native_extensions
url_launcher_linux
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import FlutterMacOS
import Foundation

import app_links
import contextual_menu
import device_info_plus
import irondash_engine_context
Expand All @@ -13,6 +14,7 @@ import super_native_extensions
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
ContextualMenuPlugin.register(with: registry.registrar(forPlugin: "ContextualMenuPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
IrondashEngineContextPlugin.register(with: registry.registrar(forPlugin: "IrondashEngineContextPlugin"))
Expand Down
8 changes: 7 additions & 1 deletion macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PODS:
- app_links (1.0.0):
- FlutterMacOS
- contextual_menu (0.0.1):
- FlutterMacOS
- device_info_plus (0.0.1):
Expand All @@ -15,6 +17,7 @@ PODS:
- FlutterMacOS

DEPENDENCIES:
- app_links (from `Flutter/ephemeral/.symlinks/plugins/app_links/macos`)
- contextual_menu (from `Flutter/ephemeral/.symlinks/plugins/contextual_menu/macos`)
- device_info_plus (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
Expand All @@ -24,6 +27,8 @@ DEPENDENCIES:
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)

EXTERNAL SOURCES:
app_links:
:path: Flutter/ephemeral/.symlinks/plugins/app_links/macos
contextual_menu:
:path: Flutter/ephemeral/.symlinks/plugins/contextual_menu/macos
device_info_plus:
Expand All @@ -40,6 +45,7 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos

SPEC CHECKSUMS:
app_links: 10e0a0ab602ffaf34d142cd4862f29d34b303b2a
contextual_menu: 6d35fb15942c0d8769f5eae8d3bda653994a6f5a
device_info_plus: ce1b7762849d3ec103d0e0517299f2db7ad60720
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
Expand All @@ -50,4 +56,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
11 changes: 11 additions & 0 deletions macos/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,16 @@
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>peregrine_url</string>
<key>CFBundleURLSchemes</key>
<array>
<string>peregrine</string>
</array>
</dict>
</array>
</dict>
</plist>
40 changes: 40 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.11.3"
app_links:
dependency: "direct main"
description:
name: app_links
sha256: "433df2e61b10519407475d7f69e470789d23d593f28224c38ba1068597be7950"
url: "https://pub.dev"
source: hosted
version: "6.3.3"
app_links_linux:
dependency: transitive
description:
name: app_links_linux
sha256: f5f7173a78609f3dfd4c2ff2c95bd559ab43c80a87dc6a095921d96c05688c81
url: "https://pub.dev"
source: hosted
version: "1.0.3"
app_links_platform_interface:
dependency: transitive
description:
name: app_links_platform_interface
sha256: "05f5379577c513b534a29ddea68176a4d4802c46180ee8e2e966257158772a3f"
url: "https://pub.dev"
source: hosted
version: "2.0.2"
app_links_web:
dependency: transitive
description:
name: app_links_web
sha256: af060ed76183f9e2b87510a9480e56a5352b6c249778d07bd2c95fc35632a555
url: "https://pub.dev"
source: hosted
version: "1.0.4"
archive:
dependency: transitive
description:
Expand Down Expand Up @@ -317,6 +349,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.2"
gtk:
dependency: transitive
description:
name: gtk
sha256: e8ce9ca4b1df106e4d72dad201d345ea1a036cc12c360f1a7d5a758f78ffa42c
url: "https://pub.dev"
source: hosted
version: "2.1.0"
highlight:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies:
file_picker: ^5.5.0
super_sliver_list: ^0.4.1
super_context_menu: ^0.8.15
app_links: ^6.3.3

dev_dependencies:
flutter_test:
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

#include "generated_plugin_registrant.h"

#include <app_links/app_links_plugin_c_api.h>
#include <contextual_menu/contextual_menu_plugin.h>
#include <irondash_engine_context/irondash_engine_context_plugin_c_api.h>
#include <super_native_extensions/super_native_extensions_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
AppLinksPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AppLinksPluginCApi"));
ContextualMenuPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ContextualMenuPlugin"));
IrondashEngineContextPluginCApiRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
app_links
contextual_menu
irondash_engine_context
super_native_extensions
Expand Down

0 comments on commit 4a97c0c

Please sign in to comment.