Finally install extension on local folder
This commit is contained in:
1 parent
809474eac4
commit
54a3e81109
3 files changed
+34
-3
No files matched your search
@@ -26,8 +26,7 @@ public sealed class ExtensionManager
|
||||
private readonly Dictionary<string, ExtensionUiMetadata> _uiMetadata;
|
||||
private readonly HashSet<string> _pinnedIds;
|
||||
|
||||
public static string ExtensionsRootPath => Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "FoxBrowser", "Extensions");
|
||||
public static string ExtensionsRootPath => WebView2EnvironmentFactory.PortableExtensionsPath;
|
||||
|
||||
public ExtensionManager(CoreWebView2Profile profile)
|
||||
{
|
||||
|
||||
@@ -13,6 +13,8 @@ public sealed class WebView2EnvironmentFactory
|
||||
private const string ProductFolderName = "FoxBrowser";
|
||||
private const string ProfileFolderName = "Profile";
|
||||
private const string LegacyProfileFolderName = "WebView2";
|
||||
private const string ExtensionsFolderName = "Extensions";
|
||||
private const string LegacyExtensionsFolderName = "Extensions";
|
||||
private const string ProtectedFolderNoticeMarker = "portable-profile-fallback-notified";
|
||||
|
||||
private readonly string _applicationDataRoot = Path.Combine(
|
||||
@@ -21,6 +23,9 @@ public sealed class WebView2EnvironmentFactory
|
||||
|
||||
public string PortableProfilePath => Path.Combine(AppContext.BaseDirectory, ProfileFolderName);
|
||||
public string LegacyProfilePath => Path.Combine(_applicationDataRoot, LegacyProfileFolderName);
|
||||
public static string PortableExtensionsPath => Path.Combine(AppContext.BaseDirectory, ExtensionsFolderName);
|
||||
public static string LegacyExtensionsPath => Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ProductFolderName, LegacyExtensionsFolderName);
|
||||
public bool UsingLegacyProfile { get; private set; }
|
||||
public string? MigrationError { get; private set; }
|
||||
|
||||
@@ -88,6 +93,7 @@ public sealed class WebView2EnvironmentFactory
|
||||
}
|
||||
}
|
||||
|
||||
MigrateLegacyExtensionsIfNeeded();
|
||||
return PortableProfilePath;
|
||||
}
|
||||
|
||||
@@ -162,6 +168,32 @@ public sealed class WebView2EnvironmentFactory
|
||||
}
|
||||
}
|
||||
|
||||
private static void MigrateLegacyExtensionsIfNeeded()
|
||||
{
|
||||
if (!Directory.Exists(LegacyExtensionsPath) || !Directory.EnumerateFileSystemEntries(LegacyExtensionsPath).Any())
|
||||
return;
|
||||
|
||||
if (Directory.Exists(PortableExtensionsPath) && Directory.EnumerateFileSystemEntries(PortableExtensionsPath).Any())
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
CopyDirectoryContents(LegacyExtensionsPath, PortableExtensionsPath);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
// Keep the legacy folder intact. A later startup can retry the migration.
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
// Keep the legacy folder intact and let the normal profile startup continue.
|
||||
}
|
||||
catch (SecurityException)
|
||||
{
|
||||
// Keep the legacy folder intact and let the normal profile startup continue.
|
||||
}
|
||||
}
|
||||
|
||||
private static void TryDeleteDirectory(string path)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<TextBlock DockPanel.Dock="Top" Text="Chrome-сумісні unpacked extensions" FontSize="16" FontWeight="SemiBold" Margin="0,0,0,4" />
|
||||
<TextBlock DockPanel.Dock="Top" Text="Кнопка «Налаштування» відкриває сторінку, вказану в manifest.json: options_ui.page або options_page." Foreground="#AEB4BE" TextWrapping="Wrap" Margin="0,0,0,4" />
|
||||
<TextBlock DockPanel.Dock="Top" Text="WebView2 не підтримує Chrome-only встановлення кнопкою Install. Завантаж ZIP/CRX, імпортуй його тут — FoxBrowser сам розпакує файл у папку профілю та підключить extension." Foreground="#FFCC66" TextWrapping="Wrap" Margin="0,0,0,4" />
|
||||
<TextBlock DockPanel.Dock="Top" Text="Імпортовані файли зберігаються у %LOCALAPPDATA%\FoxBrowser\Extensions, а реєстрація extension — у профілі WebView2. Кнопка «Папка розширень» відкриває це місце." Foreground="#AEB4BE" TextWrapping="Wrap" Margin="0,0,0,10" />
|
||||
<TextBlock DockPanel.Dock="Top" Text="Імпортовані файли зберігаються у папці Extensions поруч із FoxBrowser.exe, а реєстрація extension — у portable-профілі WebView2. Старі extension із %LOCALAPPDATA%\FoxBrowser\Extensions переносяться туди автоматично один раз." Foreground="#AEB4BE" TextWrapping="Wrap" Margin="0,0,0,10" />
|
||||
<TextBlock x:Name="ExtensionsStatus" DockPanel.Dock="Top" Foreground="#FFCC66" TextWrapping="Wrap" Margin="0,0,0,8" />
|
||||
<Grid>
|
||||
<ListBox x:Name="ExtensionList" Background="#202328" BorderBrush="#454C57" Foreground="#F2F4F7">
|
||||
|
||||
Reference in new issue
Block a user