Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions main/main.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ const { app, BrowserWindow, dialog, Menu, session, ipcMain, electron } = require
const path = require('path');
const fs = require('fs');
const fetch = require('cross-fetch');
const https = require('https');
const contextMenu = require('electron-context-menu');

if (require('electron-squirrel-startup')) app.quit();
Expand DownExpand Up@@ -191,6 +192,22 @@ ipcMain.handle('get-themes', async (event) => {
return buf;
});

function download(url, dest, cb) {
var file = fs.createWriteStream(dest);
https.get(url, function (response) {
response.pipe(file);
file.on('finish', function () {
file.close(cb);
});
});
}

ipcMain.handle('download-theme', async (event, url, name) => {
download(url, `${app.getPath('userData')}/themes/${name}`, () => {
return;
})
});

ipcMain.handle('toggle-full-screen', async (event) => {
mainWindow.setFullScreen(!mainWindow.isFullScreen());
});
Expand Down
3 changes: 3 additions & 0 deletions main/preload.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,6 +49,9 @@ contextBridge.exposeInMainWorld('native', {
}
)
},
downloadTheme: (url, name) => {
ipcRenderer.invoke('download-theme', url, name);
},
unloadTheme: () => {
document.getElementsByClassName('theme')[0].remove()
},
Expand Down
8 changes: 8 additions & 0 deletions src/search.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,6 +63,14 @@ function loadURL(url) {
if ( url.startsWith('http://') ) {
alert(`Page ${url} is not secure.`);
}
if (url.startsWith('https://raw.githubusercontent.com/CatalystDevOrg/Themes/master/') && url.endsWith('.css')) {
if (confirm("This link looks like a theme URL. Attempt to install theme?")) {
catalyst.native.downloadTheme(url, url.split("/")[6])
if (confirm(`Theme ${url.split("/")[6]} installed successfully! Switch to theme?`)) {
catalyst.native.loadTheme(url.split("/")[6])
};
}
}
view.src = url;
view.addEventListener('did-fail-load', () => {
view.src = 'home.html';
Expand Down