Skip to content

Commit fdeb999

Browse files
committed
feat: Now allowing otpauth links to be opened by the app on all platforms.
1 parent 738b64c commit fdeb999

File tree

6 files changed

+114
-24
lines changed

6 files changed

+114
-24
lines changed

bin/version.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ ${fileContent.substring(changeLogHeader.length + 2)}''';
104104
pubspecFile.writeAsStringSync(editor.toString());
105105
await Process.run('dart', ['pub', 'get']);
106106
stdout.writeln('Done.');
107+
stdout.writeln('Writing version to "snapcraft.yaml"...');
108+
File snapcraftFile = File('./snapcraft.yaml');
109+
editor = YamlEditor(snapcraftFile.readAsStringSync());
110+
editor.update(['version'], newVersion.buildName());
111+
snapcraftFile.writeAsStringSync(editor.toString());
112+
stdout.writeln('Done.');
107113
bool commit = askYNQuestion('Do you want to commit the changes ?');
108114
if (commit) {
109115
stdout.writeln('Committing changes...');

lib/main.dart

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -270,26 +270,24 @@ class _RouteWidgetState extends ConsumerState<_RouteWidget> {
270270
void initState() {
271271
super.initState();
272272
if (widget.listen) {
273-
if (currentPlatform.isMobile) {
274-
ref.listenManual(
275-
appLinksListenerProvider,
276-
(previous, next) async {
277-
if (previous == next || next is! AsyncData<Uri?> || next.value == null) {
278-
return;
279-
}
280-
Uri uri = next.value!;
281-
if (uri.host == Uri.parse(App.firebaseLoginUrl).host) {
282-
WidgetsBinding.instance.addPostFrameCallback((_) => handleLoginLink(uri));
283-
return;
284-
}
285-
if (uri.scheme == 'otpauth') {
286-
WidgetsBinding.instance.addPostFrameCallback((_) => handleTotpLink(uri));
287-
return;
288-
}
289-
},
290-
fireImmediately: true,
291-
);
292-
}
273+
ref.listenManual(
274+
appLinksListenerProvider,
275+
(previous, next) async {
276+
if (previous == next || next is! AsyncData<Uri?> || next.value == null) {
277+
return;
278+
}
279+
Uri uri = next.value!;
280+
if (uri.host == Uri.parse(App.firebaseLoginUrl).host) {
281+
WidgetsBinding.instance.addPostFrameCallback((_) => handleLoginLink(uri));
282+
return;
283+
}
284+
if (uri.scheme == 'otpauth') {
285+
WidgetsBinding.instance.addPostFrameCallback((_) => handleTotpLink(uri));
286+
return;
287+
}
288+
},
289+
fireImmediately: true,
290+
);
293291
ref.listenManual(
294292
totpLimitProvider,
295293
(previous, next) async {

linux/my_application.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
1717
// Implements GApplication::activate.
1818
static void my_application_activate(GApplication* application) {
1919
MyApplication* self = MY_APPLICATION(application);
20+
21+
GList* windows = gtk_application_get_windows(GTK_APPLICATION(application));
22+
if (windows) {
23+
gtk_window_present(GTK_WINDOW(windows->data));
24+
return;
25+
}
26+
2027
GtkWindow* window =
2128
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
2229

@@ -40,11 +47,11 @@ static void my_application_activate(GApplication* application) {
4047
if (use_header_bar) {
4148
GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
4249
gtk_widget_show(GTK_WIDGET(header_bar));
43-
gtk_header_bar_set_title(header_bar, "open_authenticator");
50+
gtk_header_bar_set_title(header_bar, "Open Authenticator");
4451
gtk_header_bar_set_show_close_button(header_bar, TRUE);
4552
gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
4653
} else {
47-
gtk_window_set_title(window, "open_authenticator");
54+
gtk_window_set_title(window, "Open Authenticator");
4855
}
4956

5057
gtk_window_set_default_size(window, 1280, 720);
@@ -78,7 +85,7 @@ static gboolean my_application_local_command_line(GApplication* application, gch
7885
g_application_activate(application);
7986
*exit_status = 0;
8087

81-
return TRUE;
88+
return FALSE;
8289
}
8390

8491
// Implements GObject::dispose.
@@ -99,6 +106,6 @@ static void my_application_init(MyApplication* self) {}
99106
MyApplication* my_application_new() {
100107
return MY_APPLICATION(g_object_new(my_application_get_type(),
101108
"application-id", APPLICATION_ID,
102-
"flags", G_APPLICATION_NON_UNIQUE,
109+
"flags", G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN,
103110
nullptr));
104111
}

macos/Runner/AppDelegate.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Cocoa
22
import FlutterMacOS
3+
import app_links
34

45
@main
56
class AppDelegate: FlutterAppDelegate {
@@ -10,4 +11,12 @@ class AppDelegate: FlutterAppDelegate {
1011
override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
1112
return true
1213
}
14+
15+
public override func application(_ application: NSApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([any NSUserActivityRestoring]) -> Void) -> Bool {
16+
guard let url = AppLinks.shared.getUniversalLink(userActivity) else {
17+
return false
18+
}
19+
AppLinks.shared.handleLink(link: url.absoluteString)
20+
return false
21+
}
1322
}

snapcraft.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: open-authenticator
2+
version: 1.3.1
3+
summary: A cross-platform OTP app, free and open-source.
4+
description: Secure your online accounts with a free, open-source and lovely-crafted app.
5+
6+
base: core24
7+
confinement: strict
8+
grade: stable
9+
10+
slots:
11+
dbus-open-authenticator:
12+
interface: dbus
13+
bus: session
14+
name: app.openauthenticator
15+
16+
apps:
17+
open-authenticator:
18+
command: openauthenticator
19+
extensions: [gnome]
20+
plugs:
21+
- network
22+
slots:
23+
- dbus-open-authenticator
24+
parts:
25+
open-authenticator:
26+
source: .
27+
plugin: flutter
28+
flutter-target: lib/main.dart

windows/runner/main.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
#include "flutter_window.h"
66
#include "utils.h"
77

8+
#include "app_links/app_links_plugin_c_api.h"
9+
810
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
911
_In_ wchar_t *command_line, _In_ int show_command) {
12+
if (SendAppLinkToInstance(L"Open Authenticator")) {
13+
return EXIT_SUCCESS;
14+
}
15+
1016
// Attach to console when present (e.g., 'flutter run') or create a
1117
// new console when running with a debugger.
1218
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
@@ -39,5 +45,41 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
3945
}
4046

4147
::CoUninitialize();
48+
4249
return EXIT_SUCCESS;
4350
}
51+
52+
bool SendAppLinkToInstance(const std::wstring& title) {
53+
// Find our exact window
54+
HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", title.c_str());
55+
56+
if (hwnd) {
57+
// Dispatch new link to current window
58+
SendAppLink(hwnd);
59+
60+
// (Optional) Restore our window to front in same state
61+
WINDOWPLACEMENT place = { sizeof(WINDOWPLACEMENT) };
62+
GetWindowPlacement(hwnd, &place);
63+
64+
switch(place.showCmd) {
65+
case SW_SHOWMAXIMIZED:
66+
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
67+
break;
68+
case SW_SHOWMINIMIZED:
69+
ShowWindow(hwnd, SW_RESTORE);
70+
break;
71+
default:
72+
ShowWindow(hwnd, SW_NORMAL);
73+
break;
74+
}
75+
76+
SetWindowPos(0, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
77+
SetForegroundWindow(hwnd);
78+
// END (Optional) Restore
79+
80+
// Window has been found, don't create another one.
81+
return true;
82+
}
83+
84+
return false;
85+
}

0 commit comments

Comments
 (0)