fix(updater): dispatch setFeedURL by provider instead of raw url

This commit is contained in:
2026-06-08 07:11:28 +05:30
parent aeadde5f40
commit 6df1389cc8
4 changed files with 36 additions and 11 deletions
+2 -5
View File
@@ -1,13 +1,10 @@
const { ipcMain } = require('electron'); const { ipcMain } = require('electron');
const { resolveFeedUrl } = require('../updater/feed-config'); const { feedConfigFor } = require('../updater/feed-config');
function register({ updater, getMainWindow, getChannel }) { function register({ updater, getMainWindow, getChannel }) {
ipcMain.handle('updater:check', async () => { ipcMain.handle('updater:check', async () => {
const channel = getChannel(); const channel = getChannel();
const version = require('electron').app.getVersion(); updater.autoUpdater.setFeedURL(feedConfigFor(channel));
const platform = process.platform;
const feed = resolveFeedUrl(channel, version, platform);
updater.autoUpdater.setFeedURL({ url: feed.replace(/\/latest-[^/]+\.yml$/, '') });
await updater.check(); await updater.check();
return { state: updater.state }; return { state: updater.state };
}); });
+8 -1
View File
@@ -28,4 +28,11 @@ function resolveFeedUrl(channel, version, platform) {
return feedForChannel(channel, version, platform); return feedForChannel(channel, version, platform);
} }
module.exports = { resolveFeedUrl, FEEDS }; function feedConfigFor(channel) {
if (channel === 'github') {
return { provider: 'github', owner: 'amitwh', repo: 'markdown-converter' };
}
return { provider: 'generic', url: 'https://updates.concreteinfo.co.in/v5' };
}
module.exports = { resolveFeedUrl, feedConfigFor, FEEDS };
+8 -3
View File
@@ -27,9 +27,14 @@ export const useSettingsStore = create<SettingsState>()(
}, },
onRehydrateStorage: () => (state) => { onRehydrateStorage: () => (state) => {
if (!state) return; if (!state) return;
const result = settingsSchema.safeParse(state); try {
if (!result.success) { const result = settingsSchema.safeParse(state);
console.warn('[settings-store] invalid persisted state, resetting to defaults', result.error); if (!result.success) {
console.warn('[settings-store] invalid persisted state, resetting to defaults', result.error);
useSettingsStore.setState({ ...DEFAULTS } as any);
}
} catch (err) {
console.warn('[settings-store] rehydration failed, resetting to defaults', err);
useSettingsStore.setState({ ...DEFAULTS } as any); useSettingsStore.setState({ ...DEFAULTS } as any);
} }
}, },
+18 -2
View File
@@ -1,4 +1,4 @@
const { resolveFeedUrl, FEEDS } = require('../../../../src/main/updater/feed-config'); const { resolveFeedUrl, feedConfigFor, FEEDS } = require('../../../../src/main/updater/feed-config');
describe('feed-config', () => { describe('feed-config', () => {
test('resolves github channel to GitHub Releases feed', () => { test('resolves github channel to GitHub Releases feed', () => {
@@ -30,4 +30,20 @@ describe('feed-config', () => {
expect(FEEDS.github).toBeDefined(); expect(FEEDS.github).toBeDefined();
expect(FEEDS.concreteinfo).toBeDefined(); expect(FEEDS.concreteinfo).toBeDefined();
}); });
}); });
describe('feedConfigFor', () => {
test('returns github provider config for github channel', () => {
const config = feedConfigFor('github');
expect(config).toEqual({ provider: 'github', owner: 'amitwh', repo: 'markdown-converter' });
});
test('returns generic provider config for concreteinfo channel', () => {
const config = feedConfigFor('concreteinfo');
expect(config).toEqual({ provider: 'generic', url: 'https://updates.concreteinfo.co.in/v5' });
});
test('falls back to generic provider on unknown channel', () => {
const config = feedConfigFor('something-weird');
expect(config).toEqual({ provider: 'generic', url: 'https://updates.concreteinfo.co.in/v5' });
});
});