Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments please: #359

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/html/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@ exports.create = function (api) {
return nest('app.html.app', app)

function app (initialTabs) {
var saveTabs = api.settings.sync.get('patchbay.saveTabs')
var _initialTabs

if (saveTabs) {
_initialTabs = api.settings.sync.get('patchbay.openTabs')
} else {
_initialTabs = api.settings.sync.get('patchbay.defaultTabs')
}

return h('App', api.app.html.tabs({
initial: initialTabs || api.settings.sync.get('patchbay.defaultTabs')
initial: initialTabs || _initialTabs
}))
}
}
41 changes: 41 additions & 0 deletions app/html/settings/save-tabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const nest = require('depnest')
const { h } = require('mutant')

exports.gives = nest({
'app.html.settings': true
})


exports.needs = nest({
'app.html.settings': 'map',
'settings.obs.get': 'first',
'settings.sync.set': 'first'
})

exports.create = function (api) {
return nest({
'app.html.settings': saveTabs
})

function saveTabs () {
const saveTabs = api.settings.obs.get('patchbay.saveTabs', false)
const toggleSaveTabs = (ev) => {
api.settings.sync.set({ patchbay: { saveTabs: ev.target.checked } })
}

return {
group: 'general',
title: 'Save Tabs',
body: h('SaveTabsStyles', [
h('p', [
'Save open tabs when Patchbay is closed',
h('input', {
type: 'checkbox',
checked: saveTabs,
'ev-change': toggleSaveTabs
})
])
])
}
}
}
25 changes: 24 additions & 1 deletion app/html/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ exports.needs = nest({
'app.sync.goTo': 'first',
'app.sync.locationId': 'first',
'history.obs.store': 'first',
'history.sync.push': 'first'
'history.sync.push': 'first',
'settings.obs.get': 'first',
'settings.sync.set': 'first'
})

exports.create = function (api) {
Expand Down Expand Up @@ -44,6 +46,27 @@ exports.create = function (api) {
return api.app.sync.locationId(loc) !== page.id
})
history.set(prunedHistory)

const defaultTabs = api.settings.obs.get('patchbay.defaultTabs', false)

const saveTabs = api.settings.obs.get('patchbay.saveTabs', false)
if (saveTabs()) {
const openTabs = api.settings.obs.get('patchbay.openTabs', [])
var _openTabs = openTabs()

var closedTab = JSON.parse(page.id)
var theTab = Object.values(closedTab)[0]

if (closedTab.page) {
theTab = '/' + theTab
}

var index = _openTabs.indexOf(theTab)
if (index !== -1) {
_openTabs.splice(index, 1)
api.settings.sync.set({ patchbay: { openTabs: _openTabs } })
}
}
}

const search = api.app.html.searchBar()
Expand Down
22 changes: 21 additions & 1 deletion app/sync/go-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ exports.needs = nest({
'history.obs.store': 'first',
'history.sync.push': 'first',
'router.async.normalise': 'first',
'router.async.router': 'first'
'router.async.router': 'first',
'settings.obs.get': 'first',
'settings.sync.set': 'first'
})

exports.create = function (api) {
Expand Down Expand Up @@ -59,6 +61,24 @@ exports.create = function (api) {
page.id = page.id || locationId
tabs.add(page, !openBackground, split)

// Save Tabs: If enabled then add it to default tabs.
const saveTabs = api.settings.obs.get('patchbay.saveTabs', false)
if (saveTabs()) {
const openTabs = api.settings.obs.get('patchbay.openTabs', [])
var _tabs = openTabs()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using const, why not use let instead of var to be a tiny bit more strict regarding variable access?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx... will do.
I "think" I can use api.settings.sync.get rather than obs.get too


var newTab = Object.values(loc)[0]
if (loc.page) {
newTab = '/' + newTab
}

if (_tabs.indexOf(newTab) === -1) {
_tabs.push(newTab)

api.settings.sync.set({ patchbay: { openTabs: _tabs } })
}
}

if (openBackground) {
const history = api.history.obs.store()
var _history = history()
Expand Down