Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.4</string>
<string>1.0.5</string>
<key>CFBundleVersion</key>
<string>17</string>
<string>18</string>
<key>GlossSafariExtensionAvailable</key>
<true/>
<key>CFBundleDocumentTypes</key>
Expand Down
15 changes: 14 additions & 1 deletion Sources/Gloss/BrowserExtensionFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ enum BrowserExtensionFiles {

if fileManager.fileExists(atPath: destination.path) {
let marker = destination.appendingPathComponent(markerName)
guard fileManager.fileExists(atPath: marker.path) else {
let isManaged = fileManager.fileExists(atPath: marker.path)
guard try isManaged || isRecognizableLegacyCopy(source: source, destination: destination)
else {
throw BrowserExtensionError.unmanagedDestination(destination.path)
}
}
Expand Down Expand Up @@ -73,6 +75,17 @@ enum BrowserExtensionFiles {
return destination
}

static func isRecognizableLegacyCopy(source: URL, destination: URL) throws -> Bool {
let sourceFiles = try relativeFiles(in: source).filter { $0 != markerName }
let destinationFiles = try relativeFiles(in: destination).filter { $0 != markerName }
guard sourceFiles == destinationFiles else { return false }

return FileManager.default.contentsEqual(
atPath: source.appendingPathComponent("manifest.json").path,
andPath: destination.appendingPathComponent("manifest.json").path
)
}

static func synchronizeManagedCopy(source: URL, destination: URL) throws {
let fileManager = FileManager.default
let sourceFiles = try relativeFiles(in: source)
Expand Down
42 changes: 42 additions & 0 deletions Tests/GlossAppTests/BrowserExtensionFilesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,48 @@ import XCTest
@testable import Gloss

final class BrowserExtensionFilesTests: XCTestCase {
func testRecognizesUnmarkedBundledCopyForMigration() throws {
let root = FileManager.default.temporaryDirectory
.appendingPathComponent("gloss-extension-migration-\(UUID().uuidString)", isDirectory: true)
let source = root.appendingPathComponent("source", isDirectory: true)
let destination = root.appendingPathComponent("destination", isDirectory: true)
defer { try? FileManager.default.removeItem(at: root) }

try FileManager.default.createDirectory(at: source, withIntermediateDirectories: true)
try FileManager.default.createDirectory(at: destination, withIntermediateDirectories: true)
let manifest = Data(#"{"name":"Gloss","version":"1.0.0"}"#.utf8)
try manifest.write(to: source.appendingPathComponent("manifest.json"))
try manifest.write(to: destination.appendingPathComponent("manifest.json"))
try Data("new".utf8).write(to: source.appendingPathComponent("background.js"))
try Data("old".utf8).write(to: destination.appendingPathComponent("background.js"))

XCTAssertTrue(
try BrowserExtensionFiles.isRecognizableLegacyCopy(
source: source,
destination: destination
)
)

try Data(#"{"name":"Other","version":"1.0.0"}"#.utf8).write(
to: destination.appendingPathComponent("manifest.json")
)
XCTAssertFalse(
try BrowserExtensionFiles.isRecognizableLegacyCopy(
source: source,
destination: destination
)
)

try manifest.write(to: destination.appendingPathComponent("manifest.json"))
try Data("foreign".utf8).write(to: destination.appendingPathComponent("extra.js"))
XCTAssertFalse(
try BrowserExtensionFiles.isRecognizableLegacyCopy(
source: source,
destination: destination
)
)
}

func testSynchronizeManagedCopyUpdatesFilesWithoutReplacingDirectory() throws {
let root = FileManager.default.temporaryDirectory
.appendingPathComponent("gloss-extension-sync-\(UUID().uuidString)", isDirectory: true)
Expand Down
11 changes: 11 additions & 0 deletions docs/release-notes/v1.0.5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Gloss 1.0.5

Gloss 1.0.5 fixes browser extension setup for existing installations.

## Browser extension

- Migrates recognizable legacy extension directories that predate the Gloss management marker.
- Preserves overwrite protection for unrelated or modified extension directories.
- Restores the **Show Extension** action without requiring users to delete or reinstall the extension manually.

Gloss 1.0.5 requires macOS 14 or newer.
Loading