示例#1
0
        public void RegisterUserHooks()
        {
            var directory = PlatformUtils.CombineDataPath("scripts");

            Log.Information($"User script directory: {directory}");

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            var files = Directory.GetFiles(directory, "*.cs", SearchOption.TopDirectoryOnly);

            Log.Information($"ScriptManager: {files.Length} user script(s) found");

            foreach (var file in files.Where(x => x != null))
            {
                try
                {
                    var script = File.ReadAllText(file);
                    RegisterHook((IHook)CSScript.Evaluator.LoadCode(script));
                    Log.Debug($"ScriptManager: {Path.GetFileName(file)} hooked successfully");
                }
                catch (CompilerException ex)
                {
                    Log.Error($"[{Path.GetFileName(file)}]: Compiler error in user script : {ex.Message}");
                }
                catch (Exception ex)
                {
                    Log.Error($"[{Path.GetFileName(file)}]: Failed to hook user script: {ex.Message}");
                }
            }
        }
示例#2
0
        // Initialization code. Don't use any Avalonia, third-party APIs or any
        // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
        // yet and stuff might break.
        public static async Task Main(string[] args)
        {
            var config = new LoggerConfiguration()
                         .WriteTo.Sentry(o =>
            {
                o.MinimumBreadcrumbLevel = Serilog.Events.LogEventLevel.Debug;
                o.MinimumEventLevel      = Serilog.Events.LogEventLevel.Fatal;
            })
                         .WriteTo.File(PlatformUtils.CombineDataPath("application.log"))
                         .WriteTo.Console();

            config = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("VERBOSE")) ?
                     config.MinimumLevel.Verbose() : config.MinimumLevel.Debug();

            Log.Logger = config.CreateLogger();

            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);

            Trace.Listeners.Add(new ConsoleTraceListener());

            SentrySdk.Init(o =>
            {
                o.Dsn            = "https://[email protected]/5462682";
                o.MaxBreadcrumbs = 120;
                o.SendDefaultPii = true;
#if DEBUG
                o.Environment = "staging";
#else
                o.Environment = "production";
#endif
                o.BeforeSend = sentryEvent =>
                {
                    try
                    {
                        sentryEvent.SetTag("arch", System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString());
                        sentryEvent.SetTag("bluetooth-mac", SettingsProvider.Instance.RegisteredDevice.MacAddress);
                        sentryEvent.SetTag("sw-version",
                                           DeviceMessageCache.Instance.DebugGetAllData?.SoftwareVersion ?? "null");

                        sentryEvent.SetExtra("arch", System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString());
                        sentryEvent.SetExtra("bluetooth-mac", SettingsProvider.Instance.RegisteredDevice.MacAddress);
                        sentryEvent.SetExtra("bluetooth-model-saved", SettingsProvider.Instance.RegisteredDevice.Model);
                        sentryEvent.SetExtra("custom-locale", SettingsProvider.Instance.Locale);
                        sentryEvent.SetExtra("sw-version",
                                             DeviceMessageCache.Instance.DebugGetAllData?.SoftwareVersion ?? "null");

                        if (MainWindow.IsReady())
                        {
                            sentryEvent.SetExtra("current-page", MainWindow.Instance.Pager.CurrentPage);
                        }
                        else
                        {
                            sentryEvent.SetExtra("current-page", "instance_not_initialized");
                        }

                        sentryEvent.SetTag("bluetooth-model", BluetoothImpl.Instance.ActiveModel.ToString());
                        sentryEvent.SetExtra("bluetooth-model", BluetoothImpl.Instance.ActiveModel);
                        sentryEvent.SetExtra("bluetooth-connected", BluetoothImpl.Instance.IsConnected);
                    }
                    catch (Exception ex)
                    {
                        sentryEvent.SetExtra("beforesend-error", ex);
                        Log.Error("Sentry.BeforeSend: Error while adding attachments: " + ex.Message);
                    }

                    return(sentryEvent);
                };
            });

            /* Fix Avalonia font issue */
            if (PlatformUtils.IsLinux)
            {
                try
                {
                    Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
                }
                catch (CultureNotFoundException ex)
                {
                    Log.Warning("Startup: Culture en-US unavailable. Falling back to C. " + ex);
                    Thread.CurrentThread.CurrentCulture   = new CultureInfo("C");
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("C");
                }
            }

            try
            {
                // OSX: Graphics must be drawn on the main thread.
                // Awaiting this call would implicitly cause the next code to run as a async continuation task
                if (PlatformUtils.IsOSX)
                {
                    SingleInstanceWatcher.Setup().Wait();
                }
                else
                {
                    await SingleInstanceWatcher.Setup();
                }

                BuildAvaloniaApp().StartWithClassicDesktopLifetime(args, ShutdownMode.OnExplicitShutdown);
            }
            catch (Exception ex)
            {
                SentrySdk.CaptureException(ex);
                Log.Error(ex.ToString());
            }
        }
示例#3
0
 public static string GetTranslatorModeFile()
 {
     return(PlatformUtils.CombineDataPath("custom_language.xaml"));
 }
示例#4
0
 public async Task ConnectAsync(string macAddress, string serviceUuid, bool noRetry = false)
 {
     BluetoothErrorAsync?.Invoke(this, new BluetoothException(BluetoothException.ErrorCodes.Unknown,
                                                              "Platform configuration not supported." +
                                                              "For Windows users, it is recommended to use Windows 10 build 1803 and later since it provides a much more reliable and newer bluetooth interface. " +
                                                              $"You can find more information about the cause of this error in the application logs ({PlatformUtils.CombineDataPath("application.log")})."));
     await Task.CompletedTask;
 }