CI/CD / preconditions (pull_request) Successful in 1s
Native JavaScript checks / Native launcher and release tests (pull_request) Successful in 1m2s
macOS checks / Native Rust tests and unsigned build (pull_request) Successful in 1m38s
CI/CD / test_and_check_app (pull_request) Successful in 6m47s
CI/CD / Publish immutable image (pull_request) Skipped
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
(() => {
|
|
if (
|
|
window !== window.top ||
|
|
location.protocol !== 'https:' ||
|
|
window.kanbanNative
|
|
) {
|
|
return;
|
|
}
|
|
const handler = window.webkit?.messageHandlers?.kanbanSettings;
|
|
if (!handler) {
|
|
return;
|
|
}
|
|
let sequence = 0;
|
|
const actions = new Set([
|
|
'getState',
|
|
'settingsReady',
|
|
'openSettings',
|
|
'setWorkspace',
|
|
'checkForUpdates',
|
|
'setUpdatePreferences',
|
|
'installUpdate',
|
|
]);
|
|
Object.defineProperty(window, 'kanbanNative', {
|
|
value: Object.freeze({
|
|
version: 1,
|
|
async request(action, payload = {}) {
|
|
if (!actions.has(action)) {
|
|
throw new Error('unsupportedAction');
|
|
}
|
|
const message = JSON.stringify({
|
|
version: 1,
|
|
id: ++sequence,
|
|
action,
|
|
payload,
|
|
});
|
|
let timer;
|
|
try {
|
|
const response = await Promise.race([
|
|
handler.postMessage(message).then(JSON.parse),
|
|
new Promise((_, reject) => {
|
|
timer = setTimeout(
|
|
() => reject(new Error('bridgeTimeout')),
|
|
10000,
|
|
);
|
|
}),
|
|
]);
|
|
if (response.error) {
|
|
throw new Error(response.error);
|
|
}
|
|
return response.result;
|
|
} finally {
|
|
clearTimeout(timer);
|
|
}
|
|
},
|
|
}),
|
|
});
|
|
window.dispatchEvent(new Event('kanban-native-ready'));
|
|
})();
|