/* * MIT License * * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.Objects.ShiftFS; using static ShiftOS.Engine.SkinEngine; namespace ShiftOS.Engine { /// /// Denotes that this class is launchable from the App Launcher. /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class LauncherAttribute : Attribute { /// /// Marks this form as a launcher item that, when clicked, will open the form. /// /// The text displayed on the launcher item /// Whether or not an upgrade must be installed to see the launcher /// The ID of the upgrade - leave blank if requiresUpgrade is false. /// The category that the item will appear in. public LauncherAttribute(string name, bool requiresUpgrade, string upgradeID = "", string category = "Other") { Category = category; Name = name; RequiresUpgrade = requiresUpgrade; ID = upgradeID; } /// /// Gets or sets the name of the launcher item /// public string Name { get; set; } /// /// Gets or sets whether this entry requires a Shiftorium upgrade. /// public bool RequiresUpgrade { get; set; } /// /// Gets or sets the ID of the required upgrade. /// public string ID { get; set; } /// /// Gets or sets this item's category. /// public string Category { get; internal set; } /// /// Gets whether or not the required upgrade is installed. /// public bool UpgradeInstalled { get { if (!RequiresUpgrade) return true; return Shiftorium.UpgradeInstalled(ID); } } } /// /// Provides core functionality for a typical ShiftOS desktop. /// public interface IDesktop { /// /// Gets the name of the desktop. /// string DesktopName { get; } /// /// Show a notification on the desktop. /// /// An application ID (for determining what system icon to show the notification alongside) /// The title of the notification. /// Isn't this.... self explanatory? void PushNotification(string app, string title, string message); /// /// Performs most of the skinning and layout handling for the desktop. /// void SetupDesktop(); /// /// Hides the currently-opened app launcher menu. /// void HideAppLauncher(); /// /// Populates the app launcher menu. /// /// All items to be placed in the menu. void PopulateAppLauncher(LauncherItem[] items); /// /// Handles desktop-specific routines for showing ShiftOS windows. /// /// The calling window. void ShowWindow(IWindowBorder border); /// /// Handles desktop-specific routines for closing ShiftOS windows. /// /// The calling window. void KillWindow(IWindowBorder border); /// /// Populates the panel button list with all open windows. /// void PopulatePanelButtons(); /// /// Performs desktop-specific routines for minimizing a window. /// /// The calling window. void MinimizeWindow(IWindowBorder brdr); /// /// Performs desktop-specific routines for maximizing a window. /// /// The calling window. void MaximizeWindow(IWindowBorder brdr); /// /// Performs desktop-specific routines for restoring a window to its default state. /// /// The calling window. void RestoreWindow(IWindowBorder brdr); /// /// Invokes an action on the UI thread. /// /// The action to invoke. void InvokeOnWorkerThread(Action act); /// /// Calculates the screen size of the desktop. /// /// The desktop's screen size. Size GetSize(); /// /// Opens the app launcher at a specific point. /// /// Where the app launcher should be opened. void OpenAppLauncher(Point loc); /// /// Opens the desktop. /// void Show(); /// /// Closes the desktop. /// void Close(); } public static class Desktop { /// /// The underlying desktop object. /// private static IDesktop _desktop = null; public static Size Size { get { return _desktop.GetSize(); } } public static IDesktop CurrentDesktop { get { return _desktop; } } public static void Init(IDesktop desk, bool show = false) { IDesktop deskToClose = null; if (_desktop != null) deskToClose = _desktop; _desktop = desk; if (show == true) _desktop.Show(); deskToClose?.Close(); } public static void MinimizeWindow(IWindowBorder brdr) { _desktop.MinimizeWindow(brdr); } public static void MaximizeWindow(IWindowBorder brdr) { _desktop.MaximizeWindow(brdr); } public static void RestoreWindow(IWindowBorder brdr) { _desktop.RestoreWindow(brdr); } public static void InvokeOnWorkerThread(Action act) { _desktop.InvokeOnWorkerThread(act); } public static void ResetPanelButtons() { _desktop.PopulatePanelButtons(); } public static void ShowWindow(IWindowBorder brdr) { _desktop.ShowWindow(brdr); } public static void PopulateAppLauncher() { _desktop.PopulateAppLauncher(AppLauncherDaemon.Available().ToArray()); } public static void OpenAppLauncher(Point loc) { _desktop.OpenAppLauncher(loc); } public static void HideAppLauncher() { _desktop.HideAppLauncher(); } public static void PushNotification(string app, string title, string msg) { InvokeOnWorkerThread(() => { _desktop.PushNotification(app, title, msg); }); } } // sorry i almost killed everything :P }