I am doing one simple Project using Electron, React and SQLite Database.
Everything working fine in locally with my readymade database.
After Build it wouldn't works as expected. I need to upload My database to %Appdata% folder.
Please help me to do this.
To Connect DB I use this.
const path = require('path');
const dbdatapath=path.join(app.getPath('userData'), "db.sqlite3");
const database = new sqlite3.Database(dbdatapath, (err) => {
if (err){ console.log('Database opening error: '+ err);}
else{
console.error('Database Connected sucess ');
}
});
I have some Predefined Master Data to work this App.
I need to upload Database when Install. Or let us know any other way to achieve this?
Related
Hello fellow developers/programmers. Today I come to ask for help with something, and is that I'm making an app that if or if it has to be portable, the problem I'm having is that when writing a zip file the app does not find the directories or generates the zip corruptly.
My code that writes the zip file looks like this:
ipcMain.on("report-file", async (event, data) => {
let zipFilePath = "report.zip"
let output = fs.createWriteStream(zipFilePath);
let archive = archiver("zip")
archive.pipe(output);
if (data.saves) {
archive.directory(`game/saves`, false)
archive.directory(`game/cache`, false)
}
archive.append(fs.createReadStream(`log.txt`), {
name: `log.txt`,
})
archive.append(fs.createReadStream(`traceback.txt`), {
name: `traceback.txt`,
})
archive.finalize()
});
Electron Version: 21.2.3
SO: Windows 11
electron-builder Version: 23.6.0
Looking a little more in depth, I found that the app is using the address
C:\User\User\AppData\Local\Temp\[id]\resources\app.asar
and it is trying to compress the files as if they were in that path, however, the files to compress are located where the .exe is. (G:\myapp\dist)
I already tried to fix it by following an old post on the stackoverflow page, however, it didn't solve the problem, so today I decided to ask my question here, do you have any idea how to get the actual path of an electron js portable app?
I found the solution to this, and it was to create a dialog with electron, and load the folder location. Then use resolve together with the address of the executable, this way it loads correctly the address of the folder where the exe is located.
let dir
dir = await dialog.showOpenDialog(win, {
properties: ['openDirectory'],
defaultPath: path.resolve('.', process.env.PORTABLE_EXECUTABLE_DIR)
});
It's my first time using Electron JS and nodejs. I've built a small app that reads some records from a database and updates them. Everything is working fine. I have a config file with the database credentials but when I build a portable win app, I cannot figure out how to read the config file that I would like to place next to the exe. I would like to have easy access to the file, so I could run the same app on different databases.
Can anyone tell me if what I want is possible and how? I already tried to get the exe location but I couldn't. I also read a lot of topics here but nothing seems to solve my problem (I might be doing something wrong).
I'm using electron-builder to build my app.
Thanks in advance.
Edit #1
My Config file is
{
"user" :"X",
"password" :"X",
"server":"X",
"database":"X",
"options":
{
"trustedconnection": true,
"enableArithAbort" : true,
"trustServerCertificate": true
}
}
This is what I've and works when I run the project with npm start
const configRootPath = path.resolve(__dirname,'dbConfig.json');
dbConfig = JSON.parse(fs.readFileSync(configRootPath, { encoding: 'utf-8' }));
However, when I build it, the app is looking for the file in another location different from the one where the executable is.
Use of Electron's app.getPath(name) function will get you the path(s) you are after, irrespective of which OS (Operating System) you are using.
Unless your application writes your dbConfig.json file, it may be difficult for your user to understand exactly where they should place their database config file as each OS will run and store your application data in a different directory. You would need to be explicit to the user as to where to place their config file(s). Alternatively, your application could create the config file(s) on the user's behalf (automatically or through a html form) and save it to a location 'known' to the application.
A common place where application specific config files are stored is in the user's application data directory. With the application name automatically amended to the directory, it can be found as shown below.
const electronApp = require('electron').app;
let appUserDataPath = electronApp.getPath('userData');
console.log(appUserDataPath );
In your use case, the below would apply.
const electronApp = require('electron').app;
const nodeFs = require('fs');
const nodePath = require('path');
const configRootPath = nodePath.join(electronApp.getPath('userData'), 'dbConfig.json');
dbConfig = JSON.parse(nodeFs.readFileSync(configRootPath, 'utf-8'));
console.log(configRootPath);
console.log(dbConfig);
You can try electron-store to store config.
Electron doesn't have a built-in way to persist user preferences and other data. This module handles that for you, so you can focus on building your app. The data is saved in a JSON file named config.json in app.getPath('userData').
I was working on a project that need some files to be downloaded into storage and later works offline . I am using Expo's Filesystem api to download the file and then saving the file in Expo FileSystem.documentDirectory
let directory = FileSystem.documentDirectory + 'media/';
await FileSystem.downloadAsync(imageurl,
directory + 'filename.jpg'
)
.then(({ uri }) => {
console.log(uri,'uri of image')
});
The problem is when i was updating app in itunesconnect the data is not persisting.
I guess you are trying to recover that file with absolute path after the update. Use a relative path instead.
iOS will update UUID of directory each time you change your build (ex. different builds on TestFlight or different version on AppStore).
ref: https://github.com/expo/expo/issues/4261#issuecomment-494072115
What you need to do is to store the filename into some persistent storage and combine that with FileSystem.documentDirectory to recover that file later, because your file is saved and the relative path works fine but the absolute path has changed.
Here is an example of copying an image into the document directory and recover that file later.
const to = FileSystem.documentDirectory + filename
await FileSystem.copyAsync({
from: uri, // uri to the image file
to
})
dispatch({ type: 'STORE_FILENAME', filename }) // Anything that persists. I use redux-persist
// ...after you updated the app to a different build
const filename = props.filename // recovered from the previous build anyhow
const uri = FileSystem.documentDirectory + filename
// maybe you want to render that image
return <Image uri={uri} />
I am updating the app store with an Ionic version of an old Titanium/Alloy app. The Alloy sql.js sync adapter has:
var ALLOY_DB_DEFAULT = "_alloy_";
A backup of a phone running the old app made with iExplorer contains the file:
(App)/Library/Private Documents/_alloy_.sql
Can I access this database like this in Ionic?
db = window.sqlitePlugin.openDatabase({
name: '_alloy_.sql',
location: 1,
})
I am trying to run the old app and test the migration, but Titanium Studio is very difficult to get going at this point. My migration works well if I just stuff the old _alloy_.sql file into the iOS Simulator at:
~/Library/Developer/CoreSimulator/Devices/<id>/data/Containers/Data/Application/<id>/Library/
Old thread response, hopefully someone still finds the answer useful.
We've solved our own bounty.
The database is stored in the IOS Library in the 'Private Data' directory with the filename _alloy_.sql
let tiAppOptions = {name: "Private Documents/_alloy_.sql", iosDatabaseLocation: 'Library'};
this.sqlite.create(tiAppOptions).then((db: SQLiteObject) => {
db.executeSql("SELECT * from table_name", {}).then((data) => {
//do something with the data.
});
}, err => {
console.log(err);
});
Android is stored in the 'default' location with filename _alloy_.sql
After worked on many small addon i want to put those add on on my server so that people can download it and use it so that i can get the feedback from the people ..but when i am downloading it from my server(it is a xpi file) getting following error..
Firefox could not install the file at
http://abhimanyu.homeunix.com/Work/abhiman_2k5#yahoo.com.xpi
because: Install script not found
-204
but when i m putting these files manually in the path it works fine..After fiddling many hours couldn't figure it out whats the problem ...please help me.
I assume that you are letting the users download your add-on through some install button.
Unfortunately, its not as simple as pointing the browser to the xpi file on the server's file system. Below, I have pasted the script that installs Omture when the user presses on the "Download Omture" button on the add-on's website which you could also find using firebug.
function installExt()
{
var url="omture_current.xpi";
InstallTrigger.install({
"Omture": { URL: url,
toString : function() { return this.URL; } } });
return false;
}