Skip to content

Commit

Permalink
fix issues while app open after click on pod6 file
Browse files Browse the repository at this point in the history
  • Loading branch information
zag committed Aug 16, 2020
1 parent e3467ad commit 0cf6d96
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 13 deletions.
10 changes: 5 additions & 5 deletions app/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ export class App extends EventEmitter {
async run() {
// restore windows
const tmpstate = await this.load('app.json') || {windows:[]}
console.log({tmpstate})
if (tmpstate.windows.length < 1 ) {
if (tmpstate.windows.length < 1 && this.windowsPull.all().length < 1 ) {
// create window dd
this.createWindow({id:0})
} else {
tmpstate.windows.map(async (opt) => this.createWindow(opt))

}
console.log({'sata':this.windowsPull.getState()})
await this.store('app.json', this.windowsPull.getState())
}

Expand All @@ -46,7 +44,7 @@ export class App extends EventEmitter {
})
}

async createWindow( options: WindowConfig) {
async createWindow( options: WindowConfig, isSkipSaveState:boolean = false ) {
let id = options.id || this.windowsPull.getNextId()
const win = new Window( { ...options, id })
this.windowsPull.add(win)
Expand All @@ -59,7 +57,9 @@ export class App extends EventEmitter {
if (!this.quitting) {
await this.closeWindow(win) }
})
await this.store('app.json', this.windowsPull.getState())
if (!isSkipSaveState) {
await this.store('app.json', this.windowsPull.getState())
}
}

async closeWindow(win:Window) {
Expand Down
27 changes: 26 additions & 1 deletion app/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { App } from './app'
import update from './update'
import log from 'electron-log'

const fs = require('fs')
const { BrowserWindow, app, ipcMain, dialog } = require('electron')
const setMainMenu = require('./menu').default
Expand Down Expand Up @@ -60,12 +62,35 @@ app.on('will-finish-launching', () => {
})
})


const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
}

if (process.platform === "win32") {
const filePath = process.argv[1];
if (filePath ) initOpenFileQueue.push(filePath)

}

app.on("second-instance", (event, argv) => {
if (argv[3]) {
mainApp.createWindow( {id:0,filePath: argv[3]} )
}
else {
log.info("no argv[3]")
// TODO::
// lastFocusedWin().focus();
}
});
app.on('ready', () => {
setMainMenu(mainApp)
mainApp.run()
if (initOpenFileQueue.length) {
initOpenFileQueue.forEach((file) => mainApp.createWindow ({id:0,filePath: file}))
initOpenFileQueue.forEach( (file) => mainApp.createWindow( {id:0,filePath: file}, true ) )
} else {

console.log('openFileDialog(undefined, true)')
// openFileInReader(undefined, undefined, true)
// openFileDialog(undefined, true)
Expand Down
4 changes: 2 additions & 2 deletions app/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function menuLabel(label) {
const openAbout = () => {
openAboutWindow({
icon_path: join(__dirname, 'icon.png'),
copyright: `Copyright (c) 2020 Alexandr Zahatski <br/><p style="text-align:center">pod6: ${version}</p>`,
copyright: `Copyright (c) 2020 Alexandr Zahatski, https://zahatski.com <br/><p style="text-align:center">pod6: ${version}</p>`,
package_json_dir: __dirname,
bug_report_url: BUG_REPORT_URL,
homepage: HOME_PAGE,
Expand Down Expand Up @@ -102,7 +102,7 @@ const openAbout = () => {
{ role: 'selectAll' },
],
}

if (!is.macos) {
(helpMenu.submenu as MenuItemConstructorOptions[]).push({
label: `About ${app.name}`,
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"build/**",
"!build/**/*.map"
],

"afterPack": "./assets/after-pack.js",
"afterSign": "electron-builder-notarize",
"mac": {
Expand Down Expand Up @@ -192,12 +191,13 @@
"typescript": "^3.5.2"
},
"dependencies": {
"pod6": "^0.0.23",
"about-window": "1.13.4",
"app-root-path": "^2.2.1",
"electron-is-dev": "^1.1.0",
"electron-log": "^4.2.4",
"electron-updater": "^4.3.4",
"electron-util": "^0.14.2",
"about-window": "1.13.4",
"mousetrap-global-bind": "^1.1.0"
"mousetrap-global-bind": "^1.1.0",
"pod6": "^0.0.23"
}
}
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ abbrev@1:
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==

about-window@^1.13.4:
about-window@1.13.4:
version "1.13.4"
resolved "https://registry.yarnpkg.com/about-window/-/about-window-1.13.4.tgz#cedfd0153c4b8b54832acae6dae695e06f27f4b4"
integrity sha512-Ge7qBRzrmPbVJ2YarUfTrZEaSfhRjeVyFhmH9NqdNDjjgP0dcWwUprH61JWlDgcM3KaDn5zUzimG4YQh6vRocw==
Expand Down Expand Up @@ -3209,6 +3209,11 @@ electron-is-dev@^1.1.0:
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-1.1.0.tgz#b15a2a600bdc48a51a857d460e05f15b19a2522c"
integrity sha512-Z1qA/1oHNowGtSBIcWk0pcLEqYT/j+13xUw/MYOrBUOL4X7VN0i0KCTf5SqyvMPmW5pSPKbo28wkxMxzZ20YnQ==

electron-log@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-4.2.4.tgz#a13e42a9fc42ca2cc7d2603c3746352efa82112e"
integrity sha512-CXbDU+Iwi+TjKzugKZmTRIORIPe3uQRqgChUl19fkW/reFUn5WP7dt+cNGT3bkLV8xfPilpkPFv33HgtmLLewQ==

electron-notarize@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/electron-notarize/-/electron-notarize-0.2.1.tgz#759e8006decae19134f82996ed910db26d9192cc"
Expand Down

0 comments on commit 0cf6d96

Please sign in to comment.