Merge branch 'main' of github.com:SamidyFR/monochrome
This commit is contained in:
commit
2d43e2d3cc
7 changed files with 82 additions and 61 deletions
2
.github/workflows/desktop-build.yml
vendored
2
.github/workflows/desktop-build.yml
vendored
|
|
@ -50,7 +50,7 @@ jobs:
|
||||||
run: npx neu update
|
run: npx neu update
|
||||||
|
|
||||||
- name: Build application
|
- name: Build application
|
||||||
run: npm run build
|
run: npm run build:desktop
|
||||||
|
|
||||||
- name: Prepare Release
|
- name: Prepare Release
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
BIN
.gitignore
vendored
BIN
.gitignore
vendored
Binary file not shown.
|
|
@ -4323,6 +4323,7 @@
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/pocketbase@0.21.3/dist/pocketbase.umd.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/pocketbase@0.21.3/dist/pocketbase.umd.js"></script>
|
||||||
|
<script src="/neutralino.js"></script>
|
||||||
<script type="module" src="/js/app.js"></script>
|
<script type="module" src="/js/app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
47
js/app.js
47
js/app.js
|
|
@ -1,4 +1,5 @@
|
||||||
//js/app.js
|
//js/app.js
|
||||||
|
console.log('[App] Script loaded');
|
||||||
import { LosslessAPI } from './api.js';
|
import { LosslessAPI } from './api.js';
|
||||||
import {
|
import {
|
||||||
apiSettings,
|
apiSettings,
|
||||||
|
|
@ -25,7 +26,7 @@ import * as Neutralino from '@neutralinojs/lib';
|
||||||
import './smooth-scrolling.js';
|
import './smooth-scrolling.js';
|
||||||
|
|
||||||
// Assign Neutralino to window for global access
|
// Assign Neutralino to window for global access
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined' && window.NL_MODE) {
|
||||||
window.Neutralino = Neutralino;
|
window.Neutralino = Neutralino;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -237,6 +238,31 @@ async function disablePwaForAuthGate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
// Initialize desktop environment (Neutralino)
|
||||||
|
const isDesktop = typeof window !== 'undefined' && (window.NL_MODE || window.location.port === '5050');
|
||||||
|
if (typeof window !== 'undefined' && window.Neutralino) {
|
||||||
|
console.log('[App] Neutralino object detected. Environment:', isDesktop ? 'Desktop' : 'Web');
|
||||||
|
if (isDesktop) {
|
||||||
|
console.log('[App] Initializing Neutralino desktop environment...');
|
||||||
|
try {
|
||||||
|
Neutralino.init();
|
||||||
|
console.log('[App] Neutralino.init() called successfully.');
|
||||||
|
|
||||||
|
// Register events immediately
|
||||||
|
Neutralino.events.on('windowClose', () => {
|
||||||
|
console.log('[App] Window close event triggered.');
|
||||||
|
Neutralino.app.exit();
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[App] Failed to initialize desktop environment:', error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('[App] Skipping Neutralino.init() on regular web environment.');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('[App] Neutralino object NOT detected.');
|
||||||
|
}
|
||||||
|
|
||||||
const api = new LosslessAPI(apiSettings);
|
const api = new LosslessAPI(apiSettings);
|
||||||
|
|
||||||
const audioPlayer = document.getElementById('audio-player');
|
const audioPlayer = document.getElementById('audio-player');
|
||||||
|
|
@ -385,22 +411,9 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
// Initialize tracker
|
// Initialize tracker
|
||||||
initTracker(player);
|
initTracker(player);
|
||||||
|
|
||||||
// Initialize desktop environment (Neutralino)
|
if (typeof window !== 'undefined' && window.Neutralino && (window.NL_MODE || window.location.port === '5050')) {
|
||||||
if (window.Neutralino) {
|
console.log('[App] Starting Discord RPC...');
|
||||||
console.log('Initializing Neutralino desktop environment (Lite Mode)...');
|
initializeDiscordRPC(player);
|
||||||
try {
|
|
||||||
Neutralino.init();
|
|
||||||
|
|
||||||
// Register events immediately
|
|
||||||
Neutralino.events.on('windowClose', () => {
|
|
||||||
Neutralino.app.exit();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Start RPC immediately after init
|
|
||||||
initializeDiscordRPC(player);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to initialize desktop environment:', error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const castBtn = document.getElementById('cast-btn');
|
const castBtn = document.getElementById('cast-btn');
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ export function initializeDiscordRPC(player) {
|
||||||
if (player.currentTrack) {
|
if (player.currentTrack) {
|
||||||
sendUpdate(player.currentTrack, player.audio.paused);
|
sendUpdate(player.currentTrack, player.audio.paused);
|
||||||
} else {
|
} else {
|
||||||
|
console.log('[DiscordRPC] Sending idling heartbeat...');
|
||||||
const idlingData = {
|
const idlingData = {
|
||||||
details: 'Idling',
|
details: 'Idling',
|
||||||
state: 'Monochrome',
|
state: 'Monochrome',
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@
|
||||||
"main": "sw.js",
|
"main": "sw.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build && npx neu build",
|
"build": "vite build",
|
||||||
|
"build:desktop": "vite build --mode neutralino && npx neu build && node -e \"const fs = require('fs'); fs.cpSync('extensions', 'dist/Monochrome/extensions', {recursive: true}); fs.copyFileSync('neutralino.config.json', 'dist/Monochrome/neutralino.config.json')\"",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"start": "vite preview",
|
"start": "vite preview",
|
||||||
"lint:js": "eslint .",
|
"lint:js": "eslint .",
|
||||||
|
|
|
||||||
|
|
@ -3,50 +3,55 @@ import { VitePWA } from 'vite-plugin-pwa';
|
||||||
import neutralino from 'vite-plugin-neutralino';
|
import neutralino from 'vite-plugin-neutralino';
|
||||||
import authGatePlugin from './vite-plugin-auth-gate.js';
|
import authGatePlugin from './vite-plugin-auth-gate.js';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
base: './',
|
const IS_NEUTRALINO = mode === 'neutralino';
|
||||||
build: {
|
|
||||||
outDir: 'www',
|
return {
|
||||||
emptyOutDir: true,
|
base: './',
|
||||||
},
|
build: {
|
||||||
plugins: [
|
outDir: IS_NEUTRALINO ? 'www' : 'dist',
|
||||||
neutralino(),
|
emptyOutDir: IS_NEUTRALINO,
|
||||||
authGatePlugin(),
|
},
|
||||||
VitePWA({
|
plugins: [
|
||||||
registerType: 'prompt',
|
IS_NEUTRALINO && neutralino(),
|
||||||
workbox: {
|
authGatePlugin(),
|
||||||
globPatterns: ['**/*.{js,css,html,ico,png,svg,json}'],
|
VitePWA({
|
||||||
cleanupOutdatedCaches: true,
|
registerType: 'prompt',
|
||||||
maximumFileSizeToCacheInBytes: 3 * 1024 * 1024, // 3 MiB limit
|
workbox: {
|
||||||
// Define runtime caching strategies
|
globPatterns: ['**/*.{js,css,html,ico,png,svg,json}'],
|
||||||
runtimeCaching: [
|
cleanupOutdatedCaches: true,
|
||||||
{
|
maximumFileSizeToCacheInBytes: 3 * 1024 * 1024, // 3 MiB limit
|
||||||
urlPattern: ({ request }) => request.destination === 'image',
|
// Define runtime caching strategies
|
||||||
handler: 'CacheFirst',
|
runtimeCaching: [
|
||||||
options: {
|
{
|
||||||
cacheName: 'images',
|
urlPattern: ({ request }) => request.destination === 'image',
|
||||||
expiration: {
|
handler: 'CacheFirst',
|
||||||
maxEntries: 100,
|
options: {
|
||||||
maxAgeSeconds: 60 * 24 * 60 * 60, // 60 Days
|
cacheName: 'images',
|
||||||
|
expiration: {
|
||||||
|
maxEntries: 100,
|
||||||
|
maxAgeSeconds: 60 * 24 * 60 * 60, // 60 Days
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
urlPattern: ({ request }) =>
|
||||||
urlPattern: ({ request }) => request.destination === 'audio' || request.destination === 'video',
|
request.destination === 'audio' || request.destination === 'video',
|
||||||
handler: 'CacheFirst',
|
handler: 'CacheFirst',
|
||||||
options: {
|
options: {
|
||||||
cacheName: 'media',
|
cacheName: 'media',
|
||||||
expiration: {
|
expiration: {
|
||||||
maxEntries: 50,
|
maxEntries: 50,
|
||||||
maxAgeSeconds: 60 * 24 * 60 * 60, // 60 Days
|
maxAgeSeconds: 60 * 24 * 60 * 60, // 60 Days
|
||||||
|
},
|
||||||
|
rangeRequests: true, // Support scrubbing
|
||||||
},
|
},
|
||||||
rangeRequests: true, // Support scrubbing
|
|
||||||
},
|
},
|
||||||
},
|
],
|
||||||
],
|
},
|
||||||
},
|
includeAssets: ['instances.json', 'discord.html'],
|
||||||
includeAssets: ['instances.json', 'discord.html'],
|
manifest: false, // Use existing public/manifest.json
|
||||||
manifest: false, // Use existing public/manifest.json
|
}),
|
||||||
}),
|
],
|
||||||
],
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue