Skip to content

Commit

Permalink
v1.28.0-beat.1 (#76)
Browse files Browse the repository at this point in the history
* chore: add flutter_inappwebview

* feat: enable flutter_inappwebview

* chore: remove unused deps

* chore: update building config

* feat: expose open method to webview

* feat: upgrade core

* chore: v1.28.0-beat.1
  • Loading branch information
igoogolx authored Jan 18, 2025
1 parent c2f4206 commit 35be0d7
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 127 deletions.
102 changes: 61 additions & 41 deletions lib/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,65 +1,85 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';
import 'package:webview_win_floating/webview_plugin.dart';
import 'package:window_manager/window_manager.dart';
import 'package:path/path.dart' as path;

class WebViewDashboard extends StatefulWidget {
final String baseUrl;
final String urlStr;
final String homeDir;
final WebViewEnvironment? webViewEnvironment;

const WebViewDashboard(this.homeDir, this.baseUrl, this.urlStr, {super.key});
const WebViewDashboard(this.baseUrl, this.urlStr, this.webViewEnvironment,
{super.key});

@override
State<WebViewDashboard> createState() => _WebViewDashboardState();
State<WebViewDashboard> createState() => _WebViewDashboard();
}

class _WebViewDashboardState extends State<WebViewDashboard> {
late WebViewController? _controller;
class _WebViewDashboard extends State<WebViewDashboard> {
final GlobalKey webViewKey = GlobalKey();

_WebViewDashboardState();
InAppWebViewController? webViewController;
InAppWebViewSettings settings = InAppWebViewSettings(
isInspectable: kDebugMode,
);

@override
void initState() {
super.initState();
late final PlatformWebViewControllerCreationParams params;
if (WebViewPlatform.instance is WebKitWebViewPlatform) {
params = WebKitWebViewControllerCreationParams();
} else {
String cacheDir = path.join(widget.homeDir, 'cache_webview');
params = WindowsPlatformWebViewControllerCreationParams(
userDataFolder: cacheDir);
}
final WebViewController controller =
WebViewController.fromPlatformCreationParams(params);

controller.setNavigationDelegate(
NavigationDelegate(onNavigationRequest: (NavigationRequest request) {
if (request.url.startsWith(widget.baseUrl)) {
return NavigationDecision.navigate;
}
launchUrl(Uri.parse(request.url));
return NavigationDecision.prevent;
}, onPageFinished: (String url) async {
await windowManager.show();
await windowManager.focus();
}),
);
}

controller.loadRequest(Uri.parse(widget.urlStr));
_controller = controller;
@override
void dispose() {
super.dispose();
}

@override
Widget build(BuildContext context) {
if(_controller !=null){
return Scaffold(
body: WebViewWidget(controller: _controller as WebViewController),
);
}
return Text("Disposed");
return InAppWebView(
key: webViewKey,
webViewEnvironment: widget.webViewEnvironment,
initialUrlRequest: URLRequest(url: WebUri(widget.urlStr)),
initialSettings: settings,

onWebViewCreated: (controller) {
webViewController = controller;
controller.addJavaScriptHandler(handlerName: 'open', callback: (args) {
if(args.isNotEmpty){
if(args[0] is String){
var filePath = args[0] as String;
final Uri fileUrl = Uri.parse(filePath);
launchUrl(fileUrl);
}
}
});
},
shouldOverrideUrlLoading: (controller, navigationAction) async {
var uri = navigationAction.request.url!;

if (uri.toString().startsWith(widget.baseUrl)) {
return NavigationActionPolicy.ALLOW;
}

if (!["http", "https", "file", "chrome", "data", "javascript", "about"]
.contains(uri.scheme)) {
if (await canLaunchUrl(uri)) {
await launchUrl(
uri,
);
return NavigationActionPolicy.CANCEL;
}
}

return NavigationActionPolicy.ALLOW;
},
onReceivedError: (controller, request, error) {},
onProgressChanged: (controller, progress) {
if (progress == 100) {
windowManager.show();
windowManager.focus();
}
},
);
}
}
20 changes: 11 additions & 9 deletions lib/home.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:lux/dashboard.dart';
import 'package:window_manager/window_manager.dart';

class Home extends StatefulWidget {
final String baseUrl;
final String urlStr;
final String homeDir;
final WebViewEnvironment? webViewEnvironment;
final bool isWebViewAvailable;

const Home(this.homeDir, this.baseUrl, this.urlStr, {super.key});
const Home(this.baseUrl, this.urlStr, this.webViewEnvironment,this.isWebViewAvailable, {super.key});
@override
State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> with WindowListener {



void _init() async {
windowManager.addListener(this);
await windowManager.setPreventClose(true);
Expand Down Expand Up @@ -46,11 +45,14 @@ class _HomeState extends State<Home> with WindowListener {
}
}


@override
Widget build(BuildContext context) {
if(!widget.isWebViewAvailable){
windowManager.focus();
return Scaffold(body: Center(child: Text("WebView is not available.") ,));
}
return Scaffold(
body: WebViewDashboard(widget.homeDir, widget.baseUrl, widget.urlStr)
);
body: WebViewDashboard(
widget.baseUrl, widget.urlStr, widget.webViewEnvironment));
}
}
}
21 changes: 14 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:lux/const/const.dart';
import 'package:lux/core_manager.dart';
import 'package:lux/elevate.dart';
Expand All @@ -11,10 +12,10 @@ import 'package:lux/tray.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:uuid/uuid.dart';
import 'package:version/version.dart';
import 'package:window_manager/window_manager.dart';
import 'package:url_launcher/url_launcher.dart';

var uuid = Uuid();

Expand All @@ -33,13 +34,22 @@ void openDashboard() async {
launchUrl(url);
}

WebViewEnvironment? webViewEnvironment;
var isWebviewAvailable = true;

void main(args) async {
WidgetsFlutterBinding.ensureInitialized();
await notifier.ensureInitialized();

try {
await windowManager.ensureInitialized();
if (Platform.isWindows) {
final availableVersion = await WebViewEnvironment.getAvailableVersion();
isWebviewAvailable = availableVersion != null;
webViewEnvironment = await WebViewEnvironment.create(
settings: WebViewEnvironmentSettings(userDataFolder: homeDir));
}

await windowManager.ensureInitialized();

PackageInfo packageInfo = await PackageInfo.fromPlatform();
final port = await findAvailablePort(8000, 9000);
Expand Down Expand Up @@ -75,18 +85,15 @@ void main(args) async {
windowManager.waitUntilReadyToShow(windowOptions, () async {});

if (Platform.isWindows) {
initSystemTray(openDashboard,exitApp, () {
initSystemTray(openDashboard, exitApp, () {
windowManager.show();
windowManager.focus();
});
}

runApp(MaterialApp(home: Home(homeDir,baseUrl,urlStr)));
runApp(MaterialApp(home: Home(baseUrl, urlStr, webViewEnvironment,isWebviewAvailable)));
} catch (e) {
await notifier.show("$e");
exitApp();
}
}



4 changes: 2 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ import Foundation

import connectivity_plus
import flutter_desktop_sleep
import flutter_inappwebview_macos
import flutter_window_close
import local_notifier
import package_info_plus
import path_provider_foundation
import screen_retriever_macos
import system_tray
import url_launcher_macos
import webview_flutter_wkwebview
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
FlutterDesktopSleepPlugin.register(with: registry.registrar(forPlugin: "FlutterDesktopSleepPlugin"))
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
FlutterWindowClosePlugin.register(with: registry.registrar(forPlugin: "FlutterWindowClosePlugin"))
LocalNotifierPlugin.register(with: registry.registrar(forPlugin: "LocalNotifierPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin"))
SystemTrayPlugin.register(with: registry.registrar(forPlugin: "SystemTrayPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
FLTWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "FLTWebViewFlutterPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
20 changes: 13 additions & 7 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ PODS:
- FlutterMacOS
- flutter_desktop_sleep (0.0.1):
- FlutterMacOS
- flutter_inappwebview_macos (0.0.1):
- FlutterMacOS
- OrderedSet (~> 6.0.3)
- flutter_window_close (0.0.1):
- FlutterMacOS
- FlutterMacOS (1.0.0)
- local_notifier (0.1.0):
- FlutterMacOS
- OrderedSet (6.0.3)
- package_info_plus (0.0.1):
- FlutterMacOS
- path_provider_foundation (0.0.1):
Expand All @@ -20,15 +24,13 @@ PODS:
- FlutterMacOS
- url_launcher_macos (0.0.1):
- FlutterMacOS
- webview_flutter_wkwebview (0.0.1):
- Flutter
- FlutterMacOS
- window_manager (0.2.0):
- FlutterMacOS

DEPENDENCIES:
- connectivity_plus (from `Flutter/ephemeral/.symlinks/plugins/connectivity_plus/darwin`)
- flutter_desktop_sleep (from `Flutter/ephemeral/.symlinks/plugins/flutter_desktop_sleep/macos`)
- flutter_inappwebview_macos (from `Flutter/ephemeral/.symlinks/plugins/flutter_inappwebview_macos/macos`)
- flutter_window_close (from `Flutter/ephemeral/.symlinks/plugins/flutter_window_close/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- local_notifier (from `Flutter/ephemeral/.symlinks/plugins/local_notifier/macos`)
Expand All @@ -37,14 +39,19 @@ DEPENDENCIES:
- screen_retriever_macos (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever_macos/macos`)
- system_tray (from `Flutter/ephemeral/.symlinks/plugins/system_tray/macos`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
- webview_flutter_wkwebview (from `Flutter/ephemeral/.symlinks/plugins/webview_flutter_wkwebview/darwin`)
- window_manager (from `Flutter/ephemeral/.symlinks/plugins/window_manager/macos`)

SPEC REPOS:
trunk:
- OrderedSet

EXTERNAL SOURCES:
connectivity_plus:
:path: Flutter/ephemeral/.symlinks/plugins/connectivity_plus/darwin
flutter_desktop_sleep:
:path: Flutter/ephemeral/.symlinks/plugins/flutter_desktop_sleep/macos
flutter_inappwebview_macos:
:path: Flutter/ephemeral/.symlinks/plugins/flutter_inappwebview_macos/macos
flutter_window_close:
:path: Flutter/ephemeral/.symlinks/plugins/flutter_window_close/macos
FlutterMacOS:
Expand All @@ -61,23 +68,22 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/system_tray/macos
url_launcher_macos:
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos
webview_flutter_wkwebview:
:path: Flutter/ephemeral/.symlinks/plugins/webview_flutter_wkwebview/darwin
window_manager:
:path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos

SPEC CHECKSUMS:
connectivity_plus: 18382e7311ba19efcaee94442b23b32507b20695
flutter_desktop_sleep: d7e29bb5c2944a0db954674f53ad190b79a7d69d
flutter_inappwebview_macos: bdf207b8f4ebd58e86ae06cd96b147de99a67c9b
flutter_window_close: ee4a6b81ca6fafe93b7cba48b0a18976e3f48e39
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
local_notifier: e9506bc66fc70311e8bc7291fb70f743c081e4ff
OrderedSet: e539b66b644ff081c73a262d24ad552a69be3a94
package_info_plus: 12f1c5c2cfe8727ca46cbd0b26677728972d9a5b
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
screen_retriever_macos: 776e0fa5d42c6163d2bf772d22478df4b302b161
system_tray: e53c972838c69589ff2e77d6d3abfd71332f9e5d
url_launcher_macos: c82c93949963e55b228a30115bd219499a6fe404
webview_flutter_wkwebview: 0982481e3d9c78fd5c6f62a002fcd24fc791f1e4
window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367
Expand Down
Loading

0 comments on commit 35be0d7

Please sign in to comment.