static void Main() { // Do this before Composer.Init() because of the Disabled setting Settings.LoadConfig(); Composer.Init(); Settings.LoadSequences(); KeyboardHook.Init(); Updater.Init(); Settings.StartWatchConfigFile(); try { var app = new Application(); var icon = new SysTrayIcon(); app.Exit += (o, e) => icon.Dispose(); app.Run(); } finally { Settings.StopWatchConfigFile(); Updater.Fini(); KeyboardHook.Fini(); Settings.SaveConfig(); Composer.Fini(); Updater.Fini(); } }
static void Main() { Composer.Init(); Settings.LoadConfig(); Settings.LoadSequences(); KeyboardHook.Init(); Settings.StartWatchConfigFile(); try { WinForms.Application.EnableVisualStyles(); WinForms.Application.SetCompatibleTextRenderingDefault(false); m_control = new RemoteControl(); m_control.DisableEvent += OnDisableEvent; m_control.ExitEvent += OnExitEvent; m_control.TriggerDisableEvent(); m_tray_icon = new WinForms.NotifyIcon { Visible = true, Icon = Properties.Resources.IconNormal, ContextMenu = new WinForms.ContextMenu(new[] { new WinForms.MenuItem("WinCompose") { Enabled = false }, new WinForms.MenuItem("-"), new WinForms.MenuItem(i18n.Text.ShowSequences, ShowSequencesClicked), new WinForms.MenuItem(i18n.Text.ShowOptions, ShowOptionsClicked), /* Keep a reference on this entry */ m_disable_item = new WinForms.MenuItem(i18n.Text.Disable, DisableClicked), new WinForms.MenuItem(i18n.Text.About, AboutClicked), new WinForms.MenuItem("-"), new WinForms.MenuItem(i18n.Text.Restart, RestartClicked), new WinForms.MenuItem(i18n.Text.Exit, OnExitEvent), }) }; m_tray_icon.DoubleClick += NotifyiconDoubleclicked; Composer.Changed += ComposerStateChanged; WinForms.Application.Run(); m_tray_icon.Dispose(); } finally { Composer.Changed -= ComposerStateChanged; m_control.DisableEvent -= OnDisableEvent; m_control.ExitEvent -= OnExitEvent; Settings.StopWatchConfigFile(); KeyboardHook.Fini(); Settings.SaveConfig(); Composer.Fini(); } }
static void Main(string[] args) { // Some commandline flags just trigger a message broadcast var command_flags = new Dictionary <string, MenuCommand>() { { "-sequences", MenuCommand.ShowSequences }, { "-settings", MenuCommand.ShowOptions }, }; foreach (var arg in args) { if (command_flags.TryGetValue(arg, out var cmd)) { NativeMethods.PostMessage(HWND.BROADCAST, WM_WINCOMPOSE.OPEN, (int)cmd, 0); return; } } // If started from Task Scheduler, we need to detach otherwise the // system may kill us after some time. if (Array.Find(args, arg => arg == "/fromtask") != null) { Process.Start(Application.ResourceAssembly.Location); return; } // Do this before Composer.Init() because of the Disabled setting Settings.LoadConfig(); Settings.LoadSequences(); Metadata.LoadDB(); KeyboardHook.Init(); Updater.Init(); Settings.StartWatchConfigFile(); try { var app = new Application(); app.Run(); } finally { Settings.StopWatchConfigFile(); Updater.Fini(); KeyboardHook.Fini(); Settings.SaveConfig(); Metadata.SaveDB(); Updater.Fini(); } }
static void Main(string[] args) { // Some commandline flags just trigger a message broadcast var command_flags = new Dictionary <string, MenuCommand>() { { "-sequences", MenuCommand.ShowSequences }, { "-settings", MenuCommand.ShowOptions }, }; foreach (var arg in args) { if (command_flags.TryGetValue(arg, out var cmd)) { NativeMethods.PostMessage(HWND.BROADCAST, WM_WINCOMPOSE.OPEN, (int)cmd, 0); return; } } // Do this before Composer.Init() because of the Disabled setting Settings.LoadConfig(); Composer.Init(); Settings.LoadSequences(); Metadata.LoadDB(); KeyboardHook.Init(); Updater.Init(); Settings.StartWatchConfigFile(); try { var app = new Application(); var icon = new SysTrayIcon(); app.Exit += (o, e) => icon.Dispose(); app.Run(); } finally { Settings.StopWatchConfigFile(); Updater.Fini(); KeyboardHook.Fini(); Settings.SaveConfig(); Metadata.SaveDB(); Composer.Fini(); Updater.Fini(); } }
static void Main() { // Do this before Composer.Init() because of the Disabled setting Settings.LoadConfig(); Composer.Init(); Settings.LoadSequences(); Updater.Init(); Settings.StartWatchConfigFile(); try { WinForms.Application.EnableVisualStyles(); WinForms.Application.SetCompatibleTextRenderingDefault(false); // Must call this after SetCompatibleTextRenderingDefault() // because it uses a WinForms timer which seems to open a // hidden window. The reason we use a WinForms timer is so that // the hook is installed from the main thread. KeyboardHook.Init(); using (SysTrayIcon icon = new SysTrayIcon()) { WinForms.Application.Run(); } } finally { Settings.StopWatchConfigFile(); Updater.Fini(); KeyboardHook.Fini(); Settings.SaveConfig(); Composer.Fini(); Updater.Fini(); } }
static void Main(string[] args) { // Some commandline flags just trigger a message broadcast foreach (var arg in args) { if (m_command_flags.TryGetValue(arg, out var cmd)) { NativeMethods.PostMessage(HWND.BROADCAST, WM_WINCOMPOSE.OPEN, (int)cmd, 0); return; } } Logging.Init(); Logger.Info($"WinCompose {Settings.Version} started, arguments: “{string.Join(" ", args)}”"); // Do this early because of the AutoLaunch setting Settings.LoadConfig(); bool from_task = args.Contains("-fromtask"); bool from_startup = args.Contains("-fromstartup"); // If run from Task Scheduler or from startup but autolaunch is // disabled, exit early. if ((from_task || from_startup) && !Settings.AutoLaunch.Value) { return; } // If run from Task Scheduler but we do not want to run elevated, // exit early. if (from_task && !Settings.RunElevated.Value) { return; } // If run from Task Scheduler, we need to detach otherwise the // system may kill us after some time. if (from_task) { Process.Start(Application.ResourceAssembly.Location, "-detached"); return; } // If run from the start menu but we want to run elevated and there // is a task scheduler entry, give it priority. if (from_startup && Settings.RunElevated.Value) { var ret = TaskScheduler.HasTask("WinCompose"); if (ret) { return; } Logger.Warn($"Scheduled task not found: {ret.Message}"); } // Try to install the Task Scheduler entry. The best time for this is // just after installation, when the installer launches us with elevated // privileges. if (!from_task && Settings.AutoLaunch.Value) { var ret = TaskScheduler.InstallTask("WinCompose", $"\"{Utils.ExecutableName}\" -fromtask", elevated: true, author: "Sam Hocevar"); if (!ret) { Logger.Warn($"Could not install scheduled task: {ret.Message}"); } } Settings.LoadSequences(); Metadata.LoadDB(); KeyboardHook.Init(); Updater.Init(); Settings.StartWatchConfigFile(); try { var app = new Application(); app.Run(); } finally { Settings.StopWatchConfigFile(); Updater.Fini(); KeyboardHook.Fini(); Settings.SaveConfig(); Metadata.SaveDB(); Updater.Fini(); Logger.Info("Program shut down"); } }
static void Main() { // Do this before Composer.Init() because of the Disabled setting Settings.LoadConfig(); Composer.Init(); Settings.LoadSequences(); KeyboardHook.Init(); Updater.Init(); Settings.StartWatchConfigFile(); try { WinForms.Application.EnableVisualStyles(); WinForms.Application.SetCompatibleTextRenderingDefault(false); m_control = new RemoteControl(); m_control.DisableEvent += OnDisableEvent; m_control.DisableEvent += SysTrayUpdateCallback; m_control.ExitEvent += OnExitEvent; m_control.TriggerDisableEvent(); m_tray_icon = new WinForms.NotifyIcon { Visible = true, //Icon = GetCurrentIcon(), //Text = GetCurrentToolTip(), ContextMenu = new WinForms.ContextMenu(new[] { new TitleMenuItem(), new WinForms.MenuItem("-"), new WinForms.MenuItem(i18n.Text.ShowSequences, ShowSequencesClicked), new WinForms.MenuItem(i18n.Text.ShowOptions, ShowOptionsClicked), m_help_item = /* Keep a reference on this entry */ new WinForms.MenuItem(i18n.Text.Help, new[] { new WinForms.MenuItem(i18n.Text.About, AboutClicked), new WinForms.MenuItem(i18n.Text.VisitWebsite, delegate(object o, EventArgs e) { System.Diagnostics.Process.Start("http://wincompose.info/"); }), m_download_item = /* Keep a reference on this entry */ new WinForms.MenuItem("", DownloadClicked) { Visible = false }, }), new WinForms.MenuItem("-"), m_disable_item = /* Keep a reference on this entry */ new WinForms.MenuItem(i18n.Text.Disable, DisableClicked), new WinForms.MenuItem(i18n.Text.Restart, RestartClicked), new WinForms.MenuItem(i18n.Text.Exit, OnExitEvent), }) }; m_tray_icon.DoubleClick += NotifyiconDoubleclicked; Composer.Changed += SysTrayUpdateCallback; Updater.Changed += SysTrayUpdateCallback; SysTrayUpdateCallback(null, new EventArgs()); Updater.Changed += UpdaterStateChanged; UpdaterStateChanged(null, new EventArgs()); WinForms.Application.Run(); m_tray_icon.Dispose(); } finally { Composer.Changed -= SysTrayUpdateCallback; Updater.Changed -= SysTrayUpdateCallback; Updater.Changed -= UpdaterStateChanged; m_control.DisableEvent -= OnDisableEvent; m_control.ExitEvent -= OnExitEvent; Settings.StopWatchConfigFile(); Updater.Fini(); KeyboardHook.Fini(); Settings.SaveConfig(); Composer.Fini(); Updater.Fini(); } }
static void Main(string[] args) { // Some commandline flags just trigger a message broadcast var command_flags = new Dictionary <string, MenuCommand>() { { "-sequences", MenuCommand.ShowSequences }, { "-settings", MenuCommand.ShowOptions }, }; foreach (var arg in args) { if (command_flags.TryGetValue(arg, out var cmd)) { NativeMethods.PostMessage(HWND.BROADCAST, WM_WINCOMPOSE.OPEN, (int)cmd, 0); return; } } // Do this early because of the AutoLaunch setting Settings.LoadConfig(); bool from_task = args.Contains("-fromtask"); bool from_startup = args.Contains("-fromstartup"); // If run from the task scheduler or from startup but autolaunch is // disabled, exit early. if ((from_task || from_startup) && !Settings.AutoLaunch.Value) { return; } // If run from Task Scheduler, we need to detach otherwise the // system may kill us after some time. if (from_task) { Process.Start(Application.ResourceAssembly.Location); return; } // If run from the start menu but there is a task scheduler entry, // give it priority. if (from_startup && SchTasks.HasTask()) { return; } SchTasks.InstallTask(); Settings.LoadSequences(); Metadata.LoadDB(); KeyboardHook.Init(); Updater.Init(); Settings.StartWatchConfigFile(); try { var app = new Application(); app.Run(); } finally { Settings.StopWatchConfigFile(); Updater.Fini(); KeyboardHook.Fini(); Settings.SaveConfig(); Metadata.SaveDB(); Updater.Fini(); } }