From 643bc02027b17192df202c6031bb6d18cf898944 Mon Sep 17 00:00:00 2001 From: Ryosuke Asano Date: Wed, 1 Nov 2023 00:37:00 +0900 Subject: [PATCH] [FB] PWA | Remove Floorp's modules --- .../ProgressiveWebAppStartMenuUtils.sys.mjs | 62 -------- .../PWA/ProgressiveWebAppWindowUtils.sys.mjs | 142 ------------------ browser/components/moz.build | 2 - 3 files changed, 206 deletions(-) delete mode 100644 browser/components/PWA/ProgressiveWebAppStartMenuUtils.sys.mjs delete mode 100644 browser/components/PWA/ProgressiveWebAppWindowUtils.sys.mjs diff --git a/browser/components/PWA/ProgressiveWebAppStartMenuUtils.sys.mjs b/browser/components/PWA/ProgressiveWebAppStartMenuUtils.sys.mjs deleted file mode 100644 index 89548377..00000000 --- a/browser/components/PWA/ProgressiveWebAppStartMenuUtils.sys.mjs +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -export const EXPORTED_SYMBOLS = ["ProgressiveWebAppStartMenuUtils"]; - -import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; - -var { XPCOMUtils } = ChromeUtils.import('resource://gre/modules/XPCOMUtils.jsm'); -const lazy = {}; - -XPCOMUtils.defineLazyModuleGetters(lazy, { - FileUtils: 'resource://gre/modules/FileUtils.sys.mjs', - PathUtils: 'resource://gre/modules/PathUtils.sys.mjs', -}); - - -export let ProgressiveWebAppStartMenuUtils = { - get browserInstallationDirectory() { - return Services.dirsvc.get("GreD", Ci.nsIFile).path; - }, - - get desktopDirectory() { - return Services.dirsvc.get("Desk", Ci.nsIFile).path; - }, - - get startMenuDirectory() { - return Services.dirsvc.get("Home", Ci.nsIFile).path + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs"; - }, - - get shellService() { - return Cc["@mozilla.org/browser/shell-service;1"].getService(Ci.nsIWindowsShellService); - }, - - async createShortCut(shortcutName, targetPath) { - let shellService = this.shellService; - let winTaskbar = Cc["@mozilla.org/windows-taskbar;1"].getService( - Ci.nsIWinTaskbar - ); - let appdir = Services.dirsvc.get("GreD", Ci.nsIFile); - let exe = appdir.clone(); - const PRIVATE_BROWSING_BINARY = `${AppConstants.MOZ_APP_DISPLAYNAME_DO_NOT_USE.toLowerCase()}.exe` - exe.append(PRIVATE_BROWSING_BINARY); - - if (!targetPath) { - targetPath = this.startMenuDirectory; - } - - await shellService.createShortcut( - exe, - [], - "Floorp Progressive Web App for " + shortcutName, - icon, - 0, - winTaskbar.defaultPrivateGroupId, - "Programs", - "Floorp Progressive Web App.lnk", - Services.dirsvc.get("GreD", Ci.nsIFile), - ); - }, -}; diff --git a/browser/components/PWA/ProgressiveWebAppWindowUtils.sys.mjs b/browser/components/PWA/ProgressiveWebAppWindowUtils.sys.mjs deleted file mode 100644 index eaefef15..00000000 --- a/browser/components/PWA/ProgressiveWebAppWindowUtils.sys.mjs +++ /dev/null @@ -1,142 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; - -var { XPCOMUtils } = ChromeUtils.import('resource://gre/modules/XPCOMUtils.jsm'); - -const lazy = {}; - -XPCOMUtils.defineLazyModuleGetters(lazy, { - NetUtil: 'resource://gre/modules/NetUtil.jsm', - setTimeout: 'resource://gre/modules/Timer.jsm', -}); - -XPCOMUtils.defineLazyServiceGetter(lazy, 'ImgTools', '@mozilla.org/image/tools;1', Ci.imgITools); -XPCOMUtils.defineLazyServiceGetter(lazy, 'WinUIUtils', '@mozilla.org/windows-ui-utils;1', Ci.nsIWindowsUIUtils); -XPCOMUtils.defineLazyServiceGetter(lazy, 'WinTaskbar', '@mozilla.org/windows-taskbar;1', Ci.nsIWinTaskbar); - - -export const EXPORTED_SYMBOLS = ["ProgressiveWebAppWindowUtils"]; - -export let ProgressiveWebAppWindowUtils = { - buildIconList (icons, purpose = 'any') { - let iconList = []; - - for (let icon of icons) { - if (!icon.purpose.split().includes(purpose)) { continue; } - iconList.push(...this.buildIconSizeList(icon)); - } - - iconList.sort((a, b) => (a.size > b.size) ? 1 : -1); - return iconList; - }, - - buildIconSizeList(icon) { - let sizeList = []; - - for (let sizeSpec of icon.sizes.split()) { - const size = sizeSpec === 'any' ? Number.MAX_SAFE_INTEGER : parseInt(sizeSpec); - sizeList.push({ icon, size }); - } - - return sizeList; - }, - - loadImage (uri) { - return new Promise((resolve, reject) => { - let channel = this.createChannel(uri); - - lazy.ImgTools.decodeImageFromChannelAsync( - uri, - channel, - (container, status) => { - if (Components.isSuccessCode(status)) { - resolve({ - type: channel.contentType, - container, - }); - } else { - reject(Components.Exception('Failed to load image', status)); - } - }, - null - ); - }); - }, - - createChannel(uri) { - return lazy.NetUtil.newChannel({ - uri, - loadUsingSystemPrincipal: true, - }); - }, - - async getIcon (icons, size) { - if (icons.length === 0) {return null;} - - let icon = this.findIconBySize(icons, size); - - try { - let image = await this.loadImage(Services.io.newURI(icon.icon.src)); - return image.container; - } catch (error) { - console.warn(error + "Use the default icon instead."); - return null; - } - }, - - findIconBySize(icons, size) { - let icon = icons.find(icon => icon.size >= size); - - if (!icon) {icon = icons[icons.length - 1];} - - return icon; - }, - - async setWindowIcons (window, iconSrc) { - - console.log('setWindowIcons', iconSrc); - - let iconList = this.buildIconList([{ - purpose: 'any', - sizes: 'any', - src: iconSrc, // example: document.querySelector('.tab-icon-image[selected="true"]').src - }]); - - let windowIcons = await Promise.all([ - this.getIcon(iconList, lazy.WinUIUtils.systemSmallIconSize), - this.getIcon(iconList, lazy.WinUIUtils.systemLargeIconSize), - ]); - - if (windowIcons[0] && windowIcons[1]) { - this.setWindowIconWithDelay(window, windowIcons[0], windowIcons[1]); - } - }, - - setWindowIconWithDelay(window, smallIcon, largeIcon) { - // There is a small delay here because otherwise `setWindowIcon` may fail - // It shouldn't visually matter because the icon will be set by a shortcut anyway - lazy.setTimeout(() => { - lazy.WinUIUtils.setWindowIcon(window, smallIcon, largeIcon); - }, 100); - }, - - setWindowAttributes(window, id) { - window.document.documentElement.setAttribute('icon', `Floorp-${id}`); - window.document.documentElement.setAttribute('windowclass', `Floorp-${id}`); - window.document.documentElement.setAttribute('windowname', `Floorp-${id}`); - }, - - - applySystemIntegration (window, id, icon) { - this.setWindowAttributes(window, id); - - if (AppConstants.platform === 'win') { - lazy.WinTaskbar.setGroupIdForWindow(window, `mozilla.Floorp-${id}`); - this.setWindowIcons(window, icon); - } - } -} diff --git a/browser/components/moz.build b/browser/components/moz.build index 91586422..448647b5 100644 --- a/browser/components/moz.build +++ b/browser/components/moz.build @@ -20,8 +20,6 @@ EXTRA_JS_MODULES += [ "FloorpStartup.sys.mjs", "PortableUpdate.sys.mjs", "PrivateContainer.sys.mjs", - "PWA/ProgressiveWebAppStartMenuUtils.sys.mjs", - "PWA/ProgressiveWebAppWindowUtils.sys.mjs", "userjsUtils.sys.mjs", "WorkspaceUtils.sys.mjs", ]