Skip to content

Commit

Permalink
electron dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminDreasond committed Aug 14, 2023
1 parent 3c2185a commit df7f574
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@
"vite-plugin-electron-renderer": "^0.14.1",
"vite-plugin-static-copy": "0.16.0"
}
}
}
26 changes: 1 addition & 25 deletions src/client/initMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,7 @@ import { cryptoCallbacks } from './state/secretStorageKeys';
import navigation from './state/navigation';
import logger from './logger';

if (__ENV_APP__.electron_mode) {
global.Olm = {

// eslint-disable-next-line object-shorthand
init: function () {

const args = [];
for (const item in arguments) {
args.push(arguments[item]);
}

if (!args[0]) args.push({});
args[0].locateFile = () => '/olm.wasm';

global.Olm = Olm;

// eslint-disable-next-line prefer-spread
Olm.init.apply(Olm, args);

}

};
} else {
global.Olm = Olm;
}
global.Olm = Olm;

class InitMatrix extends EventEmitter {
constructor() {
Expand Down
72 changes: 58 additions & 14 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ const copyFiles = {
dest: 'js/',
},

{
src: 'node_modules/@matrix-org/olm/olm.wasm',
dest: '',
},
{
src: 'config/config.json',
dest: '',
Expand Down Expand Up @@ -100,6 +96,32 @@ export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const electronMode = (String(env.ELECTRON_MODE) === 'true');

const envData = {
mode,
command,
electron_mode: electronMode,
info: {
name: String(env.appName),
welcome: String(env.appWelcome)
}
};

if (electronMode && mode === 'development') {

envData.maindir = __dirname;

copyFiles.targets.push({
src: 'node_modules/@matrix-org/olm/olm.wasm',
dest: path.join(envData.maindir, './node_modules/electron/dist/resources/electron.asar/renderer/'),
});

} else {
copyFiles.targets.push({
src: 'node_modules/@matrix-org/olm/olm.wasm',
dest: '',
});
}

// Result object
const result = {

Expand All @@ -108,15 +130,7 @@ export default defineConfig(({ command, mode }) => {
base: "",

define: {
__ENV_APP__: Object.freeze({
mode,
command,
electron_mode: electronMode,
info: {
name: String(env.appName),
welcome: String(env.appWelcome)
}
}),
__ENV_APP__: Object.freeze(envData),
},

server: {
Expand Down Expand Up @@ -237,4 +251,34 @@ export default defineConfig(({ command, mode }) => {
// Complete
return result;

});
});

/*
if (__ENV_APP__.electron_mode) {
global.Olm = {
// eslint-disable-next-line object-shorthand
init: function () {
const args = [];
for (const item in arguments) {
args.push(arguments[item]);
}
if (!args[0]) args.push({});
args[0].locateFile = () => '/olm.wasm';
global.Olm = Olm;
// eslint-disable-next-line prefer-spread
Olm.init.apply(Olm, args);
}
};
} else {
global.Olm = Olm;
}
*/

0 comments on commit df7f574

Please sign in to comment.