Node-webkit app- how to update it? - node-webkit

I am using node-webkit to develop apps for my students, and to provide one stop solution I would need to update node-webkit archive once in a month. Is there a way I can accomplish that?
Basically I need to replace just one html file every month, say "page1.html".
I googled but have no idea where to start.

On Mac, you can access the filesystem of the own app e.g.
$ ls -lh /Applications/Shock.app/Contents/Resources/app.nw/
[...]
-rw-r--r-- 1 jordi staff 2,3K 29 gen 01:47 index.html
-rw-r--r-- 1 jordi staff 467B 29 gen 01:47 lecturenotes.html
[...]
So if you put a new version on a specific URL, you could fetch it and rewrite the HTML file inside the app:
var request = require('request');
request('http://www.your-own-server.com/app/lecturenotes.html', function (error, response, body) {
if (!error && response.statusCode == 200) {
var fs = require('fs');
fs.writeFileSync('/Applications/Shock.app/Contents/Resources/app.nw/lecturenotes.html', body);
}
});
I think something similar happens on Linux. Unfortunately, the Windows version works with a binary package into the exe, so this trick won't work for the last case.

I have used App.dataPath as described in https://github.com/nwjs/nw.js/wiki/App
You can download the html files into that path. App.dataPath works platform independent , though the location is different based on the platforms , your app will have a generic path to refer the html files.
excerpt :
Get the application's data path in user's directory. Windows:
%LOCALAPPDATA%/; Linux: ~/.config/; OSX: ~/Library/Application
Support/ where is the field in the manifest.

Related

Nuxt 3 Server with Pug for email templates

I have created an endpoint with Nuxt 3 Server to send emails.
The email sending part is working great.
The styling of the email templates is done with Pug but I am having a hard time to get the path to the pug templates.
I suspect the issue is that the pug files are not being included in the build process.
When deployed to netlify which runs yarn build I get
"ENOENT: no such file or directory, open '~/views/email/welcome.pug'"
async send(template, subject) {
// 1) Render HTML based on a pug template
const html = pug.renderFile(
`~/views/email/${template}.pug`,
{
firstName: this.firstName,
url: this.url,
data: this.data,
subject
}
);
}
My project structure looks like this.
What would be the best way to handle this?
Since you want to send emails, you will a Node.js server somewhere. You could use Heroku and push your code there, then use yarn build && yarn start there.
Should fix your issue.
PS: yarn generate is for SSG, Netlify can handle those apps for free but it will not come with all the server capabilities.

Open file downloaded within React-Native app with another app

I am trying to open files (images, pdfs, videos, etc) downloaded with my React-Native app from my server.
So I'm using RNFetchBlob to download the file then I'm doing the following depending if it's an iOS or Android device:
openFile = (item, path) => {
if (Platform.OS === 'ios') {
RNFetchBlob.ios.previewDocument(path)
} else {
// I've tried setting a real mimetype instead of / but it still doesn't work
RNFetchBlob.android.actionViewIntent(path, '/')
}
}
On iOS it works as expected but nothing happens on Android even though I have apps that can read images, pdfs or videos on the device I'm testing on.
Any ideas why this doesn't work or how I could make the same thing with another library ?
Found out the reason for this, it's a know bug of the library and has a PR waiting to be merged (no timeframe from the repo owner).
Here is the link to the PR: https://github.com/joltup/rn-fetch-blob/pull/317
So basically this needs to be added to line 122-123 of file android/src/main/java/com/RNFetchBlob/RNFetchBlob.java:
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
If above is not working do to the below step:
overwrite the 121 line in android/src/main/java/com/RNFetchBlob/RNFetchBlob.java:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 121 line
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // 122 line

Can't find static assets from express/npm module

