shitty prob not working implementation for auto-updates in the desktop app
This commit is contained in:
parent
db1d607603
commit
c074b48b0a
4 changed files with 119 additions and 1 deletions
26
.github/workflows/desktop-build.yml
vendored
26
.github/workflows/desktop-build.yml
vendored
|
|
@ -48,6 +48,16 @@ jobs:
|
||||||
- name: Download Neutralino binaries
|
- name: Download Neutralino binaries
|
||||||
run: bun x neu update
|
run: bun x neu update
|
||||||
|
|
||||||
|
- name: Auto-Bump Version
|
||||||
|
run: |
|
||||||
|
$json = Get-Content neutralino.config.json -Raw | ConvertFrom-Json
|
||||||
|
$v = $json.version.Split('.')
|
||||||
|
if ($v.Count -lt 2) { $v += "0" }
|
||||||
|
$newVersion = "{0}.{1}.{2}" -f $v[0], $v[1], ${{ github.run_number }}
|
||||||
|
$json.version = $newVersion
|
||||||
|
$json | ConvertTo-Json -Depth 5 | Set-Content neutralino.config.json
|
||||||
|
shell: pwsh
|
||||||
|
|
||||||
- name: Build application
|
- name: Build application
|
||||||
run: bun run build
|
run: bun run build
|
||||||
|
|
||||||
|
|
@ -82,6 +92,20 @@ jobs:
|
||||||
mv ${{ matrix.archive_name }} out_delivery/
|
mv ${{ matrix.archive_name }} out_delivery/
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
|
- name: Generate Update Manifest
|
||||||
|
run: |
|
||||||
|
$config = Get-Content neutralino.config.json | ConvertFrom-Json
|
||||||
|
$version = $config.version
|
||||||
|
$platform = "${{ matrix.platform }}"
|
||||||
|
$archive = "${{ matrix.archive_name }}"
|
||||||
|
$json = @{
|
||||||
|
version = $version
|
||||||
|
url = "https://downloads.samidy.com/out_delivery/$archive"
|
||||||
|
notes = "Update $version is available."
|
||||||
|
}
|
||||||
|
$json | ConvertTo-Json | Set-Content "out_delivery/update-$platform.json"
|
||||||
|
shell: pwsh
|
||||||
|
|
||||||
- name: Upload to R2
|
- name: Upload to R2
|
||||||
uses: ryand56/r2-upload-action@latest
|
uses: ryand56/r2-upload-action@latest
|
||||||
with:
|
with:
|
||||||
|
|
@ -90,7 +114,7 @@ jobs:
|
||||||
r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
||||||
r2-bucket: ${{ secrets.R2_BUCKET }}
|
r2-bucket: ${{ secrets.R2_BUCKET }}
|
||||||
source-dir: 'out_delivery'
|
source-dir: 'out_delivery'
|
||||||
destination-dir: ''
|
destination-dir: 'out_delivery'
|
||||||
|
|
||||||
- name: Upload Artifact (GH Internal)
|
- name: Upload Artifact (GH Internal)
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|
|
||||||
20
index.html
20
index.html
|
|
@ -1719,6 +1719,19 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="desktop-update-modal" class="modal">
|
||||||
|
<div class="modal-overlay"></div>
|
||||||
|
<div class="modal-content">
|
||||||
|
<h3>Update Available</h3>
|
||||||
|
<p>A new version of Monochrome is available.</p>
|
||||||
|
<div id="desktop-update-notes" style="margin: 1rem 0; padding: 1rem; background: var(--background-secondary); border-radius: var(--radius); max-height: 200px; overflow-y: auto; font-size: 0.9rem;"></div>
|
||||||
|
<div class="modal-actions">
|
||||||
|
<button id="desktop-update-cancel" class="btn-secondary">Later</button>
|
||||||
|
<button id="desktop-update-confirm" class="btn-primary">Update Now</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="command-palette-overlay" style="display: none">
|
<div id="command-palette-overlay" style="display: none">
|
||||||
<div class="command-palette">
|
<div class="command-palette">
|
||||||
<div class="command-palette-header">
|
<div class="command-palette-header">
|
||||||
|
|
@ -5122,6 +5135,13 @@
|
||||||
<span class="slider"></span>
|
<span class="slider"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="setting-item" id="desktop-update-container" style="display: none">
|
||||||
|
<div class="info">
|
||||||
|
<span class="label">Desktop Update</span>
|
||||||
|
<span class="description">Check for updates to the desktop application</span>
|
||||||
|
</div>
|
||||||
|
<button id="check-desktop-updates-btn" class="btn-secondary">Check for Updates</button>
|
||||||
|
</div>
|
||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<span class="label">Analytics</span>
|
<span class="label">Analytics</span>
|
||||||
|
|
|
||||||
40
js/app.js
40
js/app.js
|
|
@ -411,6 +411,46 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
try {
|
try {
|
||||||
const desktopModule = await import('./desktop/desktop.js');
|
const desktopModule = await import('./desktop/desktop.js');
|
||||||
await desktopModule.initDesktop(player);
|
await desktopModule.initDesktop(player);
|
||||||
|
|
||||||
|
import('./desktop/neutralino-bridge.js').then(({ updater }) => {
|
||||||
|
setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
// my worker should detect a users OS and serve the right ver
|
||||||
|
const update = await updater.checkForUpdates('https://update.samidy.xyz/update.json');
|
||||||
|
|
||||||
|
if (update && update.available) {
|
||||||
|
const modal = document.getElementById('desktop-update-modal');
|
||||||
|
const notes = document.getElementById('desktop-update-notes');
|
||||||
|
const confirmBtn = document.getElementById('desktop-update-confirm');
|
||||||
|
const cancelBtn = document.getElementById('desktop-update-cancel');
|
||||||
|
|
||||||
|
if (modal) {
|
||||||
|
notes.innerHTML = update.notes || 'Bug fixes and improvements.';
|
||||||
|
modal.classList.add('active');
|
||||||
|
|
||||||
|
confirmBtn.onclick = async () => {
|
||||||
|
confirmBtn.disabled = true;
|
||||||
|
confirmBtn.textContent = 'Updating...';
|
||||||
|
try {
|
||||||
|
await updater.install();
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
confirmBtn.textContent = 'Failed';
|
||||||
|
setTimeout(() => {
|
||||||
|
confirmBtn.disabled = false;
|
||||||
|
confirmBtn.textContent = 'Update Now';
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
cancelBtn.onclick = () => modal.classList.remove('active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Failed to check for desktop updates:', e);
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load desktop module:', err);
|
console.error('Failed to load desktop module:', err);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,39 @@ export const filesystem = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updater = {
|
||||||
|
checkForUpdates: async (url) => {
|
||||||
|
if (!isNeutralino) return;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const id = Math.random().toString(36).substring(7);
|
||||||
|
const handler = (event) => {
|
||||||
|
if (event.data?.type === 'NL_RESPONSE' && event.data.id === id) {
|
||||||
|
window.removeEventListener('message', handler);
|
||||||
|
if (event.data.error) reject(event.data.error);
|
||||||
|
else resolve(event.data.result);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener('message', handler);
|
||||||
|
window.parent.postMessage({ type: 'NL_UPDATER_CHECK', id, url }, '*');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
install: async () => {
|
||||||
|
if (!isNeutralino) return;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const id = Math.random().toString(36).substring(7);
|
||||||
|
const handler = (event) => {
|
||||||
|
if (event.data?.type === 'NL_RESPONSE' && event.data.id === id) {
|
||||||
|
window.removeEventListener('message', handler);
|
||||||
|
if (event.data.error) reject(event.data.error);
|
||||||
|
else resolve(event.data.result);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener('message', handler);
|
||||||
|
window.parent.postMessage({ type: 'NL_UPDATER_INSTALL', id }, '*');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const _window = {
|
export const _window = {
|
||||||
minimize: async () => {
|
minimize: async () => {
|
||||||
if (!isNeutralino) return;
|
if (!isNeutralino) return;
|
||||||
|
|
@ -214,5 +247,6 @@ export default {
|
||||||
app,
|
app,
|
||||||
os,
|
os,
|
||||||
filesystem,
|
filesystem,
|
||||||
|
updater,
|
||||||
window: _window,
|
window: _window,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue