예제 #1
0
        private async void FirstStartAppSuggestingAddLiveTile()
        {
            //ApplicationData.Current.LocalSettings.Values.Remove("IsNotFirstStart"); // remove after testing
            if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("IsNotFirstStart"))
            {
                if (ApiInformation.IsTypePresent("Windows.UI.StartScreen.StartScreenManager"))
                {
                    AppListEntry entry = (await Package.Current.GetAppListEntriesAsync())[0];
                    bool         isSupportedStartScreen = StartScreenManager.GetDefault().SupportsAppListEntry(entry);

                    if (isSupportedStartScreen)
                    {
                        // Check if your app is currently pinned
                        bool isPinned = await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry);

                        if (!isPinned)
                        {
                            // And pin it to Start
                            await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);
                        }
                    }
                }
                ApplicationData.Current.LocalSettings.Values["IsNotFirstStart"] = true;
                //ApplicationData.Current.LocalSettings.Values.Remove("IsNotFirstStart"); // remove after testing
            }
        }
예제 #2
0
        internal static async Task <bool> IsPinnedToStart()
        {
            AppListEntry entry    = (await Package.Current.GetAppListEntriesAsync())[0];
            bool         isPinned = await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry);

            return(isPinned);
        }
예제 #3
0
        public static async Task <PinResult> PinSpecificAppToStartMenuAsync(AppListEntry entry)
        {
            var resultPinResult = PinResult.UnsupportedOs;

            if (!ApiInformation.IsTypePresent("Windows.UI.StartScreen.StartScreenManager"))
            {
                return(resultPinResult);
            }

            if (StartScreenManager.GetDefault().SupportsAppListEntry(entry))
            {
                if (await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry))
                {
                    resultPinResult = PinResult.PinAlreadyPresent;
                }
                else
                {
                    var result = await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);

                    resultPinResult = result ? PinResult.PinPresent : PinResult.PinOperationFailed;
                }
            }
            else
            {
                resultPinResult = PinResult.UnsupportedDevice;
            }

            return(resultPinResult);
        }
예제 #4
0
        internal static async Task <bool> CanPinToStart()
        {
            AppListEntry entry       = (await Package.Current.GetAppListEntriesAsync())[0];
            bool         isSupported = StartScreenManager.GetDefault().SupportsAppListEntry(entry);

            return(isSupported);
        }
예제 #5
0
        private async void ApplicationSearcher()
        {
            PackageManager packageManager = new PackageManager();

            Task <AppEntry>[] appListTasks = packageManager.FindPackagesForUser("").Where(x => !x.IsFramework && !x.IsResourcePackage).Select(async x =>
            {
                try
                {
                    IReadOnlyList <AppListEntry> apps = await x.GetAppListEntriesAsync();
                    if (apps == null || apps.Count == 0)
                    {
                        return(null);
                    }

                    AppListEntry app = apps.First();
                    BitmapImage logo = new BitmapImage();

                    logo.SetSource(await app.DisplayInfo.GetLogo(new Size(16, 16)).OpenReadAsync());
                    return(new AppEntry {
                        Name = app.DisplayInfo.DisplayName, Logo = logo, Entry = app, Package = x
                    });
                }
                catch (Exception e)
                {
                    return(null);
                }
            }).ToArray();
            AppList = (await Task.WhenAll(appListTasks)).Where(x => x != null).OrderBy(x => x.Name).ToList();
            IsDoneTaskSource.SetResult(true);
        }
 public async void NotifyFromDialog(ContentDialogResult dialogResult, object argument)
 {
     if (dialogResult == ContentDialogResult.Primary)
     {
         AppListEntry app = argument as AppListEntry;
         await app.LaunchAsync();
     }
 }
예제 #7
0
        private async void FetchInfos()
        {
            try
            {
                var    pm       = new PackageManager();
                var    packages = pm.FindPackagesForUser("");
                string path     = string.Empty;

                async Task <AppListEntry> GetAppListEntry()
                {
                    foreach (var package in packages)
                    {
                        var result = await package.GetAppListEntriesAsync();

                        for (int i = 0; i < result.Count; i++)
                        {
                            var app = result[i];

                            if (app.AppUserModelId == AppId)
                            {
                                path            = package.InstalledLocation.Path;
                                currentAppIndex = i;
                                return(app);
                            }
                        }
                    }

                    return(null);
                }

                sourceApp = await GetAppListEntry();

                AppName = sourceApp.DisplayInfo.DisplayName;


                var logoPath = GetRefinedLogoPath(path);

                if (File.Exists(logoPath))
                {
                    MemoryStream memoryStream = new MemoryStream();
                    byte[]       fileBytes    = File.ReadAllBytes(logoPath);
                    memoryStream.Write(fileBytes, 0, fileBytes.Length);
                    memoryStream.Position = 0;

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        var image = new BitmapImage();
                        image.BeginInit();
                        image.StreamSource = memoryStream;
                        image.EndInit();
                        AppImage = image;
                    }, System.Windows.Threading.DispatcherPriority.Send);
                }

                InfoFetched?.Invoke(this, null);
            }
            catch { }
        }
예제 #8
0
        private async void LivePin(object sender, RoutedEventArgs e)
        {
            // Get your own app list entry
            // (which is always the first app list entry assuming you are not a multi-app package)
            AppListEntry entry = (await Package.Current.GetAppListEntriesAsync())[0];

            // Check if Start supports your app
            bool isSupported = StartScreenManager.GetDefault().SupportsAppListEntry(entry);

            if (isSupported)
            {
                if (ApiInformation.IsTypePresent("Windows.UI.StartScreen.StartScreenManager"))
                {
                    // Primary tile API's supported!
                    bool isPinned = await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry);

                    if (isPinned)
                    {
                        await new MessageDialog("If not you can manually put the live tile on to the StartScreen", "You already have the live tile in your StartScreen").ShowAsync();
                    }
                    else
                    {
                        bool IsPinned = await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);
                    }
                }
                else
                {
                    await new MessageDialog("You need to update your device to enable automatic pinning", "Update your device").ShowAsync();
                }
            }
            else
            {
                var t = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily;
                switch (t)
                {
                case "Windows.IoT":
                    await new MessageDialog("It seems you are using a IoT device which doesn't support Primary tile API", "live tile failed").ShowAsync();
                    break;

                case "Windows.Team":
                    break;

                case "Windows.Holographic":
                    await new MessageDialog("It seems you are using hololens. Hololens doesn't support live tile", "live tile failed").ShowAsync();
                    break;

                case "Windows.Xbox":
                    await new MessageDialog("It seems you are using a xbox. Xbox doesn't support live tile", "live tile failed").ShowAsync();
                    break;

                default:
                    await new MessageDialog("It seems you are using a " + t + " device. This device does not support Primary tile API", "live tile failed").ShowAsync();
                    break;
                }
            }
        }
