Skip to content

Commit

Permalink
#6 move common logic in app folder
Browse files Browse the repository at this point in the history
  • Loading branch information
motorina0 committed Jun 1, 2021
1 parent 429094f commit 03ff612
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 70 deletions.
5 changes: 5 additions & 0 deletions src/components/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div class="p-3">
<router-view></router-view>
</div>
</template>
49 changes: 49 additions & 0 deletions src/views/app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import browser from "webextension-polyfill";
import Vue from 'vue'
import VueRouter from 'vuerouter'
import Quasar from 'quasar'
import App from '../../components/App.vue'
import routes from './routes'

// Mozilla's polyfill
Vue.prototype.$browser = browser
Vue.use(VueRouter)
Vue.use(Quasar)

async function init(elementId = 'app') {
const router = new VueRouter({
routes
})

// TODO: extract
const serverResult = await browser.storage.sync.get({
serverUrl: ''
})
const serverUrl = serverResult.serverUrl

const result = await browser.storage.sync.get({
user: ''
})
const user = result.user

if (serverUrl && user && user.id && user.wallets && user.wallets.length) {
router.replace({
path: 'lnbits',
query: {
userId: user.id,
walletId: user.wallets[0].id
},
})
} else {
router.replace('/connect')
}


new Vue({
el: `#${elementId}`,
router,
render: (h) => h(App),
})
}

export default init
File renamed without changes.
24 changes: 2 additions & 22 deletions src/views/options/options.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
import Vue from 'vue'
import VueRouter from 'vuerouter'
import Quasar from 'quasar'
import Options from '../../components/Options.vue'
import routes from './routes'
import app from '../app/app'


// Mozilla's polyfill
Vue.prototype.$browser = require('webextension-polyfill')
Vue.use(VueRouter)
Vue.use(Quasar)


const router = new VueRouter({
routes
})
router.replace('/foo')

new Vue({
el: '#options',
router,
render: (h) => h(Options),
})
app('options')
50 changes: 2 additions & 48 deletions src/views/popup/popup.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,3 @@
import browser from "webextension-polyfill";
import Vue from 'vue'
import VueRouter from 'vuerouter'
import Quasar from 'quasar'
import Popup from '../../components/Popup.vue'
import routes from './routes'
import app from '../app/app'

// Mozilla's polyfill
Vue.prototype.$browser = browser
Vue.use(VueRouter)
Vue.use(Quasar)

async function init() {
const router = new VueRouter({
routes
})

// TODO: extract
const serverResult = await browser.storage.sync.get({
serverUrl: ''
})
const serverUrl = serverResult.serverUrl

const result = await browser.storage.sync.get({
user: ''
})
const user = result.user

if (serverUrl && user && user.id && user.wallets && user.wallets.length) {
router.replace({
path: 'lnbits',
query: {
userId: user.id,
walletId: user.wallets[0].id
},
})
} else {
router.replace('/connect')
}


new Vue({
el: '#popup',
router,
render: (h) => h(Popup),
})
}

init()
app('popup')

0 comments on commit 03ff612

Please sign in to comment.