예제 #1
0
        protected override void OnCreate()
        {
            base.OnCreate();

            // Get paths to resources required for launch.
            string resPath     = Current.DirectoryInfo.Resource;
            string assetsPath  = $"{resPath}/flutter_assets";
            string icuDataPath = $"{resPath}/icudtl.dat";
            string aotLibPath  = $"{resPath}/../lib/libapp.so";

            // Read engine arguments passed from the tool.
            ParseEngineArgs();

            using var switches = new StringArray(EngineArgs);
            var engineProperties = new FlutterDesktopEngineProperties
            {
                assets_path      = assetsPath,
                icu_data_path    = icuDataPath,
                aot_library_path = aotLibPath,
                switches         = switches.Handle,
                switches_count   = (uint)switches.Length,
            };

            Handle = FlutterDesktopRunEngine(ref engineProperties, true);
            if (Handle.IsInvalid)
            {
                throw new Exception("Could not launch a Flutter application.");
            }
        }
        protected override void OnCreate()
        {
            base.OnCreate();

            Utils.ParseEngineArgs(EngineArgs);

            using (var switches = new StringArray(EngineArgs))
                using (var entrypointArgs = new StringArray(DartEntrypointArgs))
                {
                    var engineProperties = new FlutterDesktopEngineProperties
                    {
                        assets_path          = "../res/flutter_assets",
                        icu_data_path        = "../res/icudtl.dat",
                        aot_library_path     = "../lib/libapp.so",
                        switches             = switches.Handle,
                        switches_count       = (uint)switches.Length,
                        entrypoint           = DartEntrypoint,
                        dart_entrypoint_argc = entrypointArgs.Length,
                        dart_entrypoint_argv = entrypointArgs.Handle,
                    };

                    Engine = FlutterDesktopEngineCreate(ref engineProperties);
                    if (Engine.IsInvalid)
                    {
                        throw new Exception("Could not create a Flutter engine.");
                    }

                    if (!FlutterDesktopEngineRun(Engine))
                    {
                        throw new Exception("Could not launch a service application.");
                    }
                }
        }
예제 #3
0
        protected override void OnCreate()
        {
            base.OnCreate();

            Utils.ParseEngineArgs(EngineArgs);

            using (var switches = new StringArray(EngineArgs))
                using (var entrypointArgs = new StringArray(DartEntrypointArgs))
                {
                    var engineProperties = new FlutterDesktopEngineProperties
                    {
                        assets_path          = "../res/flutter_assets",
                        icu_data_path        = "../res/icudtl.dat",
                        aot_library_path     = "../lib/libapp.so",
                        switches             = switches.Handle,
                        switches_count       = (uint)switches.Length,
                        entrypoint           = DartEntrypoint,
                        dart_entrypoint_argc = entrypointArgs.Length,
                        dart_entrypoint_argv = entrypointArgs.Handle,
                    };

                    Engine = FlutterDesktopEngineCreate(ref engineProperties);
                    if (Engine.IsInvalid)
                    {
                        throw new Exception("Could not create a Flutter engine.");
                    }
                }

            var windowProperties = new FlutterDesktopWindowProperties
            {
                x           = WindowOffsetX,
                y           = WindowOffsetY,
                width       = WindowWidth,
                height      = WindowHeight,
                transparent = IsWindowTransparent,
                focusable   = IsWindowFocusable,
                top_level   = IsTopLevel,
            };

            View = FlutterDesktopViewCreateFromNewWindow(ref windowProperties, Engine);
            if (View.IsInvalid)
            {
                throw new Exception("Could not launch a Flutter application.");
            }
        }
        protected override void OnCreate()
        {
            base.OnCreate();

            var windowProperties = new FlutterDesktopWindowProperties
            {
                headed      = IsHeaded,
                x           = WindowOffsetX,
                y           = WindowOffsetY,
                width       = WindowWidth,
                height      = WindowHeight,
                transparent = IsWindowTransparent,
                focusable   = IsWindowFocusable,
            };

            Utils.ParseEngineArgs(EngineArgs);

            using var switches       = new StringArray(EngineArgs);
            using var entrypointArgs = new StringArray(DartEntrypointArgs);
            var engineProperties = new FlutterDesktopEngineProperties
            {
                assets_path          = "../res/flutter_assets",
                icu_data_path        = "../res/icudtl.dat",
                aot_library_path     = "../lib/libapp.so",
                switches             = switches.Handle,
                switches_count       = (uint)switches.Length,
                entrypoint           = DartEntrypoint,
                dart_entrypoint_argc = entrypointArgs.Length,
                dart_entrypoint_argv = entrypointArgs.Handle,
            };

            Handle = FlutterDesktopRunEngine(ref windowProperties, ref engineProperties);
            if (Handle.IsInvalid)
            {
                throw new Exception("Could not launch a Flutter application.");
            }
        }
예제 #5
0
 public static extern FlutterDesktopEngine FlutterDesktopRunEngine(
     ref FlutterDesktopWindowProperties window_properties,
     ref FlutterDesktopEngineProperties engine_properties);
예제 #6
0
 public static extern FlutterDesktopEngine FlutterDesktopEngineCreate(
     ref FlutterDesktopEngineProperties engine_properties);
예제 #7
0
 public static extern FlutterDesktopEngine FlutterDesktopRunEngine(
     ref FlutterDesktopEngineProperties engine_properties,
     bool headed);
