Move store opening to frontend only

This commit is contained in:
Jonas Dellinger
2022-05-31 18:05:26 +02:00
parent 660e34664e
commit bd1b2e82fd
3 changed files with 27 additions and 40 deletions
+13 -24
View File
@@ -1,7 +1,10 @@
from aiohttp import ClientSession, web
from injector import inject_to_tab
from json.decoder import JSONDecodeError
import uuid import uuid
from json.decoder import JSONDecodeError
from aiohttp import ClientSession, web
from injector import inject_to_tab
class Utilities: class Utilities:
def __init__(self, context) -> None: def __init__(self, context) -> None:
@@ -12,8 +15,7 @@ class Utilities:
"confirm_plugin_install": self.confirm_plugin_install, "confirm_plugin_install": self.confirm_plugin_install,
"execute_in_tab": self.execute_in_tab, "execute_in_tab": self.execute_in_tab,
"inject_css_into_tab": self.inject_css_into_tab, "inject_css_into_tab": self.inject_css_into_tab,
"remove_css_from_tab": self.remove_css_from_tab, "remove_css_from_tab": self.remove_css_from_tab
"open_plugin_store": self.open_plugin_store
} }
if context: if context:
@@ -53,7 +55,7 @@ class Utilities:
async def ping(self, **kwargs): async def ping(self, **kwargs):
return "pong" return "pong"
async def execute_in_tab(self, tab, run_async, code): async def execute_in_tab(self, tab, run_async, code):
try: try:
result = await inject_to_tab(tab, code, run_async) result = await inject_to_tab(tab, code, run_async)
if "exceptionDetails" in result["result"]: if "exceptionDetails" in result["result"]:
@@ -67,7 +69,7 @@ class Utilities:
"result" : result["result"]["result"].get("value") "result" : result["result"]["result"].get("value")
} }
except Exception as e: except Exception as e:
return { return {
"success": False, "success": False,
"result": e "result": e
} }
@@ -76,7 +78,7 @@ class Utilities:
try: try:
css_id = str(uuid.uuid4()) css_id = str(uuid.uuid4())
result = await inject_to_tab(tab, result = await inject_to_tab(tab,
f""" f"""
(function() {{ (function() {{
const style = document.createElement('style'); const style = document.createElement('style');
@@ -97,14 +99,14 @@ class Utilities:
"result" : css_id "result" : css_id
} }
except Exception as e: except Exception as e:
return { return {
"success": False, "success": False,
"result": e "result": e
} }
async def remove_css_from_tab(self, tab, css_id): async def remove_css_from_tab(self, tab, css_id):
try: try:
result = await inject_to_tab(tab, result = await inject_to_tab(tab,
f""" f"""
(function() {{ (function() {{
let style = document.getElementById("{css_id}"); let style = document.getElementById("{css_id}");
@@ -124,20 +126,7 @@ class Utilities:
"success": True "success": True
} }
except Exception as e: except Exception as e:
return { return {
"success": False, "success": False,
"result": e "result": e
} }
async def open_plugin_store(self):
await inject_to_tab("SP", """
(function() {
wpRequire = webpackJsonp.push([[], { get_require: (mod, _exports, wpRequire) => mod.exports = wpRequire }, [["get_require"]]]);
const all = () => Object.keys(wpRequire.c).map((x) => wpRequire.c[x].exports).filter((x) => x);
router = all().map(m => {
if (typeof m !== "object") return undefined;
for (let prop in m) { if (m[prop]?.Navigate) return m[prop]}
}).find(x => x)
router.NavigateToExternalWeb("http://127.0.0.1:1337/browser/redirect")
})();
""")
+12 -2
View File
@@ -1,12 +1,17 @@
import { ButtonItem, DialogButton, PanelSection, PanelSectionRow } from 'decky-frontend-lib'; import { ButtonItem, DialogButton, PanelSection, PanelSectionRow, Router } from 'decky-frontend-lib';
import { VFC } from 'react'; import { VFC } from 'react';
import { FaArrowLeft } from 'react-icons/fa'; import { FaArrowLeft, FaStore } from 'react-icons/fa';
import { useDeckyState } from './DeckyState'; import { useDeckyState } from './DeckyState';
const PluginView: VFC = () => { const PluginView: VFC = () => {
const { plugins, activePlugin, setActivePlugin, closeActivePlugin } = useDeckyState(); const { plugins, activePlugin, setActivePlugin, closeActivePlugin } = useDeckyState();
const onStoreClick = () => {
Router.CloseSideMenus();
Router.NavigateToExternalWeb('http://127.0.0.1:1337/browser/redirect');
};
if (activePlugin) { if (activePlugin) {
return ( return (
<div style={{ height: '100%' }}> <div style={{ height: '100%' }}>
@@ -22,6 +27,11 @@ const PluginView: VFC = () => {
return ( return (
<PanelSection> <PanelSection>
<div style={{ position: 'absolute', top: '3px', right: '16px', zIndex: 20 }}>
<DialogButton style={{ minWidth: 0, padding: '10px 12px' }} onClick={onStoreClick}>
<FaStore style={{ display: 'block' }} />
</DialogButton>
</div>
{plugins.map(({ name, icon }) => ( {plugins.map(({ name, icon }) => (
<PanelSectionRow key={name}> <PanelSectionRow key={name}>
<ButtonItem layout="below" onClick={() => setActivePlugin(name)}> <ButtonItem layout="below" onClick={() => setActivePlugin(name)}>
+2 -14
View File
@@ -1,25 +1,13 @@
import { DialogButton, staticClasses } from 'decky-frontend-lib'; import { staticClasses } from 'decky-frontend-lib';
import { VFC } from 'react'; import { VFC } from 'react';
import { FaShoppingBag } from 'react-icons/fa';
import { useDeckyState } from './DeckyState'; import { useDeckyState } from './DeckyState';
const TitleView: VFC = () => { const TitleView: VFC = () => {
const { activePlugin } = useDeckyState(); const { activePlugin } = useDeckyState();
const openPluginStore = () => fetch('http://127.0.0.1:1337/methods/open_plugin_store', { method: 'POST' });
if (activePlugin === null) { if (activePlugin === null) {
return ( return <div className={staticClasses.Title}>Decky</div>;
<div className={staticClasses.Title}>
Decky
<div style={{ position: 'absolute', top: '3px', right: '16px', zIndex: 20 }}>
<DialogButton style={{ minWidth: 0, padding: '10px 12px' }} onClick={openPluginStore}>
<FaShoppingBag style={{ display: 'block' }} />
</DialogButton>
</div>
</div>
);
} }
return ( return (