Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #16 from igor725/dev
Browse files Browse the repository at this point in the history
Fix updater
  • Loading branch information
igor725 authored Jun 5, 2024
2 parents 91ad34d + 6151f88 commit ae8f14d
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 39 deletions.
7 changes: 7 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ const commandHandler = (channel, cmd, info) => {
config.updateMultipleKeys(info);
settwin.close();
break;
case 'sett-forceupg':
updateWorker.postMessage({ act: 'run-check', force: true, notify: true });
break;

default:
console.error('Unhandled command: ', cmd);
Expand Down Expand Up @@ -584,6 +587,10 @@ const main = (userdir = __dirname) => {
win.send('warnmsg', { hidden: false, type: 'text', id: 'upd-nobin', text: '{$tr:updater.warns.noemu}', trparams: msg, buttons: ['{$tr:buttons.ye}', '{$tr:buttons.ig}', '{$tr:buttons.cl}'] });
break;

case 'noupd':
genericWarnMsg('{$tr:updater.warns.noupd}', true);
break;

case 'progress':
win.send('warnmsg-upd', { id: 'upd-progr', progress: msg.value });
break;
Expand Down
14 changes: 9 additions & 5 deletions services/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ const loadJSON = (url, headers = undefined) =>
});
});

const triggerCheck = async (force) => {
const noupdNotify = () => parentPort.postMessage({ resp: 'noupd' });

const triggerCheck = async ({ force, notify }) => {
const binpath = searchBinary();

let currver = 'v.0.0';
Expand Down Expand Up @@ -128,7 +130,7 @@ const triggerCheck = async (force) => {
} else {
throw new Error('No assets in the latest release!');
}
}
} else if (notify) noupdNotify();
} else {
throw new Error(`REST /releases failed: ${resp.message}`);
}
Expand All @@ -139,15 +141,15 @@ const triggerCheck = async (force) => {
return;
}

const resp = await loadJSON('https://api.github.com/repos/SysRay/psOff_public/actions/runs?per_page=1&branch=features&status=completed');
const resp = await loadJSON('https://api.github.com/repos/SysRay/psOff_public/actions/runs?per_page=1&branch=features&status=success');
if (resp.total_count > 0) {
const run = resp.workflow_runs[0];
const newver = run.id;

if (newver != currver) {
newverinfo.url = '_' + run.artifacts_url;
newverinfo.tag = newver.toString();
}
} else if (notify) noupdNotify();
} else {
throw new Error(`REST /actions failed: ${resp.message}`);
}
Expand All @@ -172,6 +174,8 @@ const download = async (url, version, headers = undefined) => {
}

return download(art.archive_download_url, version, headers);
} else if (resp.total_count === 0) {
throw new Error('No artifacts were generated for this run!');
}

