()
| 41 | |
| 42 | |
| 43 | def patch_drive_window() -> None: |
| 44 | drive_window = next((path for path in DRIVE_WINDOW_CANDIDATES if path.exists()), None) |
| 45 | if drive_window is None: |
| 46 | fail("Unable to find DriveWindow.tsx in current WebClients layout") |
| 47 | |
| 48 | content = drive_window.read_text(encoding="utf-8") |
| 49 | if "protondrive-linux-drawer-app-button:linux-icon" in content: |
| 50 | print(" ⚠ Linux drawer entry already present - skipping") |
| 51 | else: |
| 52 | if "import { c } from 'ttag';" not in content: |
| 53 | content = replace_once( |
| 54 | content, |
| 55 | "import { useLocation } from 'react-router-dom-v5-compat';\n\n", |
| 56 | "import { useLocation } from 'react-router-dom-v5-compat';\n\nimport { c } from 'ttag';\n\n", |
| 57 | "ttag import anchor", |
| 58 | ) |
| 59 | |
| 60 | if " DrawerAppButton,\n" not in content: |
| 61 | content = replace_once( |
| 62 | content, |
| 63 | " ContactDrawerAppButton,\n", |
| 64 | " ContactDrawerAppButton,\n DrawerAppButton,\n", |
| 65 | "DrawerAppButton import anchor", |
| 66 | ) |
| 67 | |
| 68 | if " Icon,\n" not in content: |
| 69 | content = replace_once( |
| 70 | content, |
| 71 | " DrawerVisibilityButton,\n", |
| 72 | " DrawerVisibilityButton,\n Icon,\n", |
| 73 | "Icon import anchor", |
| 74 | ) |
| 75 | |
| 76 | content = replace_once( |
| 77 | content, |
| 78 | " const { appInView, showDrawerSidebar } = useDrawer();", |
| 79 | " const { appInView, showDrawerSidebar, toggleDrawerApp } = useDrawer();", |
| 80 | "useDrawer destructuring", |
| 81 | ) |
| 82 | |
| 83 | linux_button = """ <DrawerAppButton |
| 84 | key="toggle-protondrive-linux-drawer-app-button" |
| 85 | tooltipText={c('Title').t`Proton Drive Linux`} |
| 86 | data-testid="protondrive-linux-drawer-app-button:linux-icon" |
| 87 | buttonContent={<Icon name="brand-linux" size={5} />} |
| 88 | onClick={() => toggleDrawerApp({ app: DRAWER_NATIVE_APPS.QUICK_SETTINGS })()} |
| 89 | alt={c('Action').t`Toggle Proton Drive Linux options`} |
| 90 | aria-controls="drawer-app-protondrive-linux" |
| 91 | aria-expanded={isAppInView(DRAWER_NATIVE_APPS.QUICK_SETTINGS, appInView)} |
| 92 | />, |
| 93 | """ |
| 94 | # Prepend-only: the Linux entry is inserted at the head of the |
| 95 | # drawerSidebarButtons array. Upstream entries that follow it — |
| 96 | # ContactDrawerAppButton, CalendarDrawerAppButton, ReferralAppButton — |
| 97 | # keep their relative order and are never disturbed by this patch. |
| 98 | content = replace_once( |
| 99 | content, |
| 100 | " const drawerSidebarButtons = [\n", |
no test coverage detected