mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 02:20:17 +08:00
Move the Electron macOS app into the main repository and ship it with every DeepTutor release. - apps/desktop: Electron shell that installs a signed bundled runtime and hosts the web UI; versioned with the bundled core. - White app icon with the black DeepTutor mark, generated by scripts/make-icon.swift; redesigned start screen and title bar. - Shell copy in en/zh/de/fr/pl/uk, starting in English and following the interface language and theme from DeepTutor Settings, including live changes. - Web UI labels itself "Open DeepTutor MacOS v<version>" inside the app (user-agent marker) and "Open DeepTutor Web v<version>" in a browser. - Sealing refuses a missing or mismatched signing key instead of silently generating a new one. - desktop-release.yml builds, smoke-tests and attaches the DMG to each GitHub Release; Developer ID signing and notarization run when secrets exist. - tests.yml runs the shell checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
3.1 KiB
Swift
71 lines
3.1 KiB
Swift
// Renders assets/icon.icns: the black DeepTutor mark on a white macOS tile.
|
|
// Usage: swift scripts/make-icon.swift <mark.png> <output.icns>
|
|
import AppKit
|
|
|
|
let arguments = CommandLine.arguments
|
|
guard arguments.count == 3, let mark = NSImage(contentsOfFile: arguments[1]) else {
|
|
FileHandle.standardError.write("usage: make-icon.swift <mark.png> <output.icns>\n".data(using: .utf8)!)
|
|
exit(1)
|
|
}
|
|
|
|
// Apple's macOS icon grid: a 824pt tile centred on a 1024pt canvas.
|
|
func render(_ size: Int) -> Data {
|
|
let scale = CGFloat(size) / 1024
|
|
let rep = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: size, pixelsHigh: size,
|
|
bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false,
|
|
colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)!
|
|
NSGraphicsContext.saveGraphicsState()
|
|
NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: rep)
|
|
let context = NSGraphicsContext.current!.cgContext
|
|
context.scaleBy(x: scale, y: scale)
|
|
|
|
let tile = CGRect(x: 100, y: 100, width: 824, height: 824)
|
|
let shape = CGPath(roundedRect: tile, cornerWidth: 185, cornerHeight: 185, transform: nil)
|
|
|
|
context.saveGState()
|
|
context.setShadow(offset: CGSize(width: 0, height: -10), blur: 22,
|
|
color: NSColor(white: 0, alpha: 0.22).cgColor)
|
|
context.addPath(shape)
|
|
context.setFillColor(NSColor.white.cgColor)
|
|
context.fillPath()
|
|
context.restoreGState()
|
|
|
|
// A barely-there top-to-bottom falloff keeps the white tile from looking flat.
|
|
context.saveGState()
|
|
context.addPath(shape)
|
|
context.clip()
|
|
let gradient = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: [
|
|
NSColor(white: 1, alpha: 1).cgColor, NSColor(white: 0.955, alpha: 1).cgColor,
|
|
] as CFArray, locations: [0, 1])!
|
|
context.drawLinearGradient(gradient, start: CGPoint(x: 512, y: tile.maxY),
|
|
end: CGPoint(x: 512, y: tile.minY), options: [])
|
|
context.restoreGState()
|
|
|
|
context.addPath(CGPath(roundedRect: tile.insetBy(dx: 1, dy: 1), cornerWidth: 184, cornerHeight: 184, transform: nil))
|
|
context.setStrokeColor(NSColor(white: 0, alpha: 0.07).cgColor)
|
|
context.setLineWidth(2)
|
|
context.strokePath()
|
|
|
|
// The mark's visual mass sits low in its square, so lift it slightly.
|
|
let side: CGFloat = 470
|
|
mark.draw(in: CGRect(x: 512 - side / 2, y: 512 - side / 2 + 14, width: side, height: side),
|
|
from: .zero, operation: .sourceOver, fraction: 1)
|
|
|
|
NSGraphicsContext.restoreGraphicsState()
|
|
return rep.representation(using: .png, properties: [:])!
|
|
}
|
|
|
|
let iconset = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("DeepTutor-\(getpid()).iconset")
|
|
try FileManager.default.createDirectory(at: iconset, withIntermediateDirectories: true)
|
|
for base in [16, 32, 128, 256, 512] {
|
|
try render(base).write(to: iconset.appendingPathComponent("icon_\(base)x\(base).png"))
|
|
try render(base * 2).write(to: iconset.appendingPathComponent("icon_\(base)x\(base)@2x.png"))
|
|
}
|
|
let task = Process()
|
|
task.executableURL = URL(fileURLWithPath: "/usr/bin/iconutil")
|
|
task.arguments = ["-c", "icns", iconset.path, "-o", arguments[2]]
|
|
try task.run()
|
|
task.waitUntilExit()
|
|
try? FileManager.default.removeItem(at: iconset)
|
|
exit(task.terminationStatus)
|