예제 #9
0
        private async void LivePin(object sender, RoutedEventArgs e)
        {
            // Get your own app list entry
            // (which is always the first app list entry assuming you are not a multi-app package)
            AppListEntry entry = (await Package.Current.GetAppListEntriesAsync())[0];

            // Check if Start supports your app
            bool isSupported = StartScreenManager.GetDefault().SupportsAppListEntry(entry);

            if (isSupported)
            {
                if (ApiInformation.IsTypePresent("Windows.UI.StartScreen.StartScreenManager"))
                {
                    // Primary tile API's supported!
                    bool isPinned = await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry);

                    if (isPinned)
                    {
                        await new MessageDialog("AlreadyTileDesc".GetLocalized(), "AlreadyTile".GetLocalized()).ShowAsync();
                    }
                    else
                    {
                        bool IsPinned = await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);
                    }
                }
                else
                {
                    await new MessageDialog("UpdateToTile".GetLocalized(), "UpdateDevice".GetLocalized()).ShowAsync();
                }
            }
            else
            {
                var t = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily;
                switch (t)
                {
                case "Windows.IoT":
                    await new MessageDialog("IoTTileFail".GetLocalized(), "LiveTileFailed".GetLocalized()).ShowAsync();
                    break;

                case "Windows.Team":
                    break;

                case "Windows.Holographic":
                    await new MessageDialog("HololensTileFail".GetLocalized(), "LiveTileFailed".GetLocalized()).ShowAsync();
                    break;

                case "Windows.Xbox":
                    await new MessageDialog("XboxTileFail".GetLocalized(), "LiveTileFailed".GetLocalized()).ShowAsync();
                    break;

                default:
                    await new MessageDialog(string.Format("OtherTileFail".GetLocalized(), t), "LiveTileFailed".GetLocalized()).ShowAsync();
                    break;
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Initialize asynchronously the object. Before this method is called, <see cref="AppDetails"/> is not set.
        /// </summary>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        internal Task InitializeAsync()
        {
            var task = Package.GetAppListEntriesAsync().AsTask();

            task.Wait();
            var appEntries = task.Result;

            AppDetails = appEntries.FirstOrDefault();

            return(Task.CompletedTask);
        }
예제 #11
0
 public static async Task <bool?> RequestPinToStartMenu()
 {
     if (IsPinToStartMenuEnabled)
     {
         AppListEntry entry = (await Package.Current.GetAppListEntriesAsync())[0];
         return(await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry));
     }
     else
     {
         return(null);
     }
 }
        private async void SetupControl()
        {
            IReadOnlyList <AppListEntry> appListEntry = await optionalPackage.GetAppListEntriesAsync();

            AppListEntry firstEntry = appListEntry.First();
            var          filestream = await(firstEntry.DisplayInfo.GetLogo(new Windows.Foundation.Size(1, 1))).OpenReadAsync();
            BitmapImage  logo       = new BitmapImage();
            await logo.SetSourceAsync(filestream);

            PackageLogo.Source = logo;

            PackageName.Text = firstEntry.DisplayInfo.DisplayName;
        }
 public async Task<bool> PinAsync()
 {
     bool isPinned = false;
     AppListEntry entry = (await Package.Current.GetAppListEntriesAsync()).FirstOrDefault();
     if (entry != null)
     {
         isPinned = await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry);
     }
     if (!isPinned)
     {
         isPinned = await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);
     }
     return isPinned;
 }
예제 #14
0
        static void Main(string[] args)
        {
            IAsyncOperation <IReadOnlyList <AppListEntry> > result = Windows.ApplicationModel.Package.Current.GetAppListEntriesAsync();

            result.Completed += delegate
            {
                AppListEntry appListEntry             = result.GetResults().First();
                appListEntry.LaunchAsync().Completed += delegate
                {
                    areWeDone.Set();
                };
            };
            areWeDone.WaitOne();
        }
예제 #15
0
        private async Task LauchUwpxAsync()
        {
            UpdateProgressInvoke(100, "Launching UWPX...");
            AppListEntry app = await GetAppByPackageFamilyNameAsync(info.appFamilyName);

            if (app is null)
            {
                UpdateProgressInvoke(100, "Failed to launch UWPX. App not found.");
            }
            else
            {
                await app.LaunchAsync();

                UpdateProgressInvoke(100, "Done");
            }
        }
예제 #16
0
        public static async Task <bool> TryAddPrimaryTile()
        {
            if (!IsUwp() && !PrimaryTileSupport)
            {
                return(false);
            }

            ListEntry = (await Package.Current.GetAppListEntriesAsync())[0];

            if (!StartScreenManager.GetDefault().SupportsAppListEntry(ListEntry))
            {
                return(false);
            }

            return(await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(ListEntry));
        }
예제 #17
0
        public override async Task <AppListReply> ListApps(Empty request, ServerCallContext context)
        {
            AppListReply reply = new AppListReply();

            var results = await _authDbContext.AuthApp
                          .AsNoTracking()
                          .Select(s => new {
                App = s,
                AssignedGroupCount = s.UserGroups.Count(),
            })
                          .ToListAsync();

            foreach (var result in results)
            {
                HostingType hostingType;
                switch (result.App.HostingType)
                {
                case AuthApp.HostingTypeEnum.NON_WEB:
                    hostingType = HostingType.NonWeb;
                    break;

                case AuthApp.HostingTypeEnum.WEB_GATEKEEPER_PROXY:
                    hostingType = HostingType.WebGatekeeperProxy;
                    break;

                case AuthApp.HostingTypeEnum.WEB_GENERIC:
                    hostingType = HostingType.WebGeneric;
                    break;

                default:
                    throw new NotImplementedException("Not implemented type: " + result.App.HostingType);
                }

                AppListEntry entry = new AppListEntry
                {
                    Id             = result.App.Id.ToString(),
                    Name           = result.App.Name,
                    GroupsAssigned = result.AssignedGroupCount,
                    HostingType    = hostingType,
                };

                reply.Apps.Add(entry);
            }

            return(reply);
        }
