Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
leetcode-mafia committed Mar 26, 2023
0 parents commit e3b5b09
Show file tree
Hide file tree
Showing 51 changed files with 4,222 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
xcuserdata/
19 changes: 19 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
1,035 changes: 1,035 additions & 0 deletions Cheetah.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
78 changes: 78 additions & 0 deletions Cheetah.xcodeproj/xcshareddata/xcschemes/Cheetah.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "37AE7A6E29A5A8B300C45FF6"
BuildableName = "Cheetah.app"
BlueprintName = "Cheetah"
ReferencedContainer = "container:Cheetah.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "37AE7A6E29A5A8B300C45FF6"
BuildableName = "Cheetah.app"
BlueprintName = "Cheetah"
ReferencedContainer = "container:Cheetah.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "37AE7A6E29A5A8B300C45FF6"
BuildableName = "Cheetah.app"
BlueprintName = "Cheetah"
ReferencedContainer = "container:Cheetah.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
11 changes: 11 additions & 0 deletions Cheetah/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
58 changes: 58 additions & 0 deletions Cheetah/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Cheetah/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
101 changes: 101 additions & 0 deletions Cheetah/BrowserExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import CheetahIPC

class BrowserExtensionState: JSONHandler<BrowserExtensionMessage> {
@Published var mode: String?
@Published var files = [String: String]()
@Published var logs = [String: String]()

var navigationStart = 0
var lastUpdate: Date?

public init() {
super.init(respondsTo: IPCMessage.browserExtensionMessage)

handler = {
guard let message = $0 else {
return nil
}

if message.navigationStart > self.navigationStart {
self.navigationStart = message.navigationStart
self.files.removeAll()
self.logs.removeAll()
}

let newMode = message.mode
if newMode != self.mode {
self.mode = newMode
self.files.removeAll()
self.logs.removeAll()
}

for (name, content) in message.files {
self.files[name] = content
}
for (name, content) in message.logs {
self.logs[name] = content
}

if self.lastUpdate == nil {
print("BrowserExtensionState: first message was received!")
}

self.lastUpdate = Date.now
return nil
}
}

var codeDescription: String {
if files.isEmpty {
return "N/A"
} else {
return files
.map { name, content in "[\(name)]\n\(content)" }
.joined(separator: "\n\n")
}
}

var logsDescription: String {
if logs.isEmpty {
return "N/A"
} else {
return logs
.map { name, content in
let recentLines = content.split(separator: "\n").suffix(20).joined(separator: "\n")
return "[\(name)]\n\(recentLines)"
}
.joined(separator: "\n\n")
}
}
}

struct NativeMessagingManifest: Codable {
enum `Type`: String, Codable {
case stdio
}

let name: String
let description: String
let path: String
let type: `Type`
let allowedExtensions: [String]
}

func installNativeMessagingManifest() throws -> Bool {
let manifest = NativeMessagingManifest(
name: "cheetah",
description: "Cheetah Extension",
path: Bundle.main.path(forAuxiliaryExecutable: "ExtensionHelper")!,
type: .stdio,
allowedExtensions: ["cheetah@phrack.org"])

let path = FileManager.default.homeDirectoryForCurrentUser.appending(path: "Library/Application Support/Mozilla/NativeMessagingHosts/cheetah.json").absoluteURL.path

print("Installing native messaging manifest at \(path)")

let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase

let contents = try encoder.encode(manifest)
return FileManager.default.createFile(atPath: path, contents: contents)
}
5 changes: 5 additions & 0 deletions Cheetah/Cheetah.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
Loading

0 comments on commit e3b5b09

Please sign in to comment.