2018-03-02 04:48:12 +01:00
|
|
|
/*
|
2018-08-03 04:18:08 +02:00
|
|
|
This file is part of FreeTube.
|
|
|
|
FreeTube is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
FreeTube is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with FreeTube. If not, see <http://www.gnu.org/licenses/>.
|
2018-03-02 04:48:12 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-03-06 05:22:12 +01:00
|
|
|
* A file for functions used for settings.
|
|
|
|
*/
|
2018-03-02 04:48:12 +01:00
|
|
|
|
|
|
|
/**
|
2018-03-06 05:22:12 +01:00
|
|
|
* Display the settings screen to the user.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
2018-06-25 22:04:11 +02:00
|
|
|
function updateSettingsView() {
|
2018-03-02 04:48:12 +01:00
|
|
|
/*
|
2018-03-06 05:22:12 +01:00
|
|
|
* Check the settings database for the user's current settings. This is so the
|
|
|
|
* settings page has the correct toggles related when it is rendered.
|
|
|
|
*/
|
2018-03-02 04:48:12 +01:00
|
|
|
settingsDb.find({}, (err, docs) => {
|
|
|
|
docs.forEach((setting) => {
|
|
|
|
switch (setting['_id']) {
|
|
|
|
case 'theme':
|
2018-03-06 05:22:12 +01:00
|
|
|
if (currentTheme == '') {
|
2018-03-02 04:48:12 +01:00
|
|
|
currentTheme = setting['value'];
|
|
|
|
}
|
|
|
|
}
|
2018-07-24 03:11:56 +02:00
|
|
|
});
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-03-11 19:15:54 +01:00
|
|
|
// Check / uncheck the switch depending on the user's settings.
|
|
|
|
if (currentTheme === 'light') {
|
2018-06-25 22:04:11 +02:00
|
|
|
settingsView.useTheme = false;
|
2018-03-11 19:15:54 +01:00
|
|
|
} else {
|
2018-06-25 22:04:11 +02:00
|
|
|
settingsView.useTheme = true;
|
2018-03-11 19:15:54 +01:00
|
|
|
}
|
2018-06-02 00:17:33 +02:00
|
|
|
|
|
|
|
if (useTor) {
|
2018-06-25 22:04:11 +02:00
|
|
|
settingsView.useTor = true;
|
2018-06-02 00:17:33 +02:00
|
|
|
} else {
|
2018-06-25 22:04:11 +02:00
|
|
|
settingsView.useTor = false;
|
2018-06-02 00:17:33 +02:00
|
|
|
}
|
2018-09-19 20:34:23 +02:00
|
|
|
|
|
|
|
if (rememberHistory) {
|
|
|
|
settingsView.history = true;
|
|
|
|
} else {
|
|
|
|
settingsView.history = false;
|
|
|
|
}
|
2018-09-21 16:49:23 +02:00
|
|
|
|
|
|
|
if (autoplay) {
|
|
|
|
settingsView.autoplay = true;
|
|
|
|
} else {
|
|
|
|
settingsView.autoplay = false;
|
|
|
|
}
|
|
|
|
|
2018-09-24 20:19:43 +02:00
|
|
|
if (enableSubtitles) {
|
2018-09-21 16:49:23 +02:00
|
|
|
settingsView.subtitles = true;
|
|
|
|
} else {
|
|
|
|
settingsView.subtitles = false;
|
2018-09-24 20:19:43 +02:00
|
|
|
}
|
2018-09-21 16:49:23 +02:00
|
|
|
|
|
|
|
if (checkForUpdates) {
|
|
|
|
settingsView.updates = true;
|
|
|
|
} else {
|
|
|
|
settingsView.updates = false;
|
|
|
|
}
|
2018-09-24 20:19:43 +02:00
|
|
|
|
|
|
|
document.getElementById('qualitySelect').value = defaultQuality;
|
|
|
|
document.getElementById('rateSelect').value = defaultPlaybackRate;
|
2018-03-02 04:48:12 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-06 05:22:12 +01:00
|
|
|
* Check the user's default settings. Set the the default settings if none are found.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function checkDefaultSettings() {
|
|
|
|
|
2018-06-02 00:17:33 +02:00
|
|
|
let newSetting;
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-06-02 00:17:33 +02:00
|
|
|
let settingDefaults = {
|
|
|
|
'theme': 'light',
|
2018-09-19 20:34:23 +02:00
|
|
|
'useTor': false,
|
|
|
|
'history': true,
|
2018-09-21 16:49:23 +02:00
|
|
|
'autoplay': true,
|
|
|
|
'subtitles': false,
|
|
|
|
'updates': true,
|
2018-09-24 20:19:43 +02:00
|
|
|
'quality': '720',
|
|
|
|
'rate': '1',
|
2018-06-02 00:17:33 +02:00
|
|
|
};
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
console.log(settingDefaults);
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
for (let key in settingDefaults){
|
|
|
|
settingsDb.find({_id: key}, (err, docs) => {
|
|
|
|
if (jQuery.isEmptyObject(docs)) {
|
|
|
|
newSetting = {
|
|
|
|
_id: key,
|
|
|
|
value: settingDefaults[key]
|
|
|
|
};
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
settingsDb.insert(newSetting);
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-06-02 00:17:33 +02:00
|
|
|
if (key == 'theme'){
|
|
|
|
setTheme('light');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
switch (docs[0]['_id']) {
|
2018-03-02 04:48:12 +01:00
|
|
|
case 'theme':
|
2018-06-02 00:17:33 +02:00
|
|
|
setTheme(docs[0]['value']);
|
2018-03-02 04:48:12 +01:00
|
|
|
break;
|
2018-06-02 00:17:33 +02:00
|
|
|
case 'useTor':
|
|
|
|
useTor = docs[0]['value'];
|
|
|
|
break;
|
2018-09-19 20:34:23 +02:00
|
|
|
case 'history':
|
|
|
|
rememberHistory = docs[0]['value'];
|
|
|
|
break;
|
2018-09-21 16:49:23 +02:00
|
|
|
case 'autoplay':
|
|
|
|
autoplay = docs[0]['value'];
|
|
|
|
break;
|
|
|
|
case 'subtitles':
|
|
|
|
enableSubtitles = docs[0]['value'];
|
|
|
|
break;
|
|
|
|
case 'updates':
|
|
|
|
checkForUpdates = docs[0]['value'];
|
|
|
|
|
|
|
|
if (checkForUpdates) {
|
|
|
|
updateChecker(options, function (error, update) { // callback function
|
|
|
|
if (error) throw error;
|
|
|
|
if (update) { // print some update info if an update is available
|
|
|
|
confirmFunction(update.name + ' is now available! Would you like to download the update?', openReleasePage);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
2018-09-24 20:19:43 +02:00
|
|
|
case 'quality':
|
|
|
|
defaultQuality = docs[0]['value'];
|
|
|
|
break;
|
|
|
|
case 'rate':
|
|
|
|
defaultPlaybackRate = docs[0]['value'];
|
|
|
|
break;
|
2018-03-02 04:48:12 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-06-02 00:17:33 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-06 05:22:12 +01:00
|
|
|
* Updates the settings based on what the user has changed.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function updateSettings() {
|
2018-08-03 04:18:08 +02:00
|
|
|
let themeSwitch = document.getElementById('themeSwitch').checked;
|
|
|
|
let torSwitch = document.getElementById('torSwitch').checked;
|
2018-09-19 20:34:23 +02:00
|
|
|
let historySwitch = document.getElementById('historySwitch').checked;
|
2018-09-21 16:49:23 +02:00
|
|
|
let autoplaySwitch = document.getElementById('autoplaySwitch').checked;
|
|
|
|
let subtitlesSwitch = document.getElementById('subtitlesSwitch').checked;
|
|
|
|
let updatesSwitch = document.getElementById('updatesSwitch').checked;
|
2018-09-24 20:19:43 +02:00
|
|
|
let qualitySelect = document.getElementById('qualitySelect').value;
|
|
|
|
let rateSelect = document.getElementById('rateSelect').value;
|
2018-08-03 04:18:08 +02:00
|
|
|
let theme = 'light';
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-09-19 20:34:23 +02:00
|
|
|
settingsView.useTor = torSwitch;
|
|
|
|
settingsView.history = historySwitch;
|
2018-09-21 16:49:23 +02:00
|
|
|
settingsView.autoplay = autoplaySwitch;
|
|
|
|
settingsView.subtitles = subtitlesSwitch;
|
|
|
|
settingsView.updates = updatesSwitch;
|
2018-09-19 20:34:23 +02:00
|
|
|
rememberHistory = historySwitch;
|
2018-09-24 20:19:43 +02:00
|
|
|
defaultQuality = qualitySelect;
|
|
|
|
defaultPlaybackRate = rateSelect;
|
2018-09-19 20:34:23 +02:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
if (themeSwitch === true) {
|
|
|
|
theme = 'dark';
|
|
|
|
}
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-03-02 04:48:12 +01:00
|
|
|
// Update default theme
|
2018-03-06 05:22:12 +01:00
|
|
|
settingsDb.update({
|
|
|
|
_id: 'theme'
|
|
|
|
}, {
|
|
|
|
value: theme
|
|
|
|
}, {}, function(err, numReplaced) {
|
2018-03-02 04:48:12 +01:00
|
|
|
console.log(err);
|
|
|
|
console.log(numReplaced);
|
|
|
|
});
|
|
|
|
|
2018-06-02 00:17:33 +02:00
|
|
|
// Update tor usage.
|
|
|
|
settingsDb.update({
|
|
|
|
_id: 'useTor'
|
|
|
|
}, {
|
|
|
|
value: torSwitch
|
|
|
|
}, {}, function(err, numReplaced) {
|
|
|
|
console.log(err);
|
|
|
|
console.log(numReplaced);
|
|
|
|
useTor = torSwitch;
|
|
|
|
});
|
|
|
|
|
2018-09-21 16:49:23 +02:00
|
|
|
// Update history
|
2018-09-19 20:34:23 +02:00
|
|
|
settingsDb.update({
|
|
|
|
_id: 'history'
|
|
|
|
}, {
|
2018-09-21 16:49:23 +02:00
|
|
|
value: historySwitch
|
2018-09-19 20:34:23 +02:00
|
|
|
}, {}, function(err, numReplaced) {
|
|
|
|
console.log(err);
|
|
|
|
console.log(numReplaced);
|
2018-09-21 16:49:23 +02:00
|
|
|
rememberHistory = historySwitch;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Update autoplay.
|
|
|
|
settingsDb.update({
|
|
|
|
_id: 'autoplay'
|
|
|
|
}, {
|
|
|
|
value: autoplaySwitch
|
|
|
|
}, {}, function(err, numReplaced) {
|
|
|
|
console.log(err);
|
|
|
|
console.log(numReplaced);
|
|
|
|
autoplay = autoplaySwitch;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Update subtitles.
|
|
|
|
settingsDb.update({
|
|
|
|
_id: 'subtitles'
|
|
|
|
}, {
|
|
|
|
value: subtitlesSwitch
|
|
|
|
}, {}, function(err, numReplaced) {
|
|
|
|
console.log(err);
|
|
|
|
console.log(numReplaced);
|
|
|
|
enableSubtitles = subtitlesSwitch;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Update checkForUpdates.
|
|
|
|
settingsDb.update({
|
|
|
|
_id: 'updates'
|
|
|
|
}, {
|
|
|
|
value: updatesSwitch
|
|
|
|
}, {}, function(err, numReplaced) {
|
|
|
|
console.log(err);
|
|
|
|
console.log(numReplaced);
|
|
|
|
checkForUpdates = updatesSwitch;
|
2018-09-19 20:34:23 +02:00
|
|
|
});
|
|
|
|
|
2018-09-24 20:19:43 +02:00
|
|
|
// Update default quality.
|
|
|
|
settingsDb.update({
|
|
|
|
_id: 'quality'
|
|
|
|
}, {
|
|
|
|
value: qualitySelect
|
|
|
|
}, {}, function(err, numReplaced) {
|
|
|
|
console.log(err);
|
|
|
|
console.log(numReplaced);
|
|
|
|
defaultQuality = qualitySelect;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Update default playback rate.
|
|
|
|
settingsDb.update({
|
|
|
|
_id: 'rate'
|
|
|
|
}, {
|
|
|
|
value: rateSelect
|
|
|
|
}, {}, function(err, numReplaced) {
|
|
|
|
console.log(err);
|
|
|
|
console.log(numReplaced);
|
|
|
|
defaultPlaybackRate = rateSelect;
|
|
|
|
});
|
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
showToast('Settings have been saved.');
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-06 05:22:12 +01:00
|
|
|
* Toggle back and forth with the current theme
|
|
|
|
*
|
|
|
|
* @param {boolean} themeValue - The value of the switch based on if it was turned on or not.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function toggleTheme(themeValue) {
|
2018-08-03 04:18:08 +02:00
|
|
|
if (themeValue.checked === true) {
|
|
|
|
setTheme('dark');
|
|
|
|
currentTheme = 'dark';
|
|
|
|
} else {
|
|
|
|
setTheme('light');
|
|
|
|
currentTheme = 'light';
|
|
|
|
}
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-06 05:22:12 +01:00
|
|
|
* Set the theme of the application
|
|
|
|
*
|
|
|
|
* @param {string} option - The theme to be changed to.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function setTheme(option) {
|
2018-08-03 04:18:08 +02:00
|
|
|
let cssFile;
|
|
|
|
const currentTheme = document.getElementsByTagName("link").item(1);
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
// Create a link element
|
|
|
|
const newTheme = document.createElement("link");
|
|
|
|
newTheme.setAttribute("rel", "stylesheet");
|
|
|
|
newTheme.setAttribute("type", "text/css");
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
// Grab the css file to be used.
|
|
|
|
switch (option) {
|
2018-03-02 04:48:12 +01:00
|
|
|
case 'light':
|
2018-08-03 04:18:08 +02:00
|
|
|
cssFile = './style/lightTheme.css';
|
|
|
|
document.getElementById('menuText').src = 'icons/textBlack.png';
|
|
|
|
document.getElementById('menuIcon').src = 'icons/iconBlack.png';
|
|
|
|
document.getElementById('menuButton').style.color = 'black';
|
2018-11-09 16:11:25 +01:00
|
|
|
document.getElementById('reloadButton').style.color = 'black';
|
2018-08-03 04:18:08 +02:00
|
|
|
break;
|
2018-03-02 04:48:12 +01:00
|
|
|
case 'dark':
|
2018-08-03 04:18:08 +02:00
|
|
|
cssFile = './style/darkTheme.css';
|
|
|
|
document.getElementById('menuText').src = 'icons/textColor.png';
|
|
|
|
document.getElementById('menuIcon').src = 'icons/iconColor.png';
|
|
|
|
document.getElementById('menuButton').style.color = 'white';
|
2018-11-09 16:11:25 +01:00
|
|
|
document.getElementById('reloadButton').style.color = 'white';
|
2018-08-03 04:18:08 +02:00
|
|
|
break;
|
2018-03-02 04:48:12 +01:00
|
|
|
default:
|
2018-08-03 04:18:08 +02:00
|
|
|
// Default to the light theme
|
|
|
|
cssFile = './style/lightTheme.css';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
newTheme.setAttribute("href", cssFile);
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
// Replace the current theme with the new theme
|
|
|
|
document.getElementsByTagName("head").item(0).replaceChild(newTheme, currentTheme);
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
|
|
|
|
2018-03-04 05:24:31 +01:00
|
|
|
/**
|
2018-08-03 04:18:08 +02:00
|
|
|
* Import Subscriptions from an OPML file.
|
|
|
|
*
|
|
|
|
* @param {string} subFile - The file location of the OPML file.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function importOpmlSubs(json){
|
|
|
|
if(!json[0]['folder'].includes('YouTube')){
|
|
|
|
showToast('Invalid OPML File. Import is unsuccessful.');
|
|
|
|
return;
|
|
|
|
}
|
2018-03-04 05:24:31 +01:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
json.forEach((channel) => {
|
|
|
|
let channelId = channel['xmlurl'].replace('https://www.youtube.com/feeds/videos.xml?channel_id=', '');
|
2018-03-04 05:24:31 +01:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
addSubscription(channelId, false);
|
|
|
|
});
|
|
|
|
window.setTimeout(displaySubs, 1000);
|
|
|
|
showToast('Subscriptions have been imported!');
|
|
|
|
return;
|
2018-03-04 05:24:31 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 04:48:12 +01:00
|
|
|
/**
|
2018-08-03 04:18:08 +02:00
|
|
|
* Import a subscriptions file that the user provides.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function importSubscriptions(){
|
|
|
|
const appDatabaseFile = localDataStorage + '/subscriptions.db';
|
|
|
|
|
|
|
|
// Open user's file browser. Only show .db files.
|
|
|
|
dialog.showOpenDialog({
|
|
|
|
properties: ['openFile'],
|
|
|
|
filters: [
|
|
|
|
{name: 'Database File', extensions: ['*']},
|
|
|
|
]
|
|
|
|
}, function(fileLocation){
|
|
|
|
if(typeof(fileLocation) === 'undefined'){
|
|
|
|
console.log('Import Aborted');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log(fileLocation);
|
|
|
|
let i = fileLocation[0].lastIndexOf('.');
|
|
|
|
let fileType = (i < 0) ? '' : fileLocation[0].substr(i);
|
|
|
|
console.log(fileType);
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-03-02 04:48:12 +01:00
|
|
|
fs.readFile(fileLocation[0], function(readErr, data){
|
|
|
|
if(readErr){
|
|
|
|
showToast('Unable to read file. File may be corrupt or have invalid permissions.');
|
|
|
|
throw readErr;
|
|
|
|
}
|
2018-03-04 05:24:31 +01:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
if (data.includes("<opml")){
|
|
|
|
getOpml(data, function (error, json){
|
|
|
|
if (!error){
|
2018-07-24 03:11:56 +02:00
|
|
|
clearFile('subscriptions', false);
|
2018-08-03 04:18:08 +02:00
|
|
|
importOpmlSubs(json['children'][0]['children']);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (fileType !== '.db'){
|
|
|
|
showToast('Incorrect file type. Import unsuccessful.');
|
|
|
|
return;
|
|
|
|
}
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
clearFile('subscriptions', false);
|
|
|
|
|
|
|
|
fs.writeFile(appDatabaseFile, data, function(writeErr){
|
|
|
|
if(writeErr){
|
|
|
|
showToast('Unable to create file. Please check your permissions and try again.');
|
|
|
|
throw writeErr;
|
|
|
|
}
|
|
|
|
showToast('Susbcriptions have been successfully imported. Please restart FreeTube for the changes to take effect.');
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-06 05:22:12 +01:00
|
|
|
* Export the susbcriptions database to a file.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function exportSubscriptions() {
|
2018-08-03 04:18:08 +02:00
|
|
|
const appDatabaseFile = localDataStorage + '/subscriptions.db';
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
const date = new Date();
|
|
|
|
let dateMonth = date.getMonth() + 1;
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
if (dateMonth < 10){
|
|
|
|
dateMonth = '0' + dateMonth;
|
|
|
|
}
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
let dateDay = date.getDate();
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
if (dateDay < 10){
|
|
|
|
dateDay = '0' + dateDay;
|
|
|
|
}
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
const dateYear = date.getFullYear();
|
|
|
|
const dateString = 'freetube-subscriptions-' + dateYear + '-' + dateMonth + '-' + dateDay;
|
|
|
|
|
|
|
|
// Open user file browser. User gives location of file to be created.
|
|
|
|
dialog.showSaveDialog({
|
|
|
|
defaultPath: dateString,
|
|
|
|
filters: [{
|
|
|
|
name: 'Database File',
|
|
|
|
extensions: ['db']
|
|
|
|
}, ]
|
|
|
|
}, function(fileLocation) {
|
|
|
|
console.log(fileLocation);
|
|
|
|
if (typeof(fileLocation) === 'undefined') {
|
|
|
|
console.log('Export Aborted');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fs.readFile(appDatabaseFile, function(readErr, data) {
|
|
|
|
if (readErr) {
|
|
|
|
throw readErr;
|
|
|
|
}
|
|
|
|
fs.writeFile(fileLocation, data, function(writeErr) {
|
|
|
|
if (writeErr) {
|
|
|
|
throw writeErr;
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
2018-08-03 04:18:08 +02:00
|
|
|
showToast('Susbcriptions have been successfully exported');
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-03 04:18:08 +02:00
|
|
|
* Clear out the data in a file.
|
|
|
|
*
|
|
|
|
* @param {string} type - The type of file to be cleared.
|
|
|
|
*/
|
|
|
|
function clearFile(type, showMessage = true){
|
|
|
|
console.log(type);
|
|
|
|
let dataBaseFile;
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
switch (type) {
|
2018-03-02 04:48:12 +01:00
|
|
|
case 'subscriptions':
|
2018-08-03 04:18:08 +02:00
|
|
|
dataBaseFile = localDataStorage + '/subscriptions.db';
|
|
|
|
break;
|
2018-03-02 04:48:12 +01:00
|
|
|
case 'history':
|
2018-08-03 04:18:08 +02:00
|
|
|
dataBaseFile = localDataStorage + '/videohistory.db';
|
|
|
|
break;
|
2018-03-02 04:48:12 +01:00
|
|
|
case 'saved':
|
2018-08-03 04:18:08 +02:00
|
|
|
dataBaseFile = localDataStorage + '/savedvideos.db';
|
|
|
|
break;
|
2018-03-02 04:48:12 +01:00
|
|
|
default:
|
2018-08-03 04:18:08 +02:00
|
|
|
showToast('Unknown file: ' + type)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace data with an empty string.
|
|
|
|
fs.writeFile(dataBaseFile, '', function(err) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
2018-03-04 05:24:31 +01:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
if (showMessage){
|
|
|
|
showToast('File has been cleared. Restart FreeTube to see the changes');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-07-24 03:11:56 +02:00
|
|
|
|
2018-06-25 22:04:11 +02:00
|
|
|
checkDefaultSettings();
|