Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
lib-window
Browse files Browse the repository at this point in the history
  • Loading branch information
turarabu committed Sep 25, 2019
1 parent 2ad0a92 commit e458b54
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 5 deletions.
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
last 1 versions
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store

# custom ignore
gui
node_modules
package-lock.json

Expand Down
8 changes: 8 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require('path')

module.exports = {
dir: {
app: __dirname,
gui: path.join(__dirname, 'gui')
}
}
71 changes: 71 additions & 0 deletions core/window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const path = require('path')
const { BrowserWindow } = require('electron')
const config = require('../config')

const list = {}
const defaults = {
icon: path.join(config.dir.gui, 'icon.ico'),
show: false,
frame: false,
webPreferences: {
nodeIntegration: false,
preload: path.join(config.dir.gui, 'script/ipc.js'),
webSecurity: true
}
}

module.exports = { exists, custom, open, load }

function exists (window) {
return list[window] instanceof BrowserWindow
}

function custom (name, options) {
return new Promise((resolve, reject) => {
if ( this.exists(name) === true )
return reject(`window ${name} already exists`)

else {
list[name] = new BrowserWindow(options)
return resolve(list[name])
}
})
}

function open (name, extra = {}) {
var options = extraOptions(defaults, extra)

return new Promise((resolve, reject) => {
this.custom(name, options)
.then(handle)
.catch(reject)

function handle (window) {
window.loadFile( path.join(config.dir.gui, `${name}.html`) )
window.once('ready-to-show', () => {
window.show()
resolve(window)
})
}
})
}

function load (window) {
return new Promise((resolve, reject) => {
if ( this.exists(window) === true )
return resolve(list[window])

else return reject(`window ${name} not exists`)
})
}

// Helper functions
function extraOptions (...options) {
var copy = {}

options.forEach(obj => {
Object.assign(copy, JSON.parse(JSON.stringify(obj)))
})

return copy
}
File renamed without changes.
24 changes: 19 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
"version": "0.2.0",
"description": "AniLibria Cross-Platform Application",
"main": "main.js",
"scripts": {
"start": "electron .",
"serve": "vue-cli-service build --watch --mode=development",
"build": "vue-cli-service build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/anilibria/cross-app.git"
"url": "git+https://github.com/anilibria/electron.git"
},
"keywords": [
"AniLibria",
Expand All @@ -18,10 +23,19 @@
},
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/anilibria/cross-app/issues"
"url": "https://github.com/anilibria/electron/issues"
},
"homepage": "https://github.com/anilibria/cross-app#readme",
"devDependencies": {
"electron": "^6.0.10"
"homepage": "https://github.com/anilibria/electron#readme",
"devDependencies": {
"@vue/cli-service": "^3.11.0",
"electron": "^6.0.10",
"pug": "^2.0.4",
"pug-plain-loader": "^1.0.0",
"raw-loader": "^3.1.0",
"stylus": "^0.54.7",
"stylus-loader": "^3.0.2",
"vue": "^2.6.10",
"vue-router": "^3.1.3",
"vue-template-compiler": "^2.6.10"
}
}
Binary file added public/icon.ico
Binary file not shown.
30 changes: 30 additions & 0 deletions vue.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require('path')

const pages = {}
const root = __dirname

for (let page of loads)
pages[page] = {
entry: path.join(root, 'source', `${page}.js`),
template: path.join(root, 'public', `${page}.html`),
filename: `${page}.html`
}

module.exports = {
publicPath: './',
pages: pages,
filenameHashing: false,
productionSourceMap: false,
outputDir: path.join(root, 'gui'),
configureWebpack: {
resolve: {
alias: {
'root': root,
':root': root,

'src': path.join(root, 'source'),
':src': path.join(root, 'source')
}
}
}
}

0 comments on commit e458b54

Please sign in to comment.