Skip to content

Commit

Permalink
Merge pull request #4 from Milansuman/js_extensions
Browse files Browse the repository at this point in the history
[FEAT] Added multiple js extension polyfills.
  • Loading branch information
Milansuman authored Jul 28, 2024
2 parents 214789b + 02b0113 commit 6d8d26d
Show file tree
Hide file tree
Showing 27 changed files with 574 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "extensions/spotlight"]
path = extensions/spotlight
url = https://github.com/Jovit-Mathew236/project-web-spotlight.git
22 changes: 22 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Flux Browser JS API Docs

## Tab Management

```ts
window.tabs.requestSplitTab(url: string): null
window.tabs.requestSplitTab(): null
window.tabs.requestFlipTabs(): null
window.tabs.requestNewGroup(url: string): null
window.tabs.addTabs(tabs: Array<Array<string>>): boolean
```
## File API

```ts
window.fs.listDir(path: string, subdir?: boolean) : Array<{path: string, isDir: boolean, dirs: Array<{path: string, isDir: boolean}>}>
window.fs.getFileUrl(): string
window.fs.getFolderUrl(): string
```
## Dialog API
```ts
window.dialog.closeDialog()
```
1 change: 1 addition & 0 deletions extensions/spotlight
Submodule spotlight added at 24c2e5
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_subdirectory(misc)
add_subdirectory(components)
add_subdirectory(windows)
add_subdirectory(api)

set(SOURCES
${SOURCES}
Expand Down
13 changes: 13 additions & 0 deletions src/api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(SOURCES ${SOURCES}
src/api/TabApi.h
src/api/TabApi.cpp
src/api/TerminalApi.h
src/api/TerminalApi.cpp
src/api/HistoryApi.h
src/api/HistoryApi.cpp
src/api/FileApi.h
src/api/FileApi.cpp
src/api/DialogApi.h
src/api/DialogApi.cpp
PARENT_SCOPE
)
9 changes: 9 additions & 0 deletions src/api/DialogApi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "DialogApi.h"

DialogApi::DialogApi(QObject *parent): QObject(parent){}

void DialogApi::closeDialog(){
emit this->closeDialogRequested();
}

DialogApi::~DialogApi() = default;
13 changes: 13 additions & 0 deletions src/api/DialogApi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <QObject>

class DialogApi: public QObject{
Q_OBJECT
public:
DialogApi(QObject *parent=nullptr);
Q_INVOKABLE void closeDialog();
~DialogApi();
signals:
void closeDialogRequested();
};
66 changes: 66 additions & 0 deletions src/api/FileApi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "FileApi.h"

#include <QDir>
#include <QJsonArray>
#include <QDirIterator>
#include <QFile>
#include <QStringList>
#include <QFileDialog>
#include <QJsonObject>

FileApi::FileApi(QObject *parent): QObject(parent){}

QJsonDocument FileApi::listDir(QString path, bool subdir){
QJsonDocument folderData;

QDir directory(path);
directory.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);
QJsonArray entries;
for(QFileInfo path: directory.entryInfoList()){
QJsonObject fileData;
fileData.insert("path", path.filePath());
fileData.insert("isDir", path.isDir());

if(subdir && path.isDir()){
QJsonArray subdirEntries;
for(QFileInfo subPath: QDir(path.filePath()).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot)){
QJsonObject subFileData;

subFileData.insert("path", subPath.filePath());
subFileData.insert("isDir", subPath.isDir());
subdirEntries.append(subFileData);
}
fileData.insert("dirs", subdirEntries);
}

entries.append(fileData);
}

folderData.setArray(entries);
return folderData;
}

QJsonDocument FileApi::search(QString fuzz){
QJsonDocument filesData;

QDirIterator iter(QDir::homePath(), QStringList(fuzz), QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);

QJsonArray files;
while(iter.hasNext()){
QFile file(iter.next());
files.append(file.fileName());
}

filesData.setArray(files);
return filesData;
}

QString FileApi::getFileURL(){
return QFileDialog::getOpenFileUrl(nullptr, "Open a file", QDir::homePath(), "").toString();
}

QString FileApi::getFolderURL(){
return QFileDialog::getExistingDirectoryUrl(nullptr, "Open a file", QDir::homePath()).toString();
}

FileApi::~FileApi() = default;
21 changes: 21 additions & 0 deletions src/api/FileApi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <QObject>
#include <QJsonDocument>

/*
listDir(string path, boolean subdir?) : Array<string>
getFileUrl(): string
getFolderUrl(): string
*/

class FileApi: public QObject{
Q_OBJECT
public:
FileApi(QObject *parent=nullptr);
Q_INVOKABLE QJsonDocument listDir(QString path, bool subdir=false);
QJsonDocument search(QString fuzz);
Q_INVOKABLE QString getFileURL();
Q_INVOKABLE QString getFolderURL();
~FileApi();
};
23 changes: 23 additions & 0 deletions src/api/HistoryApi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "HistoryApi.h"

