This commit is contained in:
iceyrazor 2024-08-25 04:23:04 -05:00
commit bcdd786134
10 changed files with 1916 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules/*

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 iceyrazor
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

11
config.json Normal file
View File

@ -0,0 +1,11 @@
{
"default_folders": [
"%Downloads%",
"%Pictures%",
"%Videos%",
"%Documents%",
"%Desktop%",
"C:\\Users\\ricke\\Desktop\\projects\\better file browser",
"C:\\Users\\ricke\\Desktop\\projects\\mic"
]
}

1460
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

15
package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "iceys-file-browser",
"version": "1.0.0",
"description": "file browser window... thing. idfk. cope",
"main": "src/main.js",
"scripts": {
"start":"electron .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "iceyrazor",
"license": "MIT",
"dependencies": {
"electron": "^15.3.0"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
src/imgassets/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
src/imgassets/icon.pdn Normal file

Binary file not shown.

347
src/index.html Normal file
View File

@ -0,0 +1,347 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<style>
::-webkit-scrollbar {
width: 0px; /* Remove scrollbar space */
background: transparent; /* Optional: just make scrollbar invisible */
}
html{
background-color: rgba(30,30,30,0.3);
color: white;
height: 100vh;
width: 100vw;
}
.main-wrap{
user-select: none;
position: absolute;
top: 5%;
right: 10px;
width: 90%;
min-height: 20px;
max-height: 70%;
overflow-y: scroll;
}
#folder_box{
position: relative;
height: 100%;
}
#folder_box > div{
padding: 2px;
}
#folder_box > div:first-child{
height: 20px;
}
.sub-folder{
padding-left: 20px;
}
.center_text{
display: flex;
grid-template-columns: 1fr 1fr;
justify-content: left;
align-items: center;
}
.center_text > img{
padding-right: 5px;
width: 30px;
height: 30px;
}
.folder-item{
padding-top: 10px;
}
#context_menu{
display: none;
user-select: none;
position: absolute;
background-color: rgba(40,40,40,1);
padding: 4px;
left: 0px;
top: 0px;
}
#context_menu > div:hover{
background-color: rgba(80,80,80);
}
#nav_bar{
user-select: none;
position: absolute;
top: 3%;
left: 5%;
width: 91%;
display: flex;
direction: rtl;
grid-template-columns: 1fr 1fr;
background-color: rgba(30,30,30,1);
display: none;
}
#nav_bar > div{
padding: 4px;
height: 100%;
}
#nav_bar > div:hover{
background-color: rgba(80,80,80,1);
}
</style>
</head>
<body>
<div class="main-wrap"><div id="folder_box"></div></div>
<div id="context_menu">
<div onClick="reload()">reload everything</div>
<div onClick="add_to_list()">add folder to list</div>
</div>
<div id="nav_bar">
<div onclick="settings()">settings</div>
</div>
<script>
//lerd teh loobrewies
const fs=require('fs'),
os=require('os'),
path=require('path'),
electron=require('electron'),
{shell,ipcRenderer}=require('electron');
//create config if not exist
if(fs.existsSync(path.resolve(__dirname,"../config.json"))!=true){
let obj={
default_folders:[
"%Downloads%",
"%Pictures%",
"%Videos%",
"%Documents%",
"%Desktop%"
]
}
fs.writeFile(
path.resolve(__dirname,"../config.json"),
JSON.stringify(obj,null,4),
()=>{
let obj=null
}
)
}
//_*folder function related*_
//load folder config
function load_default_folders(){
fs.readFile(path.resolve(__dirname + '/../config.json'), function (err, data) {
data=JSON.parse(data)["default_folders"];
let text="<div></div>"
data.forEach((folder,i)=>{
name=folder.replace(/%/g,"");
folder=folder.replace(
/%Desktop%/g,path.resolve(os.userInfo().homedir,"Desktop")
).replace(
/%Pictures%/g,path.resolve(os.userInfo().homedir,"Pictures")
).replace(
/%Documents%/g,path.resolve(os.userInfo().homedir,"Documents")
).replace(
/%Videos%/g,path.resolve(os.userInfo().homedir,"Videos")
).replace(
/%Downloads%/g,path.resolve(os.userInfo().homedir,"Downloads")
);
name=folder.replace(
path.resolve(os.userInfo().homedir,"Desktop"),'Desktop'
).replace(
path.resolve(os.userInfo().homedir,"Pictures"),'Pictures'
).replace(
path.resolve(os.userInfo().homedir,"Documents"),'Documents'
).replace(
path.resolve(os.userInfo().homedir,"Videos"),'Videos'
).replace(
path.resolve(os.userInfo().homedir,"Downloads"),'Downloads'
);
let file_parsed=folder.replace(/\\/g,"\\\\");
if (fs.existsSync(folder)) {
text+=
'<div class="folder">'+
'<div class="center_text" onclick="open_folder(\''+file_parsed+'\')">'+
'<img src="imgassets/foldericon.ico" />'+name+
'</div>'+
'<div class="sub-folder" id="'+(folder)+'"></div></div>'
} else {
text+='<div style="background-color: rgb(180,0,0);" class="not-exist" id="'+folder
+'">'+folder+' does not exist</div>'
}
})
document.getElementById('folder_box').innerHTML=text
});
}
load_default_folders();
let folder_box=document.getElementById('folder_box')
function open_folder(id){
let div=document.getElementById(id)
if(div.innerHTML==""){
fs.readdir(id,(err, files) => {
files.sort((a,b)=>{
if(a.includes(".")){
return 0
} else {
return -1
}
})
for(file in files){
let file_parsed=(id+"\\"+files[file]).replace(/\\/g,"\\\\");
if(files[file].includes('.')){
div.innerHTML+=
'<div class="folder-item" onclick="shell.openPath(\''+(file_parsed)
+'\')">'+
files[file]+'</div>'
} else {
div.innerHTML+=
'<div class="folder">'+
'<div class="center_text" onclick="open_folder(\''+file_parsed+'\')">'+
'<img src="imgassets/foldericon.ico" />'+files[file]+
'</div>'+
'<div class="sub-folder" id="'+(id+"\\"+files[file])+'"></div></div>'
}
}
})
} else {
div.innerHTML=""
}
}
//_*context menu stuffs*_
let context_data=""
context_menu=document.getElementById('context_menu')
context_menu_default=context_menu.innerHTML
window.addEventListener("contextmenu", e=>{
if(e.target.onclick){
let str=e.target.onclick.toString().match(/\'.*\'/g)[0].replace(/\'/g,"")
if(str.includes(".")){
}
else if(str){
e.preventDefault();
context_menu.innerHTML=context_menu_default
context_data=str.replace(/\\\\/g,"\\")
if(e.srcElement.parentNode.parentNode.id=="folder_box"){
context_menu.innerHTML+='<div onclick="remove_from_list()">remove from list</div>'
}
context_menu.style.display="block";
context_menu.style.left=e.pageX+'px';
context_menu.style.top=e.pageY+'px';
}
}
else if(e.target.class="not-exist"){
console.log(e.target.id.toString());
str=e.target.id.toString()
e.preventDefault();
context_menu.innerHTML='<div onclick="remove_from_list()">remove from list</div>'
context_data=str.replace(/\\\\/g,"\\")
context_menu.style.display="block";
context_menu.style.left=e.pageX+'px';
context_menu.style.top=e.pageY+'px';
}
})
window.addEventListener('mousedown',e=>{
if(context_menu.style.display!="none"){
setTimeout(()=>{
context_menu.style.display="none"
},200)
}
})
function add_to_list(id){
if(id==null){
id=context_data
}
fs.readFile(path.resolve(__dirname + '/../config.json'), function (err, data) {
data=JSON.parse(data)
data["default_folders"].push(id)
fs.writeFile(
path.resolve(__dirname,"../config.json"),
JSON.stringify(data,null,4),
()=>{
load_default_folders();
}
)
});
}
function remove_from_list(){
fs.readFile(path.resolve(__dirname + '/../config.json'), function (err, data) {
data=JSON.parse(data)
data["default_folders"].forEach((folder,i)=>{
folder=folder.replace(
/%Desktop%/g,path.resolve(os.userInfo().homedir,"Desktop")
).replace(
/%Pictures%/g,path.resolve(os.userInfo().homedir,"Pictures")
).replace(
/%Documents%/g,path.resolve(os.userInfo().homedir,"Documents")
).replace(
/%Videos%/g,path.resolve(os.userInfo().homedir,"Videos")
).replace(
/%Downloads%/g,path.resolve(os.userInfo().homedir,"Downloads")
);
if(folder==context_data){
console.log("L + RATIO + REMOVED YOUR FILE "+context_data+" + COPE");
data["default_folders"].splice(i,1)
}
});
fs.writeFile(
path.resolve(__dirname,"../config.json"),
JSON.stringify(data,null,4),
()=>{
load_default_folders();
}
)
});
}
function reload(){
location.reload();
}
//_*allow click behind*_
folder_box.addEventListener('mouseenter',()=>{
ipcRenderer.send('set-click','false')
})
folder_box.addEventListener('mouseleave',()=>{
ipcRenderer.send('set-click','true')
});
context_menu.addEventListener('mouseenter',()=>{
ipcRenderer.send('set-click','false')
})
context_menu.addEventListener('mouseleave',()=>{
ipcRenderer.send('set-click','true')
});
</script>
</body>
</html>

61
src/main.js Normal file
View File

@ -0,0 +1,61 @@
const electron = require('electron'),
{app,BrowserWindow,Menu,Tray,ipcMain} = require('electron'),
path = require('path');
myWindow=null;
global.tray=null;
app.whenReady().then(()=>{
//set tray icon
tray = new Tray(path.join(__dirname+'/imgassets/icon.ico'))
const contextMenu = Menu.buildFromTemplate([
{label:"on top",click(){
switch(myWindow.isAlwaysOnTop()){
case true:
myWindow.setAlwaysOnTop(false);
break;
case false:
myWindow.setAlwaysOnTop(true)
break;
}
}},
{label:"exit",click(){ app.quit(); }},
])
tray.setToolTip('better file browser')
tray.setContextMenu(contextMenu)
//figure out screens
primaryscreen=electron.screen.getPrimaryDisplay()
//create window
myWindow=new BrowserWindow({
width: Math.floor(primaryscreen.bounds.width/5),
//width: 800,
height: primaryscreen.bounds.height,
frame: false,
transparent:true,
webPreferences:{
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: false,
}
});
//set intial position
myWindow.setPosition(primaryscreen.bounds.width-myWindow.getBounds().width,0)
myWindow.setAlwaysOnTop(true);
myWindow.loadFile('src/index.html');
myWindow.once('ready-to-show', () => {
//myWindow.webContents.openDevTools()
myWindow.setIgnoreMouseEvents(true, { forward: true });
});
});
ipcMain.on('set-click',(event,arg)=>{
if(arg=='false'){
myWindow.setIgnoreMouseEvents(false)
} else {
myWindow.setIgnoreMouseEvents(true, { forward: true });
}
})