os-js / OS.js

OS.js - JavaScript Web Desktop Platform
https://www.os-js.org/
Other
6.88k stars 819 forks source link

Application won't reopen after closing #786

Closed iAmKeyvan72 closed 2 years ago

iAmKeyvan72 commented 2 years ago

Hello, I developed an application for OSJS and it is working well. The problem is after closing the app, it won't be reopen by clicking from the menu and for reopening the app I have to refresh the entire OSJS tab and again open the app. Is there anything that I have to check?

here is my index.js for loading the window:

import './index.scss';

import osjs from 'osjs';
import { name as applicationName } from './metadata.json';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './src';

const register = (core, args, options, metadata) => {
  const proc = core.make('osjs/application', { args, options, metadata });
  const win = proc.createWindow({
    id: 'SimorghWindow',
    title: core.make('osjs/locale').translatableFlat(proc.metadata.title),
    icon: proc.resource(metadata.icon),
    dimension: { width: 1024, height: 800 },
    position: { left: 200, top: 50 },
    attributes: {
      minDimension: { width: 1024, height: 800 },
      sessionable: true,
    },
  });

  // window.addEventListener('resize', setWindowState);

  win.on('render', () => {
    win.maximize();
    win.focus();
  });

  win.render(($content) => {
    ReactDOM.render(<App core={core} win={win} proc={proc} />, $content);
  });
  return proc;
};

osjs.register(applicationName, register);

and here is my metadata.json file:

{
  "type": "application",
  "name": "Simorgh",
  "category": "utilities",
  "server": "server.js",
  "icon": "/assets/packageIcon.png",
  "singleton": true,
  "title": {
    "en_EN": "Simorgh",
    "fa_FA": "سیمرغ"
  },
  "description": {
    "en_EN": "Simorgh",
    "fa_FA": "سیمرغ"
  },
  "files": ["main.js", "main.css"]
}

I would appreciate your help.

andersevenrud commented 2 years ago

This is because you never destroy your app instance. Usually this is done when you close your main window :)

win.on('destroy', () => proc.destroy())