예제 #18
0
        public static async Task SendTileNotificationAsync(string appName, string subject, string body)
        {
            // Construct the tile content
            TileContent content = GenerateTileContent(appName, subject, body);

            AppListEntry entry   = (await Package.Current.GetAppListEntriesAsync())[0];
            bool         isPined = await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry);

            if (!isPined)
            {
                await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);
            }

            TileNotification notification = new TileNotification(content.GetXml());

            TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);
        }
예제 #19
0
        public static Image GetImageFromEntry(AppListEntry appListEntry)
        {
            BitmapImage logo       = new BitmapImage();
            var         logoStream = appListEntry.DisplayInfo.GetLogo(new Size(50, 50));
            Task <IRandomAccessStreamWithContentType> logoStreamTask = logoStream.OpenReadAsync().AsTask();

            logoStreamTask.Wait();
            IRandomAccessStreamWithContentType logoStreamResult = logoStreamTask.Result;

            logo.SetSource(logoStreamResult);

            Image image = new Image();

            image.Source = logo;

            return(image);
        }
        //pin primary tile to Start if system can do it or primary tile existing
        private async void PinFirstTile()
        {
            // Get your own app list entry
            AppListEntry entry = (await Package.Current.GetAppListEntriesAsync())[0];
            // Check if Start supports your app
            bool isSupported = StartScreenManager.GetDefault().SupportsAppListEntry(entry);
            // Check if your app is currently pinned
            bool isPinned = await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry);

            if (isPinned)
            {
                await GoToLanding();
            }

            // If tile isn't pinned and app can do it - send request to user
            if (isSupported)
            {
                // And pin it to Start
                var tileState = await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);

                if (tileState)
                {
                    DisplayResult.Text = "Плитка успешно закреплена в меню Пуск";
                    await Task.Delay(1900);

                    Application.Current.Exit();
                }
                //возможно этот блок можна убрать:
                else
                {
                    DisplayResult.Text = "Пожалуйста, закрепите плитку в меню Пуск";
                    await Task.Delay(2300);
                    await GoToLanding();
                }
            }
            // Send mesage if app can't pin tile to Start (and maybe if user has rejected request)
            else
            {
                //will have to testing:
                DisplayResult.Text = "Пожалуйста, закрепите плитку в меню Пуск";
                await GoToLanding();
            }
        }
예제 #21
0
        private async void SetupControl()
        {
            IReadOnlyList <AppListEntry> appListEntry = await deployedPackage.GetAppListEntriesAsync();

            if (appListEntry.Count > 0)
            {
                AppListEntry firstEntry = appListEntry.First();
                var          filestream = await(firstEntry.DisplayInfo.GetLogo(new Windows.Foundation.Size(1, 1))).OpenReadAsync();
                BitmapImage  logo       = new BitmapImage();
                await logo.SetSourceAsync(filestream);

                PackageLogo.Source = logo;
                PackageName.Text   = firstEntry.DisplayInfo.DisplayName;
            }
            else
            {
                PackageName.Text = deployedPackage.Id.FullName;
            }

            ProgressBar.IsIndeterminate = true;
        }
예제 #22
0
        private async void PinButton_Click(object sender, RoutedEventArgs e)
        {
            // Get your own app list entry
            AppListEntry entry     = (await Package.Current.GetAppListEntriesAsync())[0];
            bool         isPinned1 = await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry);

            // And pin it to Start
            bool isPinned = await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);

            if (isPinned1 == true)
            {
                PopupNotice popupNotice = new PopupNotice("应用已固定在开始菜单");
                popupNotice.ShowAPopup();
            }
            else
            {
                if (isPinned == true)
                {
                    PopupNotice popupNotice = new PopupNotice("固定成功");
                    popupNotice.ShowAPopup();
                }
            }
        }
예제 #23
0
        public async void CheckAppPresence(Action notFoundCallback, bool launch = false)
        {
            AppListEntry launcher = null;

            Windows.ApplicationModel.Package pack = new PackageManager().FindPackageForUser("", PackageName);
            if (pack != null)
            {
                launcher = (await pack.GetAppListEntriesAsync()).FirstOrDefault(a => a.DisplayInfo.DisplayName == AppName);
            }

            if (launcher == null)
            {
                notFoundCallback?.Invoke();
            }
            else
            {
                IsActive = true;

                if (launch)
                {
                    await launcher.LaunchAsync();
                }
            }
        }
