Skip to content

Commit

Permalink
Merge pull request #4 from JoseMoreville/staging
Browse files Browse the repository at this point in the history
Version 0.8.0 code
  • Loading branch information
JoseMoreville authored Jul 3, 2022
2 parents 066c997 + 6080d14 commit 05ffb28
Show file tree
Hide file tree
Showing 19 changed files with 509 additions and 213 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
{
"cSpell.words": [
"asar",
"typecheck",
"vitest"
]
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ A desktop live wallpaper app made for <span style="color:#74B1AE"> Mac</span>.

# Features

- Accepts multiple media files (mp4, webm, png, jpg, gif)
- Accepts multiple media files (mp4, webM, png, jpg, gif)
- Can chose between 60fps, 30fps (might add more options later)
- Media type can have audio (Might add option to add custom audio later)
- Supports all screen resolutions (Tested on 4k, 1080p, 720p screens)
- More to be added

# Roadmap

- Detect multiple monitors and create a wallpaper for each one (different instances)
- Detect multiple monitors and create a wallpaper for each one (different instances)
- Improve image quality of the wallpaper ✅
- To add an optional particle system
- To be able to reproduce background music on the wallpaper ✅
- Cursor interaction
- To be able to detect wheter the user is using an app and stop the wallpaper to save resorces (like battery) ✅ (Unstable and experimental, available on next build)
- To be able to detect whether the user is using an app and stop the wallpaper to save resources (like battery) ✅
- To be able to launch the app at startup (Optionally) ✅
- Make it laptop friendly (reduce battery drain and all of that) ✅

Expand Down
19 changes: 17 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"name": "wallpieperi",
"description": "A desktop live wallpaper app made for Mac.",
"author": {
"name": "José Moreno",
"email": "[email protected]"
},
"private": true,
"engines": {
"node": ">=v16.13",
Expand Down Expand Up @@ -49,6 +54,7 @@
"dependencies": {
"@vueuse/core": "^8.2.5",
"@vueuse/electron": "^8.2.5",
"@vueuse/head": "^0.7.6",
"active-win": "^7.7.2",
"electron-store": "^8.0.1",
"electron-updater": "4.6.5",
Expand Down
27 changes: 19 additions & 8 deletions packages/main/src/Handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@ const activeWindow = require('active-win');

export default function useHandlers(): void {
ipcMain.handle("getBackground", (event, arg) => {
const file =
app.getPath("userData") + "/backgrounds/" + store.get("currentBackground");
return file;
const collection = store.get("currentBackground");
for (const screen in collection) {
if (Object.prototype.hasOwnProperty.call(collection, screen)) {
const background = app.getPath("userData") + "/backgrounds/" + collection[screen];
collection[screen] = background
}
}
return collection;
});

ipcMain.handle("changeBackground", (event, arg) => {
store.set(
"currentBackground",
arg.replace(`file://${app.getPath("userData")}/backgrounds/`, "")
);
const DATA_BEFORE_UPDATE = store.get("currentBackground")
let UPDATED_DATA = { ...DATA_BEFORE_UPDATE}
for (const key in arg) {
if (Object.prototype.hasOwnProperty.call(arg, key)) {
const element = arg[key].replace(`file://${app.getPath("userData")}/backgrounds/`, "");
UPDATED_DATA[key] = element
}
}
store.set("currentBackground", UPDATED_DATA);
BrowserWindow.getAllWindows()[1].reload();
return arg.replace(`file://${app.getPath("userData")}/backgrounds/`, "");
BrowserWindow.getAllWindows()[2].reload();
return UPDATED_DATA;
});

ipcMain.handle("getBackgrounds", (event, arg) => {
Expand Down
180 changes: 93 additions & 87 deletions packages/main/src/changeBackgroundWindow.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* es-lint-disable */
/* ts-lint-disable */
import {BrowserWindow, screen, app} from 'electron';
import {join} from 'path';
import {URL} from 'url';
import { BrowserWindow, screen, app } from 'electron';
import { join } from 'path';
import { URL } from 'url';
const fs = require('fs');
const Store = require('electron-store');
const store = new Store();
Expand All @@ -11,92 +11,98 @@ const store = new Store();
// yet to be configured

async function createChangeBackgroundWindow() {
const browserUploadWindow = new BrowserWindow({
//skipTaskbar: true,
movable: true,
roundedCorners: true,
title: 'Change Background',
resizable: true,
hasShadow: true,
fullscreenable: false,
show: true, // Use 'ready-to-show' event to show window
height: screen.getPrimaryDisplay().size.height-300,
width: screen.getPrimaryDisplay().size.width-300,
minHeight:screen.getPrimaryDisplay().size.height-350,
minWidth:screen.getPrimaryDisplay().size.width-600,
enableLargerThanScreen: true,
webPreferences: {
nativeWindowOpen: true,
webviewTag: false, // The webview tag is not recommended. Consider alternatives like iframe or Electron's BrowserView. https://www.electronjs.org/docs/latest/api/webview-tag#warning
preload: join(__dirname, '../../preload/dist/index.cjs'),
webSecurity: false,
},
//titleBarStyle: 'hidden',
titleBarOverlay: true,
});

/**
* If you install `show: true` then it can cause issues when trying to close the window.
* Use `show: false` and listener events `ready-to-show` to fix these issues.
*
* @see https://github.com/electron/electron/issues/25012
*/
browserUploadWindow.on('ready-to-show', () => {
browserUploadWindow?.show();

if (import.meta.env.DEV) {
browserUploadWindow?.webContents.openDevTools();
}
});
const browserUploadWindow = new BrowserWindow({
//skipTaskbar: true,
movable: true,
roundedCorners: true,
title: 'Change Background',
resizable: true,
hasShadow: true,
fullscreenable: false,
show: true, // Use 'ready-to-show' event to show window
height: screen.getPrimaryDisplay().size.height - 300,
width: screen.getPrimaryDisplay().size.width - 300,
minHeight: screen.getPrimaryDisplay().size.height - 350,
minWidth: screen.getPrimaryDisplay().size.width - 600,
enableLargerThanScreen: true,
webPreferences: {
nativeWindowOpen: true,
webviewTag: false, // The webview tag is not recommended. Consider alternatives like iframe or Electron's BrowserView. https://www.electronjs.org/docs/latest/api/webview-tag#warning
preload: join(__dirname, '../../preload/dist/index.cjs'),
webSecurity: false,
},
//titleBarStyle: 'hidden',
titleBarOverlay: true,
});

browserUploadWindow.on('close', () => app.dock.hide());
/**
* URL for main window.
* Vite dev server for development.
* `file://../renderer/index.html` for production and test
*/
const pageUrl = import.meta.env.DEV && import.meta.env.VITE_DEV_SERVER_URL !== undefined
? import.meta.env.VITE_DEV_SERVER_URL +'changeBackground'
: new URL('../renderer/dist/changeBackground.html', 'file://' + __dirname).toString();

let data = '';
fs.readdir(`${app.getPath('userData')}/backgrounds`, async (err:Error, files: Array<string>) => {
if (err) console.error(err);
files = files.filter( file =>
file.endsWith('.mp4') ||
file.endsWith('.webm') ||
file.endsWith('.png') ||
file.endsWith('.jpg') ||
file.endsWith('.jpeg'));
for (const video of files) {
if(video == store.get('currentBackground')){
data = `${app.getPath('userData')}/backgrounds/${video}`;
break;
}
}
});
browserUploadWindow.loadFile(data);
//browserUploadWindow.loadFile('/Users/hades/Library/Application Support/wallpieperi/backgrounds/videoplayback.mp4');
await browserUploadWindow.loadURL(pageUrl);

return browserUploadWindow;
}

/**
* Restore existing BrowserWindow or Create new BrowserWindow
* If you install `show: true` then it can cause issues when trying to close the window.
* Use `show: false` and listener events `ready-to-show` to fix these issues.
*
* @see https://github.com/electron/electron/issues/25012
*/
export async function restoreOrCreateChangeBackgroundWindow() {
let window = BrowserWindow.getAllWindows().find(w => !w.isDestroyed());
window?.webContents.session.clearCache();

if (BrowserWindow.getAllWindows().length === 1) {
window = await createChangeBackgroundWindow();
} else{
window = BrowserWindow.getAllWindows().filter(w => w.isMinimized())[0];
browserUploadWindow.on('ready-to-show', () => {
browserUploadWindow?.show();

if (import.meta.env.DEV) {
browserUploadWindow?.webContents.openDevTools();
}
if (window.isMinimized() ||!window.isFocused()) {
window.restore();
});

browserUploadWindow.on('close', () => app.dock.hide());
/**
* URL for main window.
* Vite dev server for development.
* `file://../renderer/index.html` for production and test
*/
/*
const pageUrl = import.meta.env.DEV && import.meta.env.VITE_DEV_SERVER_URL !== undefined
? import.meta.env.VITE_DEV_SERVER_URL +'changeBackground'
: new URL('../renderer/dist/changeBackground.html', 'file://' + __dirname).toString();
*/
const pageUrl = new URL('../renderer/dist/changeBackground.html', 'file://' + __dirname).toString();

let data = '';
fs.readdir(`${app.getPath('userData')}/backgrounds`, async (err: Error, files: Array<string>) => {
if (err) console.error(err);
files = files.filter(file =>
file.endsWith('.mp4') ||
file.endsWith('.webm') ||
file.endsWith('.png') ||
file.endsWith('.jpg') ||
file.endsWith('.jpeg'));
for (const video of files) {
if (video == store.get('currentBackground')) {
data = `${app.getPath('userData')}/backgrounds/${video}`;
break;
}
}
app.dock.show();
window.focus();
}
});
browserUploadWindow.loadFile(data);
//browserUploadWindow.loadFile('/Users/hades/Library/Application Support/wallpieperi/backgrounds/videoplayback.mp4');
await browserUploadWindow.loadURL(pageUrl);

return browserUploadWindow;
}

/**
* Restore existing BrowserWindow or Create new BrowserWindow
*/
export async function restoreOrCreateChangeBackgroundWindow() {
let window = BrowserWindow.getAllWindows().find(w => !w.isDestroyed());
window?.webContents.session.clearCache();
if (BrowserWindow.getAllWindows().length === 1 || BrowserWindow.getAllWindows().length === screen.getAllDisplays().length || window === undefined) {
window = await createChangeBackgroundWindow();
}
else {
//window = BrowserWindow.getAllWindows().filter(w => w.isMinimized())[0];
window = BrowserWindow.getAllWindows().filter(w => w.getTitle() === 'Change Background')[0];
if(!window) window = await createChangeBackgroundWindow();
}

if (window?.isMinimized() || !window?.isFocused()) window?.restore();

app.dock.show();
window.focus();

}
Loading

0 comments on commit 05ffb28

Please sign in to comment.