#include <QWebEngineHistoryItem>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonValue>

HistoryApi::HistoryApi(QWebEngineHistory *history, QObject *parent): QObject(parent), history(history){}

QJsonDocument HistoryApi::getHistory(){
QJsonDocument result;
QJsonArray array;
for(QWebEngineHistoryItem item: this->history->items()){
QJsonObject historyItem;
historyItem.insert(item.title(), QJsonValue(item.url().toString()));
array.append(historyItem);
}
result.setArray(array);

return result;
}

HistoryApi::~HistoryApi() = default;
19 changes: 19 additions & 0 deletions src/api/HistoryApi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <QObject>
#include <QWebEngineHistory>
#include <QJsonDocument>

/*
window.tabHistory.getHistory() : Array<{ title: string, url: string}>
*/

class HistoryApi: public QObject{
Q_OBJECT
private:
QWebEngineHistory *history;
public:
HistoryApi(QWebEngineHistory *history, QObject *parent=nullptr);
Q_INVOKABLE QJsonDocument getHistory();
~HistoryApi();
};
45 changes: 45 additions & 0 deletions src/api/TabApi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "TabApi.h"

#include <QJsonArray>

TabsApi::TabsApi(QObject *parent): QObject(parent){}

bool TabsApi::addTabs(QJsonDocument tabs){
if(tabs.isArray()){
QList<QList<QUrl>> tabsList;
for(QJsonValueRef group: tabs.array()){
if(group.isArray()){
QList<QUrl> urls;

for(QJsonValueRef url: group.toArray()){
urls.append(QUrl(url.toString()));
}
tabsList.append(urls);
}else{
return false;
}
}
emit this->addTabsRequested(tabsList);
}else{
return false;
}
return true;
}

void TabsApi::requestSplitTab(QString url){
emit this->splitTabRequested(QUrl(url));
}

void TabsApi::requestSplitTab(){
emit this->splitTabHomeRequested();
}

void TabsApi::requestFlipTabs(){
emit this->splitTabFlipRequested();
}

void TabsApi::requestNewGroup(QString url){
emit this->newTabRequested(QUrl(url));
}

TabsApi::~TabsApi() = default;
31 changes: 31 additions & 0 deletions src/api/TabApi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <QObject>
#include <QUrl>
#include <QJsonDocument>
#include <QList>
#include <QUrl>

/*
window.tabs.requestSplitTab(string url)
window.tabs.requestFlipTabs()
window.tabs.requestNewGroup(string url)
*/

class TabsApi: public QObject{
Q_OBJECT
public:
TabsApi(QObject *parent=nullptr);
Q_INVOKABLE bool addTabs(QJsonDocument tabs);
Q_INVOKABLE void requestSplitTab(QString url);
Q_INVOKABLE void requestSplitTab();
Q_INVOKABLE void requestFlipTabs();
Q_INVOKABLE void requestNewGroup(QString url);
~TabsApi();
signals:
void splitTabRequested(QUrl url);
void splitTabHomeRequested();
void splitTabFlipRequested();
void newTabRequested(QUrl url);
void addTabsRequested(QList<QList<QUrl>>);
};
17 changes: 17 additions & 0 deletions src/api/TerminalApi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "TerminalApi.h"

#include <cstdlib>

#ifdef __linux__
#include <pty.h>
#endif

TerminalApi::TerminalApi(QObject *parent): QObject(parent){
#ifdef __linux__

QString shell = QString(std::getenv("SHELL"));

#endif
}

TerminalApi::~TerminalApi() = default;
10 changes: 10 additions & 0 deletions src/api/TerminalApi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <QObject>

class TerminalApi: public QObject{
Q_OBJECT
public:
TerminalApi(QObject *parent=nullptr);
~TerminalApi();
};
4 changes: 2 additions & 2 deletions src/components/SideBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SideBar::SideBar(QWidget *parent): QWidget(parent){
this->gridViewButton = new IconButton(":/icons/grid.png");
this->gridViewButton->setStyleSheet(
"QPushButton{"
" background-color: rgba(87,91,138,178);"
" background-color: rgba(0,0,0,0.5);"
" border-radius: 5px;"
"}"
);
Expand All @@ -20,7 +20,7 @@ SideBar::SideBar(QWidget *parent): QWidget(parent){
this->newGroupButton = new IconButton(":/icons/plus.png");
this->newGroupButton->setStyleSheet(
"QPushButton{"
" background-color: rgba(87,91,138,178);"
" background-color: rgba(0,0,0,0.5);"
" border-radius: 5px;"
"}"
);
Expand Down
Loading

0 comments on commit 6d8d26d

Please sign in to comment.