throw new Error(`REST /artifacts failed: ${resp.message}`);
Expand Down Expand Up @@ -268,7 +272,7 @@ const commandHandler = async (msg) => {

case 'run-check':
validateEmulatorPath();
await triggerCheck(msg.force);
await triggerCheck(msg);
break;

case 'download':
Expand Down
74 changes: 42 additions & 32 deletions webroot/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,45 +351,55 @@ window._onLangReady = (() => {
});

wrapper.on('click', ({ target }) => {
const elemid = target.dataset.setpathto;
if (!elemid) return;
window.electronAPI.selectFolder().then((path) => {
const elem = document.getElementById(elemid);
elem.value = path;
elem.dispatchEvent(new Event('input', { bubbles: true }));
});
}, true);
switch (target.id) {
case 'gsd-add': {
const path = $('#gsd-path').value;
if (!path) return;

$('#gsd-add').on('click', () => {
const path = $('#gsd-path').value;
if (!path) return;
if (modified_cfg[1].scan_dirs === undefined) {
modified_cfg[1].scan_dirs = Object.assign({}, saved_cfg[1].scan_dirs);
}

if (modified_cfg[1].scan_dirs === undefined) {
modified_cfg[1].scan_dirs = Object.assign({}, saved_cfg[1].scan_dirs);
}
modified_cfg[1].scan_dirs[path] = ($('#gsd-depth').selectedIndex + 1);
refillScanDirs(modified_cfg);
} break;

modified_cfg[1].scan_dirs[path] = ($('#gsd-depth').selectedIndex + 1);
refillScanDirs(modified_cfg);
});
case 'gsd-remove': {
const path = $('#gsd-path').value;
if (!path) return;

$('#gsd-remove').on('click', () => {
const path = $('#gsd-path').value;
if (!path) return;
if (modified_cfg[1].scan_dirs === undefined) {
modified_cfg[1].scan_dirs = Object.assign({}, saved_cfg[1].scan_dirs);
}

if (modified_cfg[1].scan_dirs === undefined) {
modified_cfg[1].scan_dirs = Object.assign({}, saved_cfg[1].scan_dirs);
/**
* If we want _isSimilar to return valid result then this object
* should not change its size and loose keys, so delete is not an
* option there. Making object's value undefined has no side effects
* as it seems. JSON will not save undefined keys, but it's still there
* for _isSimilar.
*/
modified_cfg[1].scan_dirs[path] = undefined;
refillScanDirs(modified_cfg);
} break;

case 'forceupd': {
window.electronAPI.sendCommand('sett-forceupg');
window.close();
} break;

default: {
const elemid = target.dataset.setpathto;
if (!elemid) return;
window.electronAPI.selectFolder().then((path) => {
const elem = document.getElementById(elemid);
elem.value = path;
elem.dispatchEvent(new Event('input', { bubbles: true }));
});
} break;
}

/**
* If we want _isSimilar to return valid result then this object
* should not change its size and loose keys, so delete is not an
* option there. Making object's value undefined has no side effects
* as it seems. JSON will not save undefined keys, but it's still there
* for _isSimilar.
*/
modified_cfg[1].scan_dirs[path] = undefined;
refillScanDirs(modified_cfg);
});
}, true);

gsd.on('change', ({ target }) => {
$('#gsd-path').value = target.options[target.selectedIndex].dataset.folder;
Expand Down
1 change: 1 addition & 0 deletions webroot/js/warnmsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
const wrap = $('#wrapper');

if (data.hidden) {
if (data.id !== warn.dataset.wid) return;
wrap.dataset.ready = 1;
warn.dataset.active = 0;
return;
Expand Down
4 changes: 3 additions & 1 deletion webroot/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"monthly": "Monthly"
}
},
"updforce": "Force update check",
"doubleclick": "Doubleclick will run the game",
"drpc": "Enable Discord Rich Presence",
"gsd": {
Expand Down Expand Up @@ -105,7 +106,8 @@
"warns": {
"newver": "New version of psOff emulator is available! Do you want to download it? (Installed: {currver}, New: {newver})",
"noemu": "Looks like you have no psOff emulator installed. Would you like the launcher to download the latest release ({latest})?",
"downproc": "Downloading the emulator binaries, hang tight..."
"downproc": "Downloading the emulator binaries, hang tight...",
"noupd": "You're already using the latest emulator version!"
},
"errors": {
"checkfail": "Failed to check updates for your psOff installation: {error}",
Expand Down
4 changes: 3 additions & 1 deletion webroot/langs/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"monthly": "Ежемесячно"
}
},
"updforce": "Принудительная проверка обновлений",
"doubleclick": "Двойное нажатие запускает игру",
"drpc": "Включить Discord Rich Presence",
"gsd": {
Expand Down Expand Up @@ -92,7 +93,8 @@
"warns": {
"newver": "Доступна новая версия эмулятора psOff! Хотите скачать её? (Установлена: {currver}, Новая: {newver})",
"noemu": "Похоже, что у вас не установлен эмулятор psOff. Хотите скачать последний релиз ({latest})?",
"downproc": "Скачиваю эмулятор..."
"downproc": "Скачиваю эмулятор...",
"noupd": "Последняя версия уже установлена!"
},
"errors": {
"checkfail": "Не удалось проверить обновления: {error}",
Expand Down
3 changes: 3 additions & 0 deletions webroot/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<option data-cfgvalue="monthly" eo-translator="settings.launcher.updfr.opt.monthly"></option>
</select>
</div>
<div class="row">
<button id="forceupd" style="flex: 1;" eo-translator="settings.launcher.updforce"></button>
</div>
<div class="row">
<label for="dblcl" eo-translator="settings.launcher.doubleclick"></label>
<input type="checkbox" data-cfgfacility="launcher" data-cfgkey="dblcl_run" />
Expand Down

0 comments on commit ae8f14d

Please sign in to comment.