Skip to content

Commit 426cb8c

Browse files
committed
add edge extension
1 parent 468a167 commit 426cb8c

7 files changed

Lines changed: 316 additions & 13 deletions

File tree

src/edge_extension/background.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const handleRuntimeError = () => {
2+
const error = chrome.runtime.lastError;
3+
if (error) {
4+
throw new Error(error);
5+
}
6+
};
7+
8+
const safeGetTab = async (tabId) => {
9+
const tab = await chrome.tabs.get(parseInt(tabId));
10+
try {
11+
handleRuntimeError();
12+
return tab;
13+
} catch (e){
14+
console.log('safeGetTab', e.message);
15+
}
16+
return undefined;
17+
};
18+
19+
async function tryTabGoBack(tabId) {
20+
return new Promise((resolve, reject) => {
21+
chrome.tabs.goBack(null, () => {
22+
if (chrome.runtime.lastError != undefined) {
23+
resolve(false);
24+
} else {
25+
resolve(true);
26+
}
27+
})
28+
})
29+
}
30+
31+
async function browserGoBack() {
32+
let currentTabId = tabQueue.pop();
33+
console.log(currentTabId);
34+
while (tabQueue.length > 0) {
35+
let lastTabId = tabQueue[tabQueue.length - 1];
36+
if (lastTabId == currentTabId) {
37+
tabQueue.pop();
38+
continue;
39+
}
40+
if (safeGetTab(currentTabId) == undefined) {
41+
tabQueue.pop();
42+
continue;
43+
}
44+
break;
45+
}
46+
if(tabQueue.length>0){
47+
let lastTabId = tabQueue[tabQueue.length - 1];
48+
chrome.tabs.update(lastTabId, { active: true, highlighted: true });
49+
// chrome.windows.update(thisWindowId, { "focused": true });
50+
}
51+
chrome.tabs.remove(currentTabId, function () { });
52+
}
53+
54+
const processCommand = async function (command) {
55+
if (command == "go_back_or_close_tab") {
56+
if (!await tryTabGoBack()) {
57+
browserGoBack();
58+
}
59+
}
60+
};
61+
62+
chrome.commands.onCommand.addListener(processCommand);
63+
64+
let tabQueue = []
65+
66+
function activeTab(tabId) {
67+
tabQueue.push(tabId);
68+
}
69+
70+
chrome.tabs.onActivated.addListener(function (tab) {
71+
let tabId = tab.tabId;
72+
activeTab(tabId);
73+
});

src/edge_extension/manifest.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Floatouch",
4+
"description": "Enhance the touch experience in browser",
5+
"version": "0.1",
6+
"short_name": "Floatouch",
7+
"permissions": [
8+
"tabs"
9+
],
10+
"background": {
11+
"scripts": [
12+
"background.js"
13+
]
14+
},
15+
"commands": {
16+
"go_back_or_close_tab": {
17+
"suggested_key": {
18+
"default": "Alt+Left",
19+
"mac": "Alt+Left"
20+
},
21+
"description": "Global go back (Suggest: Alt + Left arrow) "
22+
}
23+
}
24+
}

src/floatouch/floatouch.sln

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.4.33403.182
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "floatouch", "floatouch\floatouch.csproj", "{3B98923C-65BE-4784-8E78-7092D267A68E}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "floatouch", "floatouch\floatouch.csproj", "{3B98923C-65BE-4784-8E78-7092D267A68E}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
11+
Debug|ARM64 = Debug|ARM64
12+
Debug|x64 = Debug|x64
1113
Release|Any CPU = Release|Any CPU
14+
Release|ARM64 = Release|ARM64
15+
Release|x64 = Release|x64
1216
EndGlobalSection
1317
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1418
{3B98923C-65BE-4784-8E78-7092D267A68E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1519
{3B98923C-65BE-4784-8E78-7092D267A68E}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{3B98923C-65BE-4784-8E78-7092D267A68E}.Debug|ARM64.ActiveCfg = Debug|ARM64
21+
{3B98923C-65BE-4784-8E78-7092D267A68E}.Debug|ARM64.Build.0 = Debug|ARM64
22+
{3B98923C-65BE-4784-8E78-7092D267A68E}.Debug|x64.ActiveCfg = Debug|x64
23+
{3B98923C-65BE-4784-8E78-7092D267A68E}.Debug|x64.Build.0 = Debug|x64
1624
{3B98923C-65BE-4784-8E78-7092D267A68E}.Release|Any CPU.ActiveCfg = Release|Any CPU
1725
{3B98923C-65BE-4784-8E78-7092D267A68E}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{3B98923C-65BE-4784-8E78-7092D267A68E}.Release|ARM64.ActiveCfg = Release|ARM64
27+
{3B98923C-65BE-4784-8E78-7092D267A68E}.Release|ARM64.Build.0 = Release|ARM64
28+
{3B98923C-65BE-4784-8E78-7092D267A68E}.Release|x64.ActiveCfg = Release|x64
29+
{3B98923C-65BE-4784-8E78-7092D267A68E}.Release|x64.Build.0 = Release|x64
1830
EndGlobalSection
1931
GlobalSection(SolutionProperties) = preSolution
2032
HideSolutionNode = FALSE

src/floatouch/floatouch/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
AllowsTransparency="True"
1313
MouseDown="Window_MouseDown"
1414
PreviewMouseUp="Window_PreviewMouseUp"
15-
15+
TouchMove="Window_TouchMove"
1616
>
1717
<VisualStateManager.VisualStateGroups>
1818
<VisualStateGroup x:Name="state">

0 commit comments

Comments
 (0)