Skip to content

Commit

Permalink
Return of popups so that we can open iOS container app via url in safari
Browse files Browse the repository at this point in the history
  • Loading branch information
workwithnano committed Dec 17, 2023
1 parent 022c283 commit 171fdb8
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Kagi Search iOS copy-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.kagimacOS.Kagi-Search</string>
<string>com.kagi.searchExtensionContainer</string>
<key>CFBundleURLSchemes</key>
<array>
<string>kagisearch</string>
Expand Down
2 changes: 1 addition & 1 deletion MainConfig.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MARKETING_VERSION = 2.0.0
CURRENT_PROJECT_VERSION = 11 // this needs to be increased with each version change as well (not set to 1 when version is updated)
CURRENT_PROJECT_VERSION = 12 // this needs to be increased with each version change as well (not set to 1 when version is updated)
5 changes: 4 additions & 1 deletion Shared (Extension)/Resources/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
},

"action": {
"default_popup": "popup.html",
"default_icon": {
"128": "images/ToolbarItemIcon.png"
}
},

"permissions": [
"nativeMessaging",
"webNavigation"
"webNavigation",
"activeTab",
"storage"
]
}
56 changes: 48 additions & 8 deletions Shared (Extension)/Resources/popup.css

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions Shared (Extension)/Resources/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
<!-- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">-->
<!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src *; img-src 'self' data:">-->
<link rel="stylesheet" href="popup.css">
<script type="module" src="popup.js"></script>
<script type="module" src="popup.js" defer></script>
</head>
<body>
<p>The Kagi extension is enabled for this site. <a href="#" id="open-app">Open the Kagi app</a> to update your extension settings.</p>
<p><a href="javascript:;" id="request-permissions">Request permissions</a></p>

<p>
<b>Current permissions returned by the API:</b>
<span id="permissions"></span>
</p>
<div id="con" style="font-family: Lufga">
<div id="content">
<p>The Kagi extension is enabled for <span id="currentHost">this site</span>.</p>
<p><a href="#" id="open-app">Open the Kagi app</a> to update your extension settings.</p>
</div>
</div>
</body>
</html>
126 changes: 103 additions & 23 deletions Shared (Extension)/Resources/popup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
const extensionId = "com.kagi.Kagi-Search-for-Safari.Extension (TFVG979488)";
document.getElementById("open-app").onclick = function() {
browser.runtime.sendNativeMessage(extensionId, {"type": "openApp"}, function(response) {
window.close();
});
}



const googleUrls = {
"google.com.au": "q",
"google.md": "q",
Expand Down Expand Up @@ -202,20 +193,109 @@ const googleUrls = {
"google.com.eg": "q",
"google.com.ng": "q"
};
const yandexUrls = {
"yandex.ru": "text",
"yandex.org": "text",
"yandex.net": "text",
"yandex.net.ru": "text",
"yandex.com.ru": "text",
"yandex.ua": "text",
"yandex.com.ua": "text",
"yandex.by": "text",
"yandex.eu": "text",
"yandex.ee": "text",
"yandex.lt": "text",
"yandex.lv": "text",
"yandex.md": "text",
"yandex.uz": "text",
"yandex.mx": "text",
"yandex.do": "text",
"yandex.tm": "text",
"yandex.de": "text",
"yandex.ie": "text",
"yandex.in": "text",
"yandex.qa": "text",
"yandex.so": "text",
"yandex.nu": "text",
"yandex.tj": "text",
"yandex.dk": "text",
"yandex.es": "text",
"yandex.pt": "text",
"yandex.pl": "text",
"yandex.lu": "text",
"yandex.it": "text",
"yandex.az": "text",
"yandex.ro": "text",
"yandex.rs": "text",
"yandex.sk": "text",
"yandex.no": "text",
"ya.ru": "text",
"yandex.com": "text",
"yandex.asia": "text",
"yandex.mobi": "text"
};
const ddgUrls = {
"duckduckgo.com": "q",
"duckduckgo.pl": "q",
"duckduckgo.jp": "q",
"duckduckgo.co": "q",
"duckduckco.de": "q",
"duckduckgo.ca": "q",
"duckduckgo.co.uk": "q",
"duckduckgo.com.mx": "q",
"duckduckgo.com.tw": "q",
"duckduckgo.dk": "q",
"duckduckgo.in": "q",
"duckduckgo.ke": "q",
"duckduckgo.mx": "q",
"duckduckgo.nl": "q",
"duckduckgo.org": "q",
"duckduckgo.sg": "q",
"duckduckgo.uk": "q",
"duckgo.com": "q",
"ddg.co": "q",
"ddg.gg": "q",
"duck.co": "q",
"duck.com": "q"
};
const bingUrls = {
"bing.com": "q"
};
const baiduUrls = {
"baidu.com": "wd",
"m.baidu.com": "word"
};
const sogouUrls = {
"sogou.com": "query",
"m.sogou.com": "keyword",
"m.so.com": "q",
"so.com": "q"
};
const ecosiaUrls = {
"ecosia.org": "q"
};
const yahooUrls = {
"search.yahoo.com": "p"
};
const engineHosts = Object.keys(Object.assign({}, googleUrls, yandexUrls, ddgUrls, bingUrls, baiduUrls, sogouUrls, ecosiaUrls, yahooUrls));

document.getElementById("request-permissions").onclick = function() {
var permissionsToRequest = {
permissions: ["webNavigation"],
origins: Object.keys(googleUrls).map((host) => ("*://" + host + "/*"))
const extensionId = "com.kagi.Kagi-Search-for-Safari.Extension (TFVG979488)";
const userAgent = window.navigator.userAgent,
platform = window.navigator?.userAgentData?.platform || window.navigator.platform,
macosPlatforms = ['macOS', 'Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
iosPlatforms = ['iPhone', 'iPad', 'iPod'];
document.getElementById("open-app").onclick = function() {
if (macosPlatforms.indexOf(platform) !== -1) {
browser.runtime.sendNativeMessage(extensionId, {"type": "openApp"}, function(response) {
window.close();
});
} else if (iosPlatforms.indexOf(platform) !== -1) {
window.open("kagisearch://")
}
browser.permissions.request(permissionsToRequest);
}

function updatePermissions() {
browser.permissions.getAll()
.then((permissions) => {
document.getElementById('permissions').innerText = permissions.permissions.join(', ');
});
}

updatePermissions();
document.addEventListener("DOMContentLoaded", (event) => {
browser.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
let url = new URL(tabs[0].url);
document.getElementById("currentHost").innerText = url.hostname;
});
});

0 comments on commit 171fdb8

Please sign in to comment.