Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ A set of [NIC](https://theos.dev/docs/nic) templates
- CLI Tool (Objective-C and Swift)
- Tweak (bare or with a simple preference switch)
- XPC service
- Safari extension


Templates planned to be included:
Expand Down
12 changes: 12 additions & 0 deletions ios/safari_extension/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TARGET := iphone:clang:latest:15.0
INSTALL_TARGET_PROCESSES = @@PROJECTNAME@@

include @@THEOS@@/makefiles/common.mk

APPEX_NAME = @@PROJECTNAME@@

@@PROJECTNAME@@_FILES = SafariWebExtensionHandler.swift
@@PROJECTNAME@@_INSTALL_PATH = /Applications/@@PARENTPROJECTNAME@@.app/PlugIns
@@PROJECTNAME@@_FRAMEWORKS = SafariServices

include $(THEOS_MAKE_PATH)/appex.mk
3 changes: 3 additions & 0 deletions ios/safari_extension/NIC/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name "iphone/safari_extension"
constrain "control" to package
constrain "theos" to link_theos
5 changes: 5 additions & 0 deletions ios/safari_extension/NIC/control.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NIC->variable("PARENTPROJECTNAME") = "";

while(NIC->variable("PARENTPROJECTNAME") eq "") {
NIC->variable("PARENTPROJECTNAME") = NIC->prompt("PROJ", "Name of parent project (required)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth specifying that by parent project name we mean an application name

}
33 changes: 33 additions & 0 deletions ios/safari_extension/Resources/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>@@PROJECTNAME@@</string>
<key>CFBundleExecutable</key>
<string>@@PROJECTNAME@@</string>
<key>CFBundleIdentifier</key>
<string>com.@@USER@@.@@PARENTPROJECTNAME@@.app.@@PROJECTNAME@@</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>@@PROJECTNAME@@</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>MinimumOSVersion</key>
<string>15.0</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPrincipalClass</key>
<string>SafariWebExtensionHandler</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.Safari.web-extension</string>
</dict>
</dict>
</plist>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions ios/safari_extension/Resources/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"manifest_version": 2,
"default_locale": "en",

"name": "@@PROJECTNAME@@",
"description": "An awesome safari extension!",
"version": "1.0",

"icons": {
"48": "images/icon-48.png",
"96": "images/icon-96.png",
"128": "images/icon-128.png",
"256": "images/icon-256.png",
"512": "images/icon-512.png"
},

"browser_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/toolbar-icon-16.png",
"19": "images/toolbar-icon-19.png",
"32": "images/toolbar-icon-32.png",
"38": "images/toolbar-icon-38.png",
"48": "images/toolbar-icon-48.png",
"72": "images/toolbar-icon-72.png"
}
},

"permissions": [ ]
}
11 changes: 11 additions & 0 deletions ios/safari_extension/Resources/popup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:root {
color-schema: light dark;
}

body {
min-width: 100px;
padding: 10px;

font-family: system-ui;
text-align: center;
}
11 changes: 11 additions & 0 deletions ios/safari_extension/Resources/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="popup.css">
<script type="module" src="popup.js"></script>
</head>
<body>
<h1 id="date"></h1>
</body>
</html>
3 changes: 3 additions & 0 deletions ios/safari_extension/Resources/popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let dateElement = document.getElementById('date');

dateElement.textContent = new Date();
19 changes: 19 additions & 0 deletions ios/safari_extension/SafariWebExtensionHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import SafariServices
import os.log

let SFExtensionMessageKey = "message"

class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {

func beginRequest(with context: NSExtensionContext) {
let item = context.inputItems[0] as! NSExtensionItem
let message = item.userInfo?[SFExtensionMessageKey]
Logger().log("Received message from browser.runtime.sendNativeMessage: \(String(describing: message))")

let response = NSExtensionItem()
response.userInfo = [ SFExtensionMessageKey: [ "Response to": message ] ]

context.completeRequest(returningItems: [response], completionHandler: nil)
}

}
Binary file added iphone_safari_extension.nic.tar
Binary file not shown.