Example #1
0
        public static void Main(string[] args)
        {
            Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ConfigContext context = new ConfigContext();

            try
            {
                ConfigHelper.DoConfig(context);
            }
            catch
            {
                // suppress error
            }
            _branch = context.Branch;
            context.SystemTray.Dispose();

            // check for updates
            if (_branch is null)
            {
#if BRANCH_unstable
                _branch = Branch.Unstable;
#elif BRANCH_stable
                _branch = Branch.Stable;
#elif BRANCH_beta
                _branch = Branch.Beta;
#else
                _branch = Branch.None;
#endif
            }

            if (_branch != Branch.None)
            {
                AutoUpdater.RunUpdateAsAdmin      = !IsDirectoryWritable(AppContext.BaseDirectory);
                AutoUpdater.ParseUpdateInfoEvent += AutoUpdater_ParseUpdateInfoEvent;
                AutoUpdater.ApplicationExitEvent += AutoUpdater_ApplicationExitEvent;

                Timer timer = new Timer(1000 * 60 * 60);
                timer.Elapsed += (_, _) =>
                {
                    AutoUpdater.Start("https://raw.githubusercontent.com/workspacer/workspacer/master/README.md");
                };
                timer.Enabled = true;
                // Put url to trigger ParseUpdateInfoEvent
                AutoUpdater.Start("https://raw.githubusercontent.com/workspacer/workspacer/master/README.md");
            }

            Run();
        }
Example #2
0
        public void Start()
        {
            // init user folder
            FileHelper.EnsureUserWorkspacerPathExists();

            // init logging
            Logger.Initialize(FileHelper.GetUserWorkspacerPath());
            Logger.Debug("starting workspacer");

            // init plugin assembly resolver
            AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;

            // init context and managers
            _context = new ConfigContext();

            // connect to watcher
            _context.ConnectToWatcher();

            // attach console output target
            Logger.AttachConsoleLogger((str) => _context.SendLogToConsole(str));

            // init system tray
            _context.SystemTray.AddToContextMenu("enable/disable workspacer", () => _context.Enabled = !_context.Enabled);
            _context.SystemTray.AddToContextMenu("quit workspacer", () => _context.Quit());
            _context.SystemTray.AddToContextMenu("restart workspacer", () => _context.Restart());
            _context.SystemTray.AddToContextMenu("show/hide keybind help", () => _context.Keybinds.ShowKeybindDialog());
            if (ConfigHelper.CanCreateExampleConfig())
            {
                _context.SystemTray.AddToContextMenu("create example workspacer.config.csx", CreateExampleConfig);
            }

            // init config
            ConfigHelper.DoConfig(_context);

            // init windows
            _context.Windows.Initialize();

            // verify config
            var allWorkspaces = _context.WorkspaceContainer.GetAllWorkspaces().ToList();

            // check to make sure there are enough workspaces for the monitors
            if (_context.MonitorContainer.NumMonitors > allWorkspaces.Count)
            {
                throw new Exception("you must specify at least enough workspaces to cover all monitors");
            }

            // init workspaces
            var state = _context.LoadState();

            if (state != null)
            {
                _context.Workspaces.InitializeWithState(state.WorkspaceState, _context.Windows.Windows);
                Enabled = true;
            }
            else
            {
                _context.Workspaces.Initialize(_context.Windows.Windows);
                Enabled = true;
                _context.Workspaces.SwitchToWorkspace(0);
            }

            // force first layout
            foreach (var workspace in _context.WorkspaceContainer.GetAllWorkspaces())
            {
                workspace.DoLayout();
            }

            // notify plugins that config is done
            _context.Plugins.AfterConfig(_context);

            // start message pump on main thread
            Application.Run();
        }