예제 #8
0
파일: App.cs 프로젝트: swift-kim/embedder
        protected override void OnCreate()
        {
            base.OnCreate();

            Console.WriteLine("Preparing to start a Flutter application...");

            if (!Information.TryGetValue("http://tizen.org/feature/screen.width", out int width) ||
                !Information.TryGetValue("http://tizen.org/feature/screen.height", out int height))
            {
                Console.Error.WriteLine("Could not obtain the screen size.");
                return;
            }
            var size = new FlutterDesktopSize
            {
                width  = width,
                height = height
            };

            var appRoot = Path.GetDirectoryName(Path.GetDirectoryName(Current.ApplicationInfo.ExecutablePath));
            var arch    = RuntimeInformation.ProcessArchitecture switch
            {
                Architecture.X86 => "x86",
                Architecture.X64 => "x64",
                Architecture.Arm => "arm",
                Architecture.Arm64 => "aarch64",
                _ => "",
            };
            var aotLibPath  = Path.Combine(appRoot, "lib", arch, "libapp.so");
            var assetsPath  = Path.Combine(appRoot, "res", "flutter_assets");
            var icuDataPath = Path.Combine(appRoot, "res", "icudtl.dat");

            var args = new List <string>
            {
                "--verbose-logging",
                "--trace-startup",
                "--disable-service-auth-codes",
            };

            if (FlutterEngineRunsAOTCompiledDartCode())
            {
                Console.WriteLine("Run AOT compiled Dart code: " + aotLibPath);
                args.Add("--aot-shared-library-name=" + aotLibPath);
            }

            var properties = new FlutterDesktopEngineProperties
            {
                assets_path   = assetsPath,
                icu_data_path = icuDataPath,
            };

            var pSize       = Marshal.AllocHGlobal(Marshal.SizeOf(size));
            var pProperties = Marshal.AllocHGlobal(Marshal.SizeOf(properties));

            Marshal.StructureToPtr <FlutterDesktopSize>(size, pSize, false);
            Marshal.StructureToPtr <FlutterDesktopEngineProperties>(properties, pProperties, false);

            try
            {
                Instance = RunFlutterApplication(pSize, pProperties, args.ToArray(), (uint)args.Count);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Could not start the Flutter application: " + ex);
            }
            finally
            {
                Marshal.FreeHGlobal(pSize);
                Marshal.FreeHGlobal(pProperties);
            }
        }
        public FlutterIntegration(string projectPath, params FlutterPlugin[] plugins)
        {
            try
            {
                FlutterWindowsInterop.SetProjectPath(projectPath);
                var props = new FlutterDesktopEngineProperties
                {
                    AssetsPath     = Path.Combine(FlutterWindowsInterop.ProjectPath, @"data\flutter_assets"),
                    IcuDataPath    = Path.Combine(FlutterWindowsInterop.ProjectPath, @"data\icudtl.dat"),
                    AotLibraryPath = Path.Combine(FlutterWindowsInterop.ProjectPath, @"data\app.so"),
                    //Switches = FlutterWindowsInterop.CreateSwitches(new[] { "--observatory-port=49494" }),
                    //SwitchesCount = new IntPtr(1)
                };

#if DEBUG
                var debugSwitches = new[] {
                    "--observatory-port=49494",
                    "--disable-service-auth-codes"
                };
                props.Switches      = FlutterWindowsInterop.CreateSwitches(debugSwitches);
                props.SwitchesCount = new IntPtr(debugSwitches.Length);
                NativeMethods.AllocConsole();
                FlutterWindowsInterop.FlutterDesktopResyncOutputStreams();
#endif

                _controller = FlutterWindowsInterop.FlutterDesktopCreateViewController(1024, 768, props);
                RegisterPlugins(_controller, plugins);

                _control = new Lazy <HwndWrapperControl>(() =>
                {
                    var view = FlutterWindowsInterop.FlutterDesktopGetView(_controller);
                    return(new HwndWrapperControl(FlutterWindowsInterop.FlutterDesktopViewGetHWND(view)));
                });

                ulong next_flutter_event_time = (ulong)DateTime.Now.Ticks;
                CompositionTarget.Rendering += (s, e) =>
                {
                    /*taken from run_loop.cpp
                     *
                     * bool processedEvents = false;
                     * while(NativeMethods.PeekMessage(out var msg, Control.ChildWnd, (Messages.WM)0, (Messages.WM)0, Messages.PM.REMOVE))
                     * {
                     *  processedEvents = true;
                     *  NativeMethods.TranslateMessage(ref msg);
                     *  NativeMethods.DispatchMessage(ref msg);
                     *  next_flutter_event_time = Math.Min(next_flutter_event_time ,
                     *      FlutterWindowsInterop.FlutterDesktopProcessMessages(_controller));
                     * }
                     * if(!processedEvents)
                     * {
                     *  next_flutter_event_time = Math.Min(next_flutter_event_time,
                     *      FlutterWindowsInterop.FlutterDesktopProcessMessages(_controller));
                     * }*/
                    //NativeMethods.PostMessage(Control.ChildWnd, 0, IntPtr.Zero, IntPtr.Zero);
                    FlutterWindowsInterop.FlutterDesktopProcessMessages(_controller);
                };

                /*_runLoopTimer = new DispatcherTimer(DispatcherPriority.Render);
                 * _runLoopTimer.Interval =
                 *
                 * _runLoopTimer.Tick += (s, e) =>
                 * {
                 *
                 * };*/
                //_runLoopTimer.Start();
            }
            catch (Exception ex)
            {
            }
        }