|
1 | 1 | # uni_links_desktop |
2 | 2 |
|
3 | | -A new flutter plugin project. |
| 3 | +[![pub version][pub-image]][pub-url] [![][discord-image]][discord-url] |
4 | 4 |
|
5 | | -## Getting Started |
| 5 | +[pub-image]: https://img.shields.io/pub/v/uni_links_desktop.svg |
| 6 | +[pub-url]: https://pub.dev/packages/uni_links_desktop |
6 | 7 |
|
7 | | -This project is a starting point for a Flutter |
8 | | -[plug-in package](https://flutter.dev/developing-packages/), |
9 | | -a specialized package that includes platform-specific implementation code for |
10 | | -Android and/or iOS. |
| 8 | +[discord-image]: https://img.shields.io/discord/884679008049037342.svg |
| 9 | +[discord-url]: https://discord.gg/zPa6EZ2jqb |
11 | 10 |
|
12 | | -For help getting started with Flutter, view our |
13 | | -[online documentation](https://flutter.dev/docs), which offers tutorials, |
14 | | -samples, guidance on mobile development, and a full API reference. |
| 11 | +A desktop (supports macOS and Windows) implementation of [uni_links](https://github.com/leanflutter/uni_links_desktop) plugin. |
15 | 12 |
|
| 13 | +--- |
| 14 | + |
| 15 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 16 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 17 | + |
| 18 | +- [uni_links_desktop](#uni_links_desktop) |
| 19 | + - [Platform Support](#platform-support) |
| 20 | + - [Quick Start](#quick-start) |
| 21 | + - [Installation](#installation) |
| 22 | + - [Usage](#usage) |
| 23 | + - [macOS](#macos) |
| 24 | + - [Windows](#windows) |
| 25 | + - [Who's using it?](#whos-using-it) |
| 26 | + - [License](#license) |
| 27 | + |
| 28 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 29 | + |
| 30 | +## Platform Support |
| 31 | + |
| 32 | +| Linux | macOS | Windows | |
| 33 | +| :---: | :---: | :-----: | |
| 34 | +| ➖ | ✔️ | ✔️ | |
| 35 | + |
| 36 | +## Quick Start |
| 37 | + |
| 38 | +### Installation |
| 39 | + |
| 40 | +Add this to your package's pubspec.yaml file: |
| 41 | + |
| 42 | +```yaml |
| 43 | +dependencies: |
| 44 | + uni_links_desktop: ^0.1.1 |
| 45 | +``` |
| 46 | +
|
| 47 | +Or |
| 48 | +
|
| 49 | +```yaml |
| 50 | +dependencies: |
| 51 | + uni_links_desktop: |
| 52 | + git: |
| 53 | + url: https://github.com/leanflutter/uni_links_desktop.git |
| 54 | + ref: main |
| 55 | +``` |
| 56 | +
|
| 57 | +### Usage |
| 58 | +
|
| 59 | +```dart |
| 60 | +import 'package:uni_links_desktop/uni_links_desktop.dart'; |
| 61 | + |
| 62 | +void main() { |
| 63 | + if (Platform.isMacOS || Platform.isWindows) { |
| 64 | + enableUniLinksDesktop(); |
| 65 | + if (Platform.isWindows) { |
| 66 | + registerProtocol('unilinks'); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + runApp(MyApp()); |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +> Just add these extra steps, see [uni_links](https://github.com/avioli/uni_links/tree/master/uni_links) for other usage |
| 75 | +
|
| 76 | +##### macOS |
| 77 | + |
| 78 | +Change the file `macos/Runner/Info.plist` as follows: |
| 79 | + |
| 80 | +```diff |
| 81 | +<?xml version="1.0" encoding="UTF-8"?> |
| 82 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 83 | +<plist version="1.0"> |
| 84 | +<dict> |
| 85 | + <key>CFBundleDevelopmentRegion</key> |
| 86 | + <string>$(DEVELOPMENT_LANGUAGE)</string> |
| 87 | + <key>CFBundleExecutable</key> |
| 88 | + <string>$(EXECUTABLE_NAME)</string> |
| 89 | + <key>CFBundleIconFile</key> |
| 90 | + <string></string> |
| 91 | + <key>CFBundleIdentifier</key> |
| 92 | + <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> |
| 93 | + <key>CFBundleInfoDictionaryVersion</key> |
| 94 | + <string>6.0</string> |
| 95 | + <key>CFBundleName</key> |
| 96 | + <string>$(PRODUCT_NAME)</string> |
| 97 | + <key>CFBundlePackageType</key> |
| 98 | + <string>APPL</string> |
| 99 | + <key>CFBundleShortVersionString</key> |
| 100 | + <string>$(FLUTTER_BUILD_NAME)</string> |
| 101 | + <key>CFBundleVersion</key> |
| 102 | + <string>$(FLUTTER_BUILD_NUMBER)</string> |
| 103 | + <key>LSMinimumSystemVersion</key> |
| 104 | + <string>$(MACOSX_DEPLOYMENT_TARGET)</string> |
| 105 | + <key>NSHumanReadableCopyright</key> |
| 106 | + <string>$(PRODUCT_COPYRIGHT)</string> |
| 107 | + <key>NSMainNibFile</key> |
| 108 | + <string>MainMenu</string> |
| 109 | ++ <key>CFBundleURLTypes</key> |
| 110 | ++ <array> |
| 111 | ++ <dict> |
| 112 | ++ <key>CFBundleTypeRole</key> |
| 113 | ++ <string>Editor</string> |
| 114 | ++ <key>CFBundleURLName</key> |
| 115 | ++ <string></string> |
| 116 | ++ <key>CFBundleURLSchemes</key> |
| 117 | ++ <array> |
| 118 | ++ <string>unilinks</string> |
| 119 | ++ </array> |
| 120 | ++ </dict> |
| 121 | ++ </array> |
| 122 | + <key>NSPrincipalClass</key> |
| 123 | + <string>NSApplication</string> |
| 124 | +</dict> |
| 125 | +</plist> |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +##### Windows |
| 130 | + |
| 131 | +Change the file `windows/runner/main.cpp` as follows: |
| 132 | + |
| 133 | +```diff |
| 134 | +#include <flutter/dart_project.h> |
| 135 | +#include <flutter/flutter_view_controller.h> |
| 136 | +#include <windows.h> |
| 137 | + |
| 138 | +#include "flutter_window.h" |
| 139 | +#include "utils.h" |
| 140 | + |
| 141 | ++#include <protocol_handler/protocol_handler_plugin.h> |
| 142 | + |
| 143 | +int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, |
| 144 | + _In_ wchar_t *command_line, _In_ int show_command) { |
| 145 | ++ HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"uni_links_desktop_example"); |
| 146 | ++ if (hwnd != NULL) { |
| 147 | ++ DispatchToProtocolHandler(hwnd); |
| 148 | ++ |
| 149 | ++ ::ShowWindow(hwnd, SW_NORMAL); |
| 150 | ++ ::SetForegroundWindow(hwnd); |
| 151 | ++ return EXIT_FAILURE; |
| 152 | ++ } |
| 153 | + |
| 154 | + // Attach to console when present (e.g., 'flutter run') or create a |
| 155 | + // new console when running with a debugger. |
| 156 | + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { |
| 157 | + CreateAndAttachConsole(); |
| 158 | + } |
| 159 | + |
| 160 | + // Initialize COM, so that it is available for use in the library and/or |
| 161 | + // plugins. |
| 162 | + ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); |
| 163 | + |
| 164 | + flutter::DartProject project(L"data"); |
| 165 | + |
| 166 | + std::vector<std::string> command_line_arguments = |
| 167 | + GetCommandLineArguments(); |
| 168 | + |
| 169 | + project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); |
| 170 | + |
| 171 | + FlutterWindow window(project); |
| 172 | + Win32Window::Point origin(10, 10); |
| 173 | + Win32Window::Size size(1280, 720); |
| 174 | + if (!window.CreateAndShow(L"uni_links_desktop_example", origin, size)) { |
| 175 | + return EXIT_FAILURE; |
| 176 | + } |
| 177 | + window.SetQuitOnClose(true); |
| 178 | + |
| 179 | + ::MSG msg; |
| 180 | + while (::GetMessage(&msg, nullptr, 0, 0)) { |
| 181 | + ::TranslateMessage(&msg); |
| 182 | + ::DispatchMessage(&msg); |
| 183 | + } |
| 184 | + |
| 185 | + ::CoUninitialize(); |
| 186 | + return EXIT_SUCCESS; |
| 187 | +} |
| 188 | +``` |
| 189 | + |
| 190 | +> Please see the example app of this plugin for a full example. |
| 191 | +
|
| 192 | +## Who's using it? |
| 193 | + |
| 194 | +- [Biyi](https://biyidev.com/) - A convenient translation and dictionary app. |
| 195 | + |
| 196 | +## License |
| 197 | + |
| 198 | +[MIT](./LICENSE) |
0 commit comments