tldr;
My project is an NPM module that is used by an ExpressJS server. The server needs to specify an endpoint and my module will do the rest. How do I get my module to load the correct html page and grab the correct js/css files from the correct path?
The Problem
I'm running into a problem where I can see the directory structure of the site, using the serveIndex library, and all the files are in their correct directories but for some reason when I try to load any of the files, whether from the serveIndex view or from the actual endpoint where it should load, I get nothing but 404 errors.
Here's an example if someone wanted to use this NPM module from their project.
app.js (their server)
const express = require('express')
const { adminAreaConfig } = require('express-admin-area')
const app = express()
const adminArea = adminAreaConfig(express) // my module being passed the "express" library
app.use('/admin', adminArea) // specify a URL to use my module
app.listen(3000, () => console.log('\n\nServer Online\n\n'))
Here's an image of my projects dir structure after it's been built.
Going off of a console.log(__dirname), which returns <long path string>/express-admin-area/build/src, I then tell my module, using the express reference passed by the actual server in the code above, to look in the views directory with
... import libraries etc ...
const adminAreaConfig = express => {
const adminArea = express.Router()
adminArea.use('/', express.static(__dirname + '/views') // sets my modules views to the "http://localhost:3000/admin" path
adminArea.use('/dirs', serveIndex(__dirname)) // will get into this later
... some other stuff like exports etc ...
This then attempts to load the index.html file in the express-admin-area/build/src/views directory but fails because it can't locate the CSS and JS files inside express-admin-area/build/src/views/static/css or .../js.
First, I know it fails because instead of looking for http://localhost:3000/admin/static/css/styles.css it looks for http://localhost:3000/static/css/styles.css, so that's another problem I need to solve entirely.
Second, looking back at the small code sample above, adminArea.use('/dirs', serveIndex(__dirname)), I'm using the serveIndex library in an attempt to view the directory structure. If I go to http://localhost:3000/admin/dirs I get the correct directories and files in the browser
But now, if I try to view an actual file I'm met with the error Cannot GET /admin/dir/main.js for example if I were to go to http://localhost:3000/admin/dir/main.js, but I can continue going deeper in the directories if I wanted such as the controllers or routes directories from the image.
What I want
I need a way to get these static assets to load. If I point my module to a basic html page with a simple <h1>Hello, World!</h1> then that's what Ill get but trying to load any outside scripts/stylesheets is when I get the 404 errors and nothing loads.
I'll be answering my own question.
The solution is actually pretty simple. The view layer of this module is handled by React, CRA to be specific. CRA will look for some specific environment variables, one of them being PUBLIC_URL. All I had to do was
Create a .env file in the root directory of my CRA
add PUBLIC_URL="/admin"
Afterward, it's just rebuilding the project, yarn build, and reset the server. CRA will then look at http://localhost:3000/admin/static/... instead of http://localhost:3000/static/... for static assets.

Safari Push Notifications - Verifying hashes in manifest.json failed even though correct

I have created a push package with the appropriate files as per the Apple spec for APNS. This manifest file represents all of the files that are present:
{
"icon.iconset/icon_128x128.png": "78609fcff69688f969a38f957ac2f10fc79d6732",
"icon.iconset/icon_128x128#2x.png": "78609fcff69688f969a38f957ac2f10fc79d6732",
"icon.iconset/icon_16x16.png": "d348589e2cf37d8f23940f8545afe75a2e98b4ac",
"icon.iconset/icon_16x16#2x.png": "d348589e2cf37d8f23940f8545afe75a2e98b4ac",
"icon.iconset/icon_32x32.png": "e4418a1c5f2ecfbb702961515aaa65d5449b1c53",
"icon.iconset/icon_32x32#2x.png": "e4418a1c5f2ecfbb702961515aaa65d5449b1c53",
"website.json": "45be9c4a6f1bf96e27a9eecab219304b35c5ac24"
}
I have manually checked the sha1 values on the CLI and they are all correct, along with the file locations. And yet I still get this error back from Safari each time I try to get permission:
{ '{"logs":': { '"Verifying hashes in manifest.json failed"]': '' } }
Which is not valid JSON either. Any ideas why this would be failing?
I recently implemented push notifications through pushwoosh. They automatically created the package for me and I checked how they done it. The only difference between mine manifest file and your is a back slash before the normal slash. Maybe it could do the difference for you. Copy and paste this code in your manifest (I have already added your SHA1 values):
{"icon.iconset\/icon_16x16.png":"d348589e2cf37d8f23940f8545afe75a2e98b4ac","icon.iconset\/icon_16x16#2x.png":"d348589e2cf37d8f23940f8545afe75a2e98b4ac","icon.iconset\/icon_32x32.png":"e4418a1c5f2ecfbb702961515aaa65d5449b1c53","icon.iconset\/icon_32x32#2x.png":"e4418a1c5f2ecfbb702961515aaa65d5449b1c53","icon.iconset\/icon_128x128.png":"78609fcff69688f969a38f957ac2f10fc79d6732","icon.iconset\/icon_128x128#2x.png":"78609fcff69688f969a38f957ac2f10fc79d6732","website.json":"45be9c4a6f1bf96e27a9eecab219304b35c5ac24"}
I created a small ruby script for generating these manifests based on the code in https://github.com/SymmetricInfinity/push_package/blob/master/lib/push_package.rb.
Copy the script into a directory containing an icon.iconset directory and your website.json. Then you can run ruby gen_manifest.rb inside that directory and the script will write the manifest.json. At the very least it may be a sanity check to see that everything is correct. The script is here: https://gist.github.com/adamvduke/7934457
If you don't have any ruby experience, comment back and I can walk you through it.

F4 IDE gives "Invalid Uri scheme for local file" when running Fantom app

I started a very simple project using Xored's F4 IDE for Fantom. The first few times I ran it there was no error, but I started adding dependencies (fanbatis) and at some point the error below starting showing up every time I run a test or a dummy Hello World app.
[23:44:18 22-Nov-13] [err] [pathenv] Cannot parse path: C:\dev\f4workspace\auth\bin\fan
sys::ArgErr: Invalid Uri scheme for local file: c:\dev\f4workspace\auth\bin\fan/
fan.sys.LocalFile.uriToFile (LocalFile.java:64)
fan.sys.File.make (File.java:26)
util::PathEnv.parsePath (PathEnv.fan:47)
fan.sys.List.each (List.java:555)
util::PathEnv.parsePath (PathEnv.fan:43)
util::PathEnv.make$ (PathEnv.fan:22)
util::PathEnv.make (PathEnv.fan:20)
java.lang.reflect.Method.invoke (Unknown)
fan.sys.Method.invoke (Method.java:559)
fan.sys.Method$MethodFunc.callList (Method.java:198)
fan.sys.Type.make (Type.java:246)
fan.sys.ClassType.make (ClassType.java:110)
fan.sys.Type.make (Type.java:236)
fan.sys.Sys.initEnv (Sys.java:447)
fan.sys.Sys. (Sys.java:224)
fanx.tools.Fan.execute (Fan.java:28)
fanx.tools.Fan.run (Fan.java:298)
fanx.tools.Fan.main (Fan.java:336)
Hello, World!
It is more a nuisance at the moment because the tests and the dummy app still run. I created another project, copying all the source code adding class by class and testing after each change and the error never occurred. Any ideas please?
That's an interesting issue!
tl/dr: you have an empty project 'auth' in your workspace, either create some dummy class inside it or go to Run -> Run configurations, find your launch config and uncheck project without sources on 'Projects' tab.
In order to keep your Fantom installation clean from projects in a workspace, F4 puts built pods into project/bin/fan/lib/fan. When F4 launches projects from workspace, it uses PathEnv and builds FAN_ENV_PATH by joining paths to Fantom installation and bin/ folders in projects in workspace.
When Fantom runtime analyzes FAN_ENV_PATH, at first it interprets a path as native OS path, but if dir does not exist, it attempts to interpret it as file URI, here's relevant part of PathEnv source:
path.split(File.pathSep[0]).each |item|
{
if (item.isEmpty) return
dir := File.os(item).normalize
if (!dir.exists) dir = File(item.toUri.plusSlash, false).normalize
if (!dir.exists) { log.warn("Dir not found: $dir"); return }
The problem code is item.toUri – On Mac OS X and Linux this is parsed as an URI without scheme with path only, so if directory does not exist, this code just prints a warning in a console.
But on Windows, because of disk name in path, disk name is interpreted as scheme:
fansh> "C:\\Users".toUri { echo(path); echo(scheme) }
[\Users]
c
fansh> "/Users".toUri { echo(path); echo(scheme) }
[Users]
null
And then File constructor fails, because expects either 'file' scheme, or null scheme:
public static java.io.File uriToFile(Uri uri)
{
if (uri.scheme() != null && !uri.scheme().equals("file"))
throw ArgErr.make("Invalid Uri scheme for local file: " + uri);
return new java.io.File(uriToPath(uri));
}
I've created an issue here, so that F4 would automatically skip empty projects when building FAN_ENV_PATH – https://github.com/xored/f4/issues/25.
I thought the problem had something to do with the forward slash at the end of path as shown in this line of the error message
Invalid Uri scheme for local file: c:\dev\f4workspace\auth\bin\fan/
However, I found that such path didn't exist. I manually created both the bin and the fan folders and the error disappeared. To be honest I don't really know why F4 needs and checks for that folder because so far it hasn't written any file in it.