Skip to content

Commit

Permalink
fix: open omni failed in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
panjiangyi committed Jan 9, 2024
1 parent bc330ce commit 9e95543
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
19 changes: 13 additions & 6 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const clearActions = () => {
const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
let muteaction = {title:"Mute tab", desc:"Mute the current tab", type:"action", action:"mute", emoji:true, emojiChar:"🔇", keycheck:true, keys:['⌥','⇧', 'M']};
let pinaction = {title:"Pin tab", desc:"Pin the current tab", type:"action", action:"pin", emoji:true, emojiChar:"📌", keycheck:true, keys:['⌥','⇧', 'P']};
if (response.mutedInfo.muted) {
if (response?.mutedInfo?.muted) {
muteaction = {title:"Unmute tab", desc:"Unmute the current tab", type:"action", action:"unmute", emoji:true, emojiChar:"🔈", keycheck:true, keys:['⌥','⇧', 'M']};
}
if (response.pinned) {
if (response?.pinned) {
pinaction = {title:"Unpin tab", desc:"Unpin the current tab", type:"action", action:"unpin", emoji:true, emojiChar:"📌", keycheck:true, keys:['⌥','⇧', 'P']};
}
actions = [
Expand Down Expand Up @@ -475,10 +475,17 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
}
break;
case "search":
chrome.search.query(
{text:message.query,disposition:message.disposition}
)
break;
var query = () =>
chrome.search.query({
text: message.query,
disposition: message.disposition,
});
if (message.__inNewTab__) {
setTimeout(query, 125);
} else {
query();
}
break;
case "restore-new-tab":
restoreNewTab();
break;
Expand Down
8 changes: 5 additions & 3 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ $(document).ready(() => {
// Request actions from the background
chrome.runtime.sendMessage({request:"get-actions"}, (response) => {
actions = response.actions;
populateOmni()
});

// New tab page workaround
if (window.location.href == "chrome-extension://mpanekjjajcabgnlbabmopeenljeoggm/newtab.html") {
if (window.__inNewTab__) {
isOpen = true;
$("#omni-extension").removeClass("omni-closing");
window.setTimeout(() => {
Expand Down Expand Up @@ -131,7 +132,7 @@ $(document).ready(() => {

// Close the omni
function closeOmni() {
if (window.location.href == "chrome-extension://mpanekjjajcabgnlbabmopeenljeoggm/newtab.html") {
if (window.__inNewTab__) {
chrome.runtime.sendMessage({request:"restore-new-tab"});
} else {
isOpen = false;
Expand Down Expand Up @@ -304,7 +305,8 @@ $(document).ready(() => {
window.open($(".omni-item-active").attr("data-url"), "_self");
}
} else {
chrome.runtime.sendMessage({request:action.action, disposition:(e.altKey||e.metaKey)? "NEW_TAB":"CURRENT_TAB", tab:action, query:$(".omni-extension input").val()});
var disposition = window.__inNewTab__ ? "CURRENT_TAB" : e.altKey || e.metaKey ? "NEW_TAB" : "CURRENT_TAB";
chrome.runtime.sendMessage({request:action.action,__inNewTab__:window.__inNewTab__, disposition:disposition, tab:action, query:$(".omni-extension input").val()});
switch (action.action) {
case "bookmark":
if (e.ctrlKey || e.metaKey) {
Expand Down
2 changes: 1 addition & 1 deletion src/newtab.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</style>
</head>
<body>

<script src="newtab.js"></script>
<script src="jquery.js"></script>
<script src="content.js"></script>
<script src="virtualized-list.min.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/newtab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.__inNewTab__ = true;

0 comments on commit 9e95543

Please sign in to comment.