electronでtodoアプリを作成しています。
画面のサイズと位置を保存して、次回起動時に復元する処理をしています。
下記のコマンドで結果がことなるのですが1のコマンドでも期待通り動かしたいと思います。
ご教授お願いいたします。
よろしくお願いいたします。
1.asar pack
2.electron-packager
1のコマンドを使用するとパッケージする前に保存した画面サイズと位置で起動しますが
サイズ、位置を変更して再起動してもパッケージ前に保存したサイズと位置で起動してしまいます。
2のコマンドを使用した場合は期待通り動きます。
os :winsows7
version
electron:1.4.13
node.js:6.10.2
javascript
1const {app, BrowserWindow, Menu} = require('electron'); 2const path = require('path'); 3const url = require('url'); 4 5 6let win; 7 8function createWindow () { 9 // Create the browser window. 10 try{ 11 var setWin = require("./setWin.json"); 12 win = new BrowserWindow(setWin); 13 }catch(e){ 14 win = new BrowserWindow({width: 800, height: 600, x: 0, y: 0, show: false}); 15 } 16 17 win.once('ready-to-show', () => { win.show(); }); 18 win.loadURL(url.format({ 19 pathname: path.join(__dirname, 'index.html'), 20 protocol: 'file:', 21 slashes: true 22 })); 23 24 var settings_path = require('path').join(__dirname, 'setWin.json'); 25 26 win.on('close', function() { 27 var fs = require('fs'); 28 var item = win.getBounds(); 29 item = '{' + '"x":' + item['x'] + ',' + '"y":' + item['y'] + ',' + '"width":' + item['width'] + ',' + '"height":' + item['height'] + ',' + '"show":false}' 30 31 fs.writeFileSync(settings_path, item); 32 33 }); 34 35 36 win.on('closed', () => { 37 38 win = null; 39 }) 40} 41 42app.on('ready', createWindow); 43 44const template = [ 45 { 46 label: 'Edit', submenu: [{role: 'undo'}, {role: 'redo'},{type: 'separator'},{role: 'cut'},{role: 'copy'},{role: 'paste'},{role: 'pasteandmatchstyle'}, 47 {role: 'delete'},{role: 'selectall'}] 48 }, 49 { 50 label: 'View',submenu: [{role: 'reload'},{role: 'toggledevtools'},{type: 'separator'},{role: 'zoomin'},{role: 'zoomout'},{type: 'separator'},{role: 'togglefullscreen'}] 51 }, 52 { 53 role: 'window',submenu: [{role: 'minimize'},{role: 'close'}] 54 } 55] 56const menu = Menu.buildFromTemplate(template) 57Menu.setApplicationMenu(menu) 58 59 60 61 62 63app.on('window-all-closed', () => { 64 65 if (process.platform !== 'darwin') { 66 app.quit(); 67 } 68}); 69 70app.on('activate', () => { 71 72 if (win === null) { 73 createWindow(); 74 } 75});
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/15 14:41