forked from thennothinghappened/GMEdit-Constructor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
73 lines (60 loc) · 2.01 KB
/
Copy pathinit.js
File metadata and controls
73 lines (60 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Evil workaround to use ES modules in a project that wasn't designed
* for them, because I like using them too much :)
*/
(() => {
const PLUGIN_NAME = 'GMEdit-Constructor';
const PLUGIN_VERSION = '0.24.1';
/** @type {NodeModules} */
const nodeModules = {
path: require('node:path'),
child_process: require('node:child_process')
};
/**
* Make sure we aren't running on rosetta, since GMEdit has
* a native build and Rosetta seems to cause some weirdness!
*/
function isRunningInRosetta() {
if (process.platform !== 'darwin') {
return false;
}
if (process.arch !== 'x64') {
return false;
}
const output = nodeModules.child_process
.execSync('sysctl -in sysctl.proc_translated')
.toString('utf-8');
// If the return of this command is 1, we are running in Rosetta.
return output.includes('1');
}
GMEdit.register(PLUGIN_NAME, {
init: async function(state) {
if (isRunningInRosetta()) {
return Electron_Dialog.showMessageBox({
title: 'GMEdit-Constructor cannot load on Rosetta!',
message: `${PLUGIN_NAME} does not work correctly on Rosetta - please consider using GMEdit's native Arm64 build found at https://yellowafterlife.itch.io/gmedit`,
buttons: ['Dismiss'],
type: 'error'
});
}
if (window.ConstructorPlugin !== undefined) {
window.ConstructorPlugin.destroy();
}
const res = await import('./js/ConstructorPlugin.js')
.then(({ ConstructorPlugin }) => ConstructorPlugin.initialize(PLUGIN_NAME, PLUGIN_VERSION, nodeModules, state.dir))
.catch(err => /** @type {Result<import('./js/ConstructorPlugin').ConstructorPlugin>} */ ({ ok: false, err }));
if (!res.ok) {
console.error('Failed to launch Constructor!', res.err);
alert('Failed to launch Constructor, see the JavaScript console for details.');
return;
}
window.ConstructorPlugin = res.data;
},
cleanup: function() {
if (window.ConstructorPlugin !== undefined) {
window.ConstructorPlugin?.destroy();
delete window.ConstructorPlugin;
}
}
});
})();