feat: 🌱 include script ok
This commit is contained in:
parent
dc16fc8c49
commit
c8d5e899f7
@ -16,13 +16,4 @@
|
||||
<php min-version="8.2"/>
|
||||
<nextcloud min-version="29" max-version="30"/>
|
||||
</dependencies>
|
||||
<navigations>
|
||||
<navigation>
|
||||
<id>retro</id>
|
||||
<name>Games</name>
|
||||
<route>retro.page.index</route>
|
||||
<icon>app.svg</icon>
|
||||
<type>link</type>
|
||||
</navigation>
|
||||
</navigations>
|
||||
</info>
|
||||
|
@ -10,26 +10,35 @@ use OCP\AppFramework\Http\Attribute\FrontpageRoute;
|
||||
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
||||
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Util;
|
||||
|
||||
class PageController extends Controller
|
||||
{
|
||||
public function __construct(IRequest $request, private IInitialState $initialState)
|
||||
{
|
||||
public function __construct(
|
||||
IRequest $request,
|
||||
private readonly IRootFolder $rootFolder,
|
||||
private readonly IUserSession $userSession
|
||||
) {
|
||||
parent::__construct(Application::APP_ID, $request);
|
||||
}
|
||||
|
||||
#[NoCSRFRequired]
|
||||
#[NoAdminRequired]
|
||||
#[FrontpageRoute(verb: 'GET', url: '/{path}')]
|
||||
public function index(): TemplateResponse
|
||||
{
|
||||
Util::addStyle(Application::APP_ID, Application::APP_ID . '-main');
|
||||
Util::addScript(Application::APP_ID, Application::APP_ID . '-main');
|
||||
#[FrontpageRoute(verb: 'GET', url: '/{path}', requirements: ['path' => '.+'])]
|
||||
public function run(string $path): TemplateResponse {
|
||||
$user = $this->userSession->getUser();
|
||||
|
||||
$this->initialState->provideInitialState();
|
||||
if (!$user) {
|
||||
throw new \Exception('User not logged in');
|
||||
}
|
||||
|
||||
$folder = $this->rootFolder->getUserFolder($user->getUID());
|
||||
$folder->get($path);
|
||||
|
||||
Util::addScript(Application::APP_ID, Application::APP_ID.'-main');
|
||||
|
||||
return new TemplateResponse(
|
||||
Application::APP_ID,
|
||||
|
@ -17,7 +17,7 @@ class LoadAdditionalScriptsListener implements IEventListener
|
||||
{
|
||||
public function handle(Event $event): void {
|
||||
if ($event instanceof LoadAdditionalScriptsEvent) {
|
||||
Util::addInitScript(Application::APP_ID, 'init');
|
||||
Util::addInitScript(Application::APP_ID, Application::APP_ID.'-init');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
||||
findUnusedBaselineEntry="true"
|
||||
findUnusedCode="false"
|
||||
phpVersion="8.1"
|
||||
phpVersion="8.2"
|
||||
>
|
||||
<projectFiles>
|
||||
<directory name="lib" />
|
||||
|
12
src/init.ts
12
src/init.ts
@ -1,25 +1,25 @@
|
||||
import { FileAction, FileType, Node, registerFileAction } from '@nextcloud/files'
|
||||
import cores from './mime.json'
|
||||
import { generateUrl } from '@nextcloud/router'
|
||||
import icon from '../img/'
|
||||
import { t } from '@nextcloud/l10n'
|
||||
|
||||
const action = new FileAction({
|
||||
id: 'retro',
|
||||
displayName: () => t('repod', 'Play'),
|
||||
iconSvgInline: () => icon,
|
||||
iconSvgInline: () => '',
|
||||
enabled: (files: Node[]) => {
|
||||
if (files.length !== 1) return false
|
||||
const file = files[0]
|
||||
if (file.type !== FileType.File) return false
|
||||
if (!file.fileid || file.type !== FileType.File) return false
|
||||
const extension = file.extension?.substring(1)
|
||||
for (const core in cores) {
|
||||
if (cores[core].types === file.mime) return true
|
||||
if (cores[core].extensions.includes(file.extension)) return true
|
||||
if (cores[core].types.includes(file.mime)) return true
|
||||
if (cores[core].extensions.includes(extension)) return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
exec: async (file: Node) => {
|
||||
location.href = generateUrl('/apps/retro/' + file.path)
|
||||
location.href = generateUrl(`/apps/retro/${file.path}`)
|
||||
return true
|
||||
},
|
||||
})
|
||||
|
@ -11,6 +11,7 @@ const config = defineConfig({
|
||||
export default createAppConfig(
|
||||
{
|
||||
main: resolve(join('src', 'main.ts')),
|
||||
init: resolve(join('src', 'init.ts')),
|
||||
},
|
||||
{
|
||||
config,
|
||||
|
Loading…
x
Reference in New Issue
Block a user