-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
feat: add appflowy-flutter://new deep link to create notes from clipper #8719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexrosepizant
wants to merge
2
commits into
AppFlowy-IO:main
Choose a base branch
from
alexrosepizant:feat/deeplink-new-note
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
frontend/appflowy_flutter/lib/startup/tasks/deeplink/new_note_deeplink_handler.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:appflowy/startup/startup.dart'; | ||
| import 'package:appflowy/startup/tasks/deeplink/deeplink_handler.dart'; | ||
| import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/note_creation_notifier.dart'; | ||
| import 'package:appflowy_backend/log.dart'; | ||
| import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart'; | ||
| import 'package:appflowy_result/appflowy_result.dart'; | ||
| import 'package:flutter/services.dart'; | ||
|
|
||
| /// Handles deep links of the form: | ||
| /// | ||
| /// ``` | ||
| /// appflowy-flutter://new | ||
| /// ?workspace_id=<uuid> (optional – switches workspace first) | ||
| /// &parent_view_id=<uuid> (optional – target space / folder) | ||
| /// &name=<title> (optional – defaults to "New Note") | ||
| /// &content=<url-encoded-markdown> (optional) | ||
| /// &clipboard (optional – read content from clipboard) | ||
| /// ``` | ||
| /// | ||
| /// Either `content` or `clipboard` can supply the initial Markdown body. | ||
| /// When both are present, `clipboard` takes precedence. | ||
| class NewNoteDeepLinkHandler extends DeepLinkHandler<void> { | ||
| /// [service] is injected for testability; defaults to the [getIt] singleton. | ||
| NewNoteDeepLinkHandler({CreateNoteService? service}) | ||
| : _service = service ?? getIt<CreateNoteService>(); | ||
|
|
||
| final CreateNoteService _service; | ||
|
|
||
| static const _host = 'new'; | ||
| static const _workspaceIdKey = 'workspace_id'; | ||
| static const _parentViewIdKey = 'parent_view_id'; | ||
| static const _nameKey = 'name'; | ||
| static const _contentKey = 'content'; | ||
| static const _clipboardKey = 'clipboard'; | ||
|
|
||
| @override | ||
| bool canHandle(Uri uri) => uri.host == _host; | ||
|
|
||
| @override | ||
| Future<FlowyResult<void, FlowyError>> handle({ | ||
| required Uri uri, | ||
| required DeepLinkStateHandler onStateChange, | ||
| }) async { | ||
| final name = uri.queryParameters[_nameKey]?.trim(); | ||
| final effectiveName = | ||
| (name == null || name.isEmpty) ? 'New Note' : name; | ||
|
|
||
| String? content; | ||
|
|
||
| // `clipboard` flag takes precedence over an explicit `content` value. | ||
| if (uri.queryParameters.containsKey(_clipboardKey)) { | ||
| final clipboardData = await Clipboard.getData(Clipboard.kTextPlain); | ||
| content = clipboardData?.text; | ||
| if (content == null || content.isEmpty) { | ||
| Log.warn('NewNoteDeepLink: clipboard was empty'); | ||
| } | ||
| } else { | ||
| content = uri.queryParameters[_contentKey]; | ||
| } | ||
|
|
||
| _service.request( | ||
| CreateNoteParams( | ||
| workspaceId: uri.queryParameters[_workspaceIdKey], | ||
| parentViewId: uri.queryParameters[_parentViewIdKey], | ||
| name: effectiveName, | ||
| content: content, | ||
| ), | ||
| ); | ||
|
|
||
| Log.info( | ||
| 'NewNoteDeepLink: queued note creation ' | ||
| '"$effectiveName" (workspace=${uri.queryParameters[_workspaceIdKey]}, ' | ||
| 'parent=${uri.queryParameters[_parentViewIdKey]})', | ||
| ); | ||
|
|
||
| return FlowyResult.success(null); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...lutter/lib/workspace/presentation/home/menu/sidebar/workspace/note_creation_notifier.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import 'package:flutter/foundation.dart'; | ||
|
|
||
| /// Parameters for a note-creation deep-link request. | ||
| class CreateNoteParams { | ||
| CreateNoteParams({ | ||
| this.workspaceId, | ||
| this.parentViewId, | ||
| required this.name, | ||
| this.content, | ||
| }); | ||
|
|
||
| /// Target workspace UUID. If null, the currently open workspace is used. | ||
| final String? workspaceId; | ||
|
|
||
| /// Parent view (space / folder) UUID. If null, falls back to the current | ||
| /// default space. | ||
| final String? parentViewId; | ||
|
|
||
| /// Title of the new document. | ||
| final String name; | ||
|
|
||
| /// Markdown content to pre-fill the document. May be null for an empty note. | ||
| final String? content; | ||
| } | ||
|
|
||
| /// Service registered in [getIt] that carries a pending note-creation request | ||
| /// from the deep-link layer to the sidebar layer. | ||
| /// | ||
| /// Using a [ChangeNotifier]-based singleton registered via [getIt] avoids | ||
| /// leaking a hidden global mutable across layers and makes the dependency | ||
| /// explicit and injectable for tests. | ||
| class CreateNoteService extends ChangeNotifier { | ||
| CreateNoteParams? _pending; | ||
|
|
||
| /// The pending note-creation request, or null when idle. | ||
| CreateNoteParams? get pending => _pending; | ||
|
|
||
| /// Enqueue a new note-creation request and notify listeners. | ||
| void request(CreateNoteParams params) { | ||
| _pending = params; | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| /// Mark the pending request as handled (consume it). | ||
| void consume() { | ||
| _pending = null; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.