예제 #24
0
        public static async Task <PinResult> PinSpecificAppToTaskBarAsync(AppListEntry appListEntry)
        {
            var resultPinResult = PinResult.UnsupportedOs;

            if (!ApiInformation.IsTypePresent("Windows.UI.Shell.TaskbarManager"))
            {
                return(resultPinResult);
            }

            if (TaskbarManager.GetDefault().IsSupported)
            {
                if (TaskbarManager.GetDefault().IsPinningAllowed)
                {
                    if (await TaskbarManager.GetDefault().IsAppListEntryPinnedAsync(appListEntry))
                    {
                        resultPinResult = PinResult.PinAlreadyPresent;
                    }
                    else
                    {
                        var result = await TaskbarManager.GetDefault().RequestPinAppListEntryAsync(appListEntry);

                        resultPinResult = result ? PinResult.PinPresent : PinResult.PinOperationFailed;
                    }
                }
                else
                {
                    resultPinResult = PinResult.PinNotAllowed;
                }
            }
            else
            {
                resultPinResult = PinResult.UnsupportedDevice;
            }

            return(resultPinResult);
        }
        public override async void FetchInfosAsync()
        {
            string appUserModelId = Data.AppUserModelId;
            string path           = string.Empty;

            if (string.IsNullOrEmpty(Data.AppUserModelId) ||
                string.IsNullOrWhiteSpace(Data.AppUserModelId))
            {
                await Task.Run(() =>
                {
                    appUserModelId = GetAppUserModelIdForProcess();
                });
            }

            try
            {
                var pm       = new PackageManager();
                var packages = pm.FindPackagesForUser(string.Empty);

                async Task <AppListEntry> GetAppListEntry()
                {
                    foreach (var package in packages)
                    {
                        var result = await package.GetAppListEntriesAsync();

                        for (int i = 0; i < result.Count; i++)
                        {
                            var app = result[i];

                            if (app.AppUserModelId == appUserModelId)
                            {
                                path            = package.InstalledLocation.Path;
                                currentAppIndex = i;
                                return(app);
                            }
                        }
                    }

                    return(null);
                }

                sourceApp = await GetAppListEntry();
            }
            catch { }

            if (sourceApp == null)
            {
                return;
            }

            try
            {
                DisplayName = sourceApp.DisplayInfo.DisplayName;
            }
            catch { }

            await Task.Run(() =>
            {
                string logoPath = string.Empty;
                try
                {
                    logoPath = GetRefinedLogoPath(path);
                }
                catch { }

                if (File.Exists(logoPath))
                {
                    MemoryStream memoryStream = new();
                    byte[] fileBytes          = File.ReadAllBytes(logoPath);
                    memoryStream.Write(fileBytes, 0, fileBytes.Length);
                    memoryStream.Seek(0, SeekOrigin.Begin);

                    LogoStream = memoryStream;
                }
            });

            InfoFetched?.Invoke(this, null);
        }
예제 #26
0
 internal static async Task PinToStart()
 {
     AppListEntry entry    = (await Package.Current.GetAppListEntriesAsync())[0];
     bool         isPinned = await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);
 }
예제 #27
0
 public static async void StartApp(AppListEntry appListEntry)
 {
     await appListEntry.LaunchAsync();
 }
예제 #28
0
        internal static async Task <AppListEntryEx <T> > CreateInstanceAsync(PackageEx package, AppListEntry appListEntry, Func <Stream, string, T> stream2Logo)
        {
            var entry = new AppListEntryEx <T>(package, appListEntry);
            await entry.InitializeAsync(stream2Logo);

            return(entry);
        }
예제 #29
0
 private AppListEntryEx(PackageEx package, AppListEntry appListEntry)
 {
     Package           = package;
     AppUserModelId    = appListEntry.AppUserModelId;
     this.appListEntry = appListEntry;
 }
예제 #30
0
        private static async Task <bool> IsPinToStartMenuSupported()
        {
            AppListEntry entry = (await Package.Current.GetAppListEntriesAsync())[0];

            return(StartScreenManager.GetDefault().SupportsAppListEntry